I have an internal loop for each socket:
if (!chat.room.list[hash]) { // room has expired
socket.leave(hash);
delete chat.user.list[socket.store.data.id].rooms[hash];
delete socket.store.data.inRooms[hash]; // delete room hash from user store
}
socket.leave(hash)
does nothing - socket still receives messages sent to hash
room.
As a side note - if I connect with client Anna and client Bob - both receive messages, but if I reconnect with client Bob - Bob cannot send messages to Anna.
Is there somewhere a full socket io API documentation (as I couldn't find socket.leave(room) examples)?
EDIT:
Got it! Socket IO saves room handles with slash, so you have to use socket.leave('/'+hash)
Rooms in socket.io are implicitly created and implicitly deleted. Basically they are automatically removed when they are empty.
And yes, a preceding /
is added to the rooms name internally but you do not need to add this to remove a socket from a room.
Try firing console.log(io.sockets.manager.rooms)
whenever a room is created to have a look at what's happening internally.
As of 0.8.7 i tried it out and it seems you don't have to add the / (slash) anymore
socket.leave(hash)
Works just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With