Multiples rooms socket io

0

as they are.

I have a question with some sockets in socket io. What I'm trying to do is create several rooms, and then send them an event that runs every second, that's an interval ..

var Room = function (room_name, data) {
    this.id = room_name
    this.data = data
    this.timer = setInterval(this.timerFunction.bind(this), 1000);
}

Room.prototype.timerFunction = function () {
    io.in(this.id).emit('prueba_interval', this.data);
}

items.forEach(room_name => {
    new Room(room_name, 'algun texto de prueba cada segundo')
})

This part works, creates the 4 rooms and starts issuing the event 'test_interval' every second.

Now, is there a way I can modify this? from another event?

Assuming the client presses a button and issues an event, the server receives it

socket.on('modificar_interval', room_name => {
        // aqui llega el nombre del room al que pertenece el usuario
        // aqui es donde tengo la duda
        new Room(room_name, 'el texto del room ha cambiado')
    })

Could I modify that same event to change the text?

And instead of receiving 'some test text every second'

may receive 'some test text every second'

It should be noted that this interval will be a timer, a countdown.

Greetings

    
asked by danielvkp 13.10.2018 в 23:31
source

0 answers