During a disconnect event, the socket is still available for your process. For example, this should work
io.socket.on('connection', function(socket){ socket.on('disconnect', function() { // this returns a list of all rooms this user is in var rooms = io.sockets.manager.roomClients[socket.id]; for(var room in rooms) { socket.leave(room); } }); });
Although this is not actually required, as socket.io will automatically disable rooms on a disconnect event. However, you can use this method if you want to perform a specific action.
Loourr
source share