Skip to content

Add support for getting clients in a given room#1630

Closed
FREEZX wants to merge 11 commits into
socketio:masterfrom
FREEZX:master
Closed

Add support for getting clients in a given room#1630
FREEZX wants to merge 11 commits into
socketio:masterfrom
FREEZX:master

Conversation

@FREEZX

@FREEZX FREEZX commented Jun 17, 2014

Copy link
Copy Markdown

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

rauchg commented Jun 17, 2014

Copy link
Copy Markdown
Contributor

Room should be optional right?

@rauchg

rauchg commented Jun 17, 2014

Copy link
Copy Markdown
Contributor

clients(fn) should work

@rauchg

rauchg commented Jun 17, 2014

Copy link
Copy Markdown
Contributor

Thanks for submitting this btw!

@FREEZX

FREEZX commented Jun 17, 2014

Copy link
Copy Markdown
Author

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

FREEZX commented Jun 19, 2014

Copy link
Copy Markdown
Author

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
Copy Markdown

👍

@panuhorsmalahti

Copy link
Copy Markdown

+1

1 similar comment
@mikaturunen

Copy link
Copy Markdown

👍

@ryanhestin

Copy link
Copy Markdown

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
Copy Markdown

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

FREEZX commented Jun 24, 2014

Copy link
Copy Markdown
Author

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

@ghost

ghost commented Jun 24, 2014

Copy link
Copy Markdown

@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
Copy Markdown

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

@ghost

ghost commented Jun 24, 2014

Copy link
Copy Markdown

@panuhorsmalahti

Copy link
Copy Markdown

@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
Copy Markdown

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

FREEZX commented Jun 25, 2014

Copy link
Copy Markdown
Author

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

@indrekj

indrekj commented Jun 30, 2014

Copy link
Copy Markdown

+1

@paulosborne

Copy link
Copy Markdown

+1

@julianlam

Copy link
Copy Markdown

Was this actually merged, or just closed?

@rauchg

rauchg commented Jan 10, 2015

Copy link
Copy Markdown
Contributor

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

@defunctzombie

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@rauchg

rauchg commented Jan 10, 2015

Copy link
Copy Markdown
Contributor

It's not though.

@panuhorsmalahti

Copy link
Copy Markdown

In which version is this feature coming?

@bcharbonnier

Copy link
Copy Markdown

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

rauchg commented Jan 21, 2015

Copy link
Copy Markdown
Contributor

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

@bcharbonnier

Copy link
Copy Markdown

Great! Thanks :)

@hayksaakian

Copy link
Copy Markdown

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

@marksyzm

marksyzm commented Jun 2, 2015

Copy link
Copy Markdown

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

@luin

luin commented Jun 12, 2015

Copy link
Copy Markdown

Any updates on this pr?

@emadd

emadd commented Jul 3, 2015

Copy link
Copy Markdown

+1

1 similar comment
@austinkelleher

Copy link
Copy Markdown

+1

@wanming

wanming commented Jul 31, 2015

Copy link
Copy Markdown
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
Copy Markdown

+1

@samuel281

Copy link
Copy Markdown

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

@LordMajestros

Copy link
Copy Markdown

@samuel281 needs to be rebased

@Shadowstep33

Copy link
Copy Markdown

+1

@Shadowstep33

Copy link
Copy Markdown

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

@JCMais

JCMais commented May 30, 2016

Copy link
Copy Markdown

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
Copy Markdown
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.