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

Add support for getting clients in a given room #1630

Closed
wants to merge 11 commits into from

Conversation

FREEZX
Copy link

@FREEZX FREEZX commented Jun 17, 2014

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

@rauchg
Copy link
Contributor

rauchg commented Jun 17, 2014

Room should be optional right?

@rauchg
Copy link
Contributor

rauchg commented Jun 17, 2014

clients(fn) should work

@rauchg
Copy link
Contributor

rauchg commented Jun 17, 2014

Thanks for submitting this btw!

@FREEZX
Copy link
Author

FREEZX commented Jun 17, 2014

Sorry, i only made it for getting clients in a given room, though i'll try to do that tomorrow.
Please also check the mentioned pull requests when you can, the redis one needs a little attention, because i have no idea how to properly clean up the database on exit.

@FREEZX
Copy link
Author

FREEZX commented Jun 19, 2014

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.

@julianlam
Copy link

👍

@panuhorsmalahti
Copy link

+1

1 similar comment
@mikaturunen
Copy link

👍

@ryanhestin
Copy link

Not to blow up this thread, but you already can get the list of clients in a room.

io['sockets']['adapter']['rooms'] returns a dictionary of all the rooms currently open as the key and a dictionary of all clients and their current status in the room as the value (key:value).

Is this not sufficient? Am I missing something? Should this data not be accessed directly or is this PR merely a convenience thing?

@panuhorsmalahti
Copy link

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.

@FREEZX
Copy link
Author

FREEZX commented Jun 24, 2014

Also, it doesn't work in a multi node environment.

@ghost
Copy link

ghost commented Jun 24, 2014

@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

@ryanhestin
Copy link

@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?

@panuhorsmalahti
Copy link

@hestinr12
As I understand it, you would need to convert that object of rooms of clients to clients to get the 0.9 functionality (and filter out duplicates). Only a few lines of code, but it makes the migration easier. More importantly, most programmers are not aware of io['sockets']['adapter']['rooms']. It should be documented in the migration guide at least.

@panuhorsmalahti
Copy link

Hmm,

io['sockets']['adapter']['sids'] ===
{"T6DaL1e3HD8y41KYAAAA":{"T6DaL1e3HD8y41KYAAAA":true},"UzoTueQjgPvQbWusAAAB":{"UzoTueQjgPvQbWusAAAB":true} /* ... */

So I can get an array of socket ids, but how can I get the actual socket connections using the ids?

@FREEZX
Copy link
Author

FREEZX commented Jun 25, 2014

@panuhorsmalahti try with io.sockets.connected[id]

@indrekj
Copy link

indrekj commented Jun 30, 2014

+1

@paulosborne
Copy link

+1

@julianlam
Copy link

Was this actually merged, or just closed?

@rauchg
Copy link
Contributor

rauchg commented Jan 10, 2015

We have another issue tracking this I believe. Is this why you closed @defunctzombie ?

@defunctzombie
Copy link
Contributor

I thought it was merged per the comment of "coming in next release". Sorry if that is not the case yet.

@defunctzombie
Copy link
Contributor

If this is ready for merge, could the OP please cleanup the commit history.

@rauchg
Copy link
Contributor

rauchg commented Jan 10, 2015

It's not though.

@panuhorsmalahti
Copy link

In which version is this feature coming?

@bcharbonnier
Copy link

Is it part of 1.3.x or not ? I can't see it in the release notes changes .....
I mean, the real question is: did the bug get fixed somehow via another PR ?

@rauchg
Copy link
Contributor

rauchg commented Jan 21, 2015

It's the top priority for our next release. #1945

@bcharbonnier
Copy link

Great! Thanks :)

@hayksaakian
Copy link

Not clear if this is in or not? (It's been a few months since last comment on this pull)

@marksyzm
Copy link

marksyzm commented Jun 2, 2015

:) It is not. I'm guessing... soon.

@luin
Copy link

luin commented Jun 12, 2015

Any updates on this pr?

@emadd
Copy link

emadd commented Jul 3, 2015

+1

1 similar comment
@austinkelleher
Copy link

+1

@wanming
Copy link

wanming commented Jul 31, 2015

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

@benkaiser
Copy link

+1

@samuel281
Copy link

I'm still waiting for this feature. Is there any blocker?

@LordMajestros
Copy link

@samuel281 needs to be rebased

@Shadowstep33
Copy link

+1

@Shadowstep33
Copy link

io['sockets']['adapter']['sids'] is returning an empty literal for me even though a client is clearly connected

@JCMais
Copy link

JCMais commented May 30, 2016

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'} );
    }
});

@darrachequesne
Copy link
Member

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

Successfully merging this pull request may close these issues.