Skip to content

Ability to get all clients for a given room #1428

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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion lib/adapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Module dependencies.
*/
Expand Down Expand Up @@ -120,3 +119,27 @@ Adapter.prototype.broadcast = function(packet, opts){
}
}
};

/**
* Gets all sockets in a room.
*
* Options:
* - `room` {String} room name
*
* @api public
*/

Adapter.prototype.clients = function(room){
var sockets = [];

var room = this.rooms[room];
if (room){
for (var id in room)
{
sockets.push(this.nsp.connected[id]);
}
}

return sockets;

};
14 changes: 13 additions & 1 deletion lib/namespace.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Module dependencies.
*/
Expand Down Expand Up @@ -224,3 +223,16 @@ Namespace.prototype.write = function(){
this.emit.apply(this, args);
return this;
};

/**
* Gets all sockets in a room.
*
* Options:
* - `room` {String} room name
*
* @api public
*/

Namespace.prototype.clients = function(room){
return this.adapter.clients(room);
};