-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Add support for getting clients in a given room #1630
Conversation
Room should be optional right? |
|
Thanks for submitting this btw! |
Sorry, i only made it for getting clients in a given room, though i'll try to do that tomorrow. |
I made the base adapter work without the room parameter. I'll add this into the redis adapter as well, though i still need to do something to clean up redis on normal exit. |
👍 |
+1 |
1 similar comment
👍 |
Not to blow up this thread, but you already can get the list of clients in a room.
Is this not sufficient? Am I missing something? Should this data not be accessed directly or is this PR merely a convenience thing? |
That doesn't give a list of all the clients connected to all the rooms. It's a convenience I guess, but makes migration from socket-io 0.9 to 1.0 a lot easier. |
Also, it doesn't work in a multi node environment. |
@hestinr12 Now we have an official redis adapter and there's no way to get that dictionary from redis adapter. A convenient API for getting clients is pretty much required for some use cases as discussed earlier in #1428 |
@panuhorsmalahti in what case does it not? @FREEZX mostly out of curiosity, why does that occur? Is this just a reference to the local instance's connections? @bdemirkir so to clarify, this is provides an interface to the redis cache handling the multi-node environment? |
@hestinr12 Yes. Please look at these PRs: |
@hestinr12 |
Hmm,
So I can get an array of socket ids, but how can I get the actual socket connections using the ids? |
@panuhorsmalahti try with io.sockets.connected[id] |
+1 |
…will not work in multi-node environment. Fix: http://stackoverflow.com/questions/23858604/how-to-get-rooms-clients-list-in-socket-io-1-0 Request: socketio/socket.io#1428 Pull requests: - socketio/socket.io#1630 - socketio/socket.io-adapter#5 - socketio/socket.io-redis-adapter#15
+1 |
Was this actually merged, or just closed? |
We have another issue tracking this I believe. Is this why you closed @defunctzombie ? |
I thought it was merged per the comment of "coming in next release". Sorry if that is not the case yet. |
If this is ready for merge, could the OP please cleanup the commit history. |
It's not though. |
In which version is this feature coming? |
Is it part of 1.3.x or not ? I can't see it in the release notes changes ..... |
It's the top priority for our next release. #1945 |
Great! Thanks :) |
Not clear if this is in or not? (It's been a few months since last comment on this pull) |
:) It is not. I'm guessing... soon. |
Any updates on this pr? |
+1 |
1 similar comment
+1 |
getClientsInRoom: (io, roomName) ->
ret = []
room = io.sockets.adapter.rooms[roomName]
return ret if !room
for socketID of room
ret.push(io.sockets.connected[socketID])
ret |
+1 |
I'm still waiting for this feature. Is there any blocker? |
@samuel281 needs to be rebased |
+1 |
io['sockets']['adapter']['sids'] is returning an empty literal for me even though a client is clearly connected |
For anyone interested, I'm currently using the following to accomplish that: io.in( room ).clients(function( error, clients ) {
if (error) throw error;
for ( var i = 0, len = clients.length; i < len; i++ ) {
io.sockets.connected[clients[i]].emit( 'something', {some: 'data'} );
}
}); |
Closed by socketio/socket.io-adapter#24 and socketio/socket.io-redis-adapter#109. Thanks! |
Added a clients function that calls the adapter's clients function, in order to get the connected clients in a room.
Pull requests implementing the underlying adapter functions:
Redis adapter: socketio/socket.io-redis-adapter#15
Memory adapter: socketio/socket.io-adapter#5