I am trying to find a list of rooms in which the client is currently in a disconnected event (closes browsers / reloads the page / Internet connection has been deleted).
I need this for the following reason: the user entered several rooms. Then other people did the same. Then it closes the browser tab. And I want to notify all the people in the rooms in which he is that he has left.
So I need to do something inside the "disconnect" event.
io.sockets.on('connection', function(client){ ... client.on('disconnect', function(){ }); });
I already tried two approaches and found that both of them are wrong:
1) iterate through adapter.rooms .
for (room in client.adapter.rooms){ io.sockets.in(room).emit('userDisconnected', UID); }
This is wrong because the rooms for the adapters have all the rooms. Not just my client numbers.
2) Transition through client.rooms . This returns the correct list of rooms the client is in, but not in the disconnect event. When disabled, this list is already empty [] .
So how can I do this? I am using the latest version of socket.io at the time of writing: 1.1.0
Salvador dali
source share