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');