Is it possible to get rooms which socket is currently in, without calling
io.sockets.clients(roomName)
for every room name and looking for this socket in results
Is it possible to get rooms which socket is currently in, without calling
io.sockets.clients(roomName)
for every room name and looking for this socket in results
socket.io 1.7.3+ ->
Being sure that socket is in only one room at a time, my solution was:
socket.io 1.7.3 +
Version 1.7.3,
socket.rooms
containssocket.id
, so remove it and get the list of rooms:In other version, you can print the
socket
and find the rooms.1.4.5 version =>
io.sockets.adapter.rooms[roomname].sockets
You can save room in socket itself when it joins a room
Later you can retrieve all rooms that the socket is in by simply
From the Server API documentation:
https://socket.io/docs/server-api/#socket-rooms