문제

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.

도움이 되었습니까?

해결책

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' ]
[]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top