Is it possible to get rooms which socket is currently in, without calling
io.sockets.clients(roomName)
for every room name and looking for
When using a non-default adapter, such as socket.io-redis, socket.rooms
doesn't seem to do the trick. The way I managed to get the rooms for a specific client without looping was to use io.sockets.adapter.sids[socket.id]
, which returns the rooms as an object.
{ 'R-ZRgSf7h4wfPatcAAAC': true, ROOM: true, ROOM_2: true }
Note that this doesn't list sockets on other processes, though!
socket.io v1.3.7, socket.io-redis 1.0.0