From 757c8a46717e06721ba1f8a0408739e925daaa00 Mon Sep 17 00:00:00 2001 From: crickeys Date: Wed, 19 Feb 2014 21:24:28 -0600 Subject: [PATCH 1/2] adding ability to retrieve all clients in a room --- lib/namespace.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/namespace.js b/lib/namespace.js index 0f0504c923..bb8015a2a2 100644 --- a/lib/namespace.js +++ b/lib/namespace.js @@ -1,4 +1,3 @@ - /** * Module dependencies. */ @@ -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); + }; From b6eacc98dd84aa00f1d9fc65b39f54c5dc3e9c92 Mon Sep 17 00:00:00 2001 From: crickeys Date: Wed, 19 Feb 2014 21:25:04 -0600 Subject: [PATCH 2/2] Ability to retrieve all clients for a given room --- lib/adapter.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/adapter.js b/lib/adapter.js index c9d7f6528f..bdebf0afa5 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -1,4 +1,3 @@ - /** * Module dependencies. */ @@ -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; + + };