Question

I've seen this on the socketio wiki.

Note that it is not necessary to call socket.leave() during the disconnect event. This will happen automatically. Empty rooms will be automatically pruned so there is no need to manually remove them.

But after some tests, it is not working. After disconnecting (server-side or client-side), the socket is not removed from his room. So my question is, the previous text is still relevant or not ? Because either i have a problem in my code or the wiki is not updated.

I've tried to check inside the socketio code to check this out but i couldn't track the code to see what happens.

If the text is still relevant, when is the room leaved, after or before the code that we put inside the on('disconnected') event ?

Thank you.

Was it helpful?

Solution

You could always delete the entry under socket.namespace.manager.rooms that contains your socket.

socket.join(socket.id);
console.log(socket.namespace.manager.rooms['/'+socket.id]);
socket.namespace.manager.rooms["/"+socket.id].splice(socket.namespace.manager.rooms["/"+socket.id].indexOf(socket.id),1);
console.log(socket.namespace.manager.rooms['/'+socket.id]);

This returns

[ '36_IcxqkWgBgLfC6p3Yj' ]
[]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top