Answer the question
In order to leave comments, you need to log in
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
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');
socket.on('leave all', function(){
socket.emit('leave all');
})
socket.on('leave all', function(){
socket.leave('Vasia1234');
})
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 questionAsk a Question
731 491 924 answers to any question