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