套接字断开的Socket.io

Iam*_*ter 2 node.js socket.io

我有socket.io这个场景:

套接字连接并加入一个房间,他就是主人.其他插座加入他的房间.当主人断开连接时,我想从这个房间踢出所有其他插座.

我想到了这个:

socket.on('disconnect', function(data){
    // if socket's 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.       
});
Run Code Online (Sandbox Code Playgroud)

我想这样做没有太多的逻辑和循环停止应用程序.这样的事情有可能io.sockets.leave(socket.room)吗?

Ere*_*evi 5

alessioalex的答案返回错误,因为它试图在一组套接字上调用"leave".这是一个有效的解决方案:

io.sockets.clients(socket.room).forEach(function(listener) {
    listener.leave(socket.room);
});
Run Code Online (Sandbox Code Playgroud)