Socket.io: How can we check if socket is already joined a room ?

Created on 25 Oct 2017  路  2Comments  路  Source: socketio/socket.io

Hi,
I am creating unique room while Group calling, i want to know if same socket already connected or joined in other rooms, i mean want to filter socket id in all rooms, please let me know if there is any method to check socket id in all created rooms ?

Most helpful comment

io.on('connection', function(socket){
  socket.join('room1');
  console.log(socket.rooms); // contains an object with all of the roomnames as keys and values
})

All 2 comments

io.on('connection', function(socket){
  socket.join('room1');
  console.log(socket.rooms); // contains an object with all of the roomnames as keys and values
})

For me the log shows the same output before and after the call to join a room, i.e. the room "mychannel" doesn't show up in socket.rooms, any idea why is that the case?

console.log(socket.rooms);
socket.join("mychannel");
console.log(socket.rooms);
Was this page helpful?
0 / 5 - 0 ratings