R
R
Rostislav Ignatenko2017-05-25 11:02:00
Node.js
Rostislav Ignatenko, 2017-05-25 11:02:00

How to force all members of the room to leave it if the creator left?

Suppose several users entered the room to Vasia1234 and it worked for them How to make it so that if this Vasia1234 left the room (by clicking on a certain button), then all users who were in it automatically left it? It only comes to my mind. But in practice, I have not yet checked whether this even works or not, maybe someone knows how this is implemented? socket.join('Vasia1234');
io.sockets.to('Vasia1234').leave('Vasia1234')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rostislav Ignatenko, 2017-05-25
@lepard

I did it differently, if the creator leaves the room, a socket message is sent to all users of the room, which causes a socket message from the client to disconnect.
// Creator leaves the room

socket.leave('Vasia1234');
io.sockets.to('Vasia1234').emit('leave all');

//Processing for all users of the room from the client side
socket.on('leave all', function(){
socket.emit('leave all');
})

//Processing for all users of the room from the server side
socket.on('leave all',  function(){
socket.leave('Vasia1234');
})

D
Denis Bukreev, 2017-05-25
@denisbookreev

In this case, you need to try "does this work or not", and then ask yourself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question