Skip to content
Advertisement

disconnect client from socket.io id

I can connect specific player to specific room like:

socket.join('sampleroom');

And documentation says that ‘you can use leave method to leave room’ like:

socket.leave('sampleroom');

But I just want any client to leave using io object instead of socket. I need something like:

io.sockets(specificSocketID).leave('sampleroom');

Is there any way to leave client from room using just socket id with io object?

Advertisement

Answer

As @tresdin mentioned, we can store socket ids, however io object is also stored so actually we don’t need it. We can use specific socket id like

io.sockets.sockets[specificSocketID].leave('sampleroom');
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement