Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get all the rooms #1884

Closed
barisusakli opened this issue Nov 21, 2014 · 11 comments
Closed

How to get all the rooms #1884

barisusakli opened this issue Nov 21, 2014 · 11 comments
Labels
enhancement New feature or request

Comments

@barisusakli
Copy link

#1630 already adds support for .clients([room], fn); to grab a list of socket ids in a room. I sent a PR to @FREEZX for adding the method .roomClients([socketid],fn) as well to grab a list of rooms the socket id is in.

This was possible in 0.9.x with io.sockets.manager.roomClients[socket_id] and it used to work across multiple nodes when used with RedisStore.

It was also possible to get a hash of all the rooms with io.sockets.manager.rooms but I don't see this available in 1.x. There is io.sockets.adapter.rooms but that doesn't work across nodes as far as I can see.

It is possible to get this data using the above two functions. First get all socket ids in room '' then call roomClients repeatedly to get the rooms and merge those but it means making n calls to roomClients, where as it was as simple as reading the io.sockets.manager.rooms object in 0.9.x

@mikaturunen
Copy link

👍

@nkzawa nkzawa added Rooms enhancement New feature or request labels Dec 25, 2014
@ronkorving
Copy link

+1 on this one. You can't even make a decent chat system without the ability to list rooms.

@mike-aungsan
Copy link

(Y)

@nebkam
Copy link

nebkam commented Oct 21, 2015

👍

@VarunVerma7
Copy link

Does anyone have a solution to getting access to the all rooms?

@darrachequesne
Copy link
Member

Closed by socketio/socket.io-redis-adapter#168.

io.adapter.allRooms(function (err, rooms) {
  console.log(rooms); // an array containing all rooms (accross every node)
});

@ApplefaceLisa
Copy link

I'm using 2.0.4 and io.adapter.allRooms not work. Any idea?

@wangdalang
Copy link

i use io.sockets.adapter.rooms

@Noitidart
Copy link

@wangdalang can you please show code example and link to docs for that. I can't seem to find it.

@minhquan1313
Copy link

console.log(🚀 ~ io.adapter.rooms:, io.adapter.rooms);
image

@darrachequesne
Copy link
Member

For future readers:

As noted above, you can have access to the list of rooms on a single server with:

const rooms = io.of("/").adapter.rooms

Please note that this Map will contain:

  • both public and private rooms (by "private" I mean the room named after each socket.id)
  • only the rooms on this single server, in a multi-server setup

There is no native way to list all the rooms across multiple servers, it's up to you to implement it depending on your application logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

13 participants