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

Suggestion for implementation of clients API #24

Merged
merged 1 commit into from
Jan 31, 2015
Merged
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
41 changes: 41 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,44 @@ Adapter.prototype.broadcast = function(packet, opts){
}
});
};

/**
* Gets a list of clients by sid.
*
* @param {Array} explicit set of rooms to check.
* @api public
*/

Adapter.prototype.clients = function(rooms, fn){
var ids = {};
var self = this;
var sids = [];
var socket;

rooms = rooms || [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should maybe also consider the signature clients(fn) ?

if (rooms.length) {
for (var i = 0; i < rooms.length; i++) {
var room = self.rooms[rooms[i]];
if (!room) continue;
for (var id in room) {
if (room.hasOwnProperty(id)) {
if (ids[id]) continue;
socket = self.nsp.connected[id];
if (socket) {
sids.push(id);
ids[id] = true;
}
}
}
}
} else {
for (var id in self.sids) {
if (self.sids.hasOwnProperty(id)) {
socket = self.nsp.connected[id];
if (socket) sids.push(id);
}
}
}

if (fn) process.nextTick(fn.bind(null, null, sids));
};