0

I have searched for it in stack overflow, but could not get what I wanted certainly. So here my question is: Is it possible to get an array of rooms presently available in socket.io.

I have looked other questions like this in stackoverflow. BUt I am not clear.

when I use io.sockets.adapter.rooms and console log the output, I get:

    { TeMJp5CVxdJlXsDiAAAA: [ TeMJp5CVxdJlXsDiAAAA: true ],
      lobby: [ TeMJp5CVxdJlXsDiAAAA: true ],
      'H-xHQXha_NdOs6sPAAAB': [ 'H-xHQXha_NdOs6sPAAAB': true ],
      room: [ 'H-xHQXha_NdOs6sPAAAB': true ],
     '5LglXlxtn498I9NaAAAC': [] }

It comprises of ids and room names mixed up. I need only array of rooms. Need help

Community
  • 1
  • 1
Saiteja Parsi
  • 412
  • 1
  • 5
  • 15
  • 1
    The problem is every connected socket joins a "default" room with the socket id as name. Maybe you can check `io.sockets.connected` for all connected socket ids and filter them out of the room list. But then you have the problem that rooms stay there even after disconnection. – DerM Sep 30 '14 at 08:15

1 Answers1

0

I like the way this guys deals with that problem so I give credit to his work instead. Basically whenever a room is created you add it to an array. https://github.com/tamaspiros/advanced-chat

Dslayer
  • 1,101
  • 14
  • 17