socket on socket

I have this script with

The socket connects and connects to the room, and it is the master. Other sockets are connected to his room. When the master disconnects, I want to knock all other sockets out of this room.

I thought about this:

socket.on('disconnect', function(data){
    // if socket id == room  he is the master and kick other sockets from this 
    // room and join them to a room of their own identified by their ids.       


I want to do this without too much logic and for the loops to stop the application. Is something like io.sockets.leave(

this possible ?


source to share

2 answers

I'm not 100% sure, but after reading the Socket.IO documentation on github I think this should work:;




Alessioalex's response returns an error as it tries to call "leave" on the socket array. Working solution:

io.sockets.clients( {




All Articles