Skip to content

How to get number of clients in a room #1661

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
johnny0614 opened this issue Jul 4, 2014 · 5 comments
Closed

How to get number of clients in a room #1661

johnny0614 opened this issue Jul 4, 2014 · 5 comments

Comments

@johnny0614
Copy link

in 0.7.x, I can clients() function to retrieve the number of clients in a room. But how can I do it in version 1.0.x ?

@13ruce1337
Copy link

I ran into the same problem a about a week ago. I found this answer on SO to be helpful in finding:

io.sockets.sockets

which returns an array of connected clients.

you can also just create your own array and push to it in the callback of .on('connection')

@BenBals
Copy link

BenBals commented Jul 4, 2014

So to answer your question:
13ruce1337 is completly right. To get the number of clients connected just get the length of the array of all clients by

io.sockets.sockets.length

@download13
Copy link

It would be good to be able to get the IDs of every socket in a room. Is there any way to do that?

@peteruithoven
Copy link

@download13, that's another question, see #1428 for example.

@darrachequesne
Copy link
Member

That issue was closed automatically. Please check if your issue is fixed with the latest release, and reopen if needed (with a fiddle reproducing the issue if possible).

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

6 participants