Skip to content

Joining same room more then once and clients in a room #1544

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

Closed
ismarslomic opened this issue May 29, 2014 · 6 comments
Closed

Joining same room more then once and clients in a room #1544

ismarslomic opened this issue May 29, 2014 · 6 comments

Comments

@ismarslomic
Copy link

I'm trying to figure out what happens if the clients emits to join the same room more then once, To test and find answer on this I wanted initially to find out how many clients room has after same clients send more then one emit for joining the room, but Rooms chapter in wiki is outdated. When I try to use io.sockets.clients('room') I get Object #<Namespace> has no method 'clients'.

So I got two questions:

  1. what happens if client tries to join same room more then once? Will he get emits for that room for each time he has tried to join?
  2. How can I find out which clients are in a room?

Im using socket.io v1.0.2

@ismarslomic
Copy link
Author

@rase-
Copy link
Contributor

rase- commented May 29, 2014

  1. As per this line of code, the socket will receive emits only once. The socket is added to a room only once, and if another attempt is made for the same socket to join the room, this attempt will be ignored.
  2. There is currently no public API for getting the clients, and there is some discussion ongoing in Ability to get all clients for a given room #1428. If you really need to get them, for some reason, you can fetch the actual clients from the adapter, assuming you are not using the redis adapter like so:

  socket.join('test room');
  var clients = io.sockets.adapter.rooms['test room'];
  console.log(clients);
  for (var clientId in clients) {
    console.log(io.sockets.connected[clientId]);
  }

I hope this helps. Closing the issue since number 2 is a duplicate.

@rase- rase- closed this as completed May 29, 2014
@ismarslomic
Copy link
Author

Thanks! That's works for me. Maybe Wiki should be updated with this information since it is referring to older version of API?

@rase-
Copy link
Contributor

rase- commented May 29, 2014

@ismarslomic thanks for pointing that out. The socket.io website has some documentation about rooms. We will have all our documentation there in the future.

@ismarslomic
Copy link
Author

Im talking particullary about the Wiki-page at Github (https://github.com/Automattic/socket.io/wiki/Rooms#clients-in-a-room) and not socket.io web page.

I'm not sure which of these two will be the master documentation place for the project. Right now it's little bit confusing, since you can find different information at different places.

@crisu
Copy link

crisu commented Oct 6, 2024

image
image
more joins => more clients => more signals

I used Socket.IO Admin UI. first pic is from sockets tab; second pic is from clients tab. .

var clients = io.sockets.adapter.rooms['test room']; return 1 -> meaning that call returns sockets not clients

"socket.io": "4.7.5",

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

No branches or pull requests

3 participants