Skip to content

Commit ffadfa6

Browse files
authoredNov 20, 2016
[feature] Add clientRooms method (#41)
That method returns the list of rooms a given socket has joined. It is intended to be used by other adapters, without them needing to access the innards of the adapter.
1 parent 915af31 commit ffadfa6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

‎index.js

+13
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Adapter.prototype.broadcast = function(packet, opts){
151151
* Gets a list of clients by sid.
152152
*
153153
* @param {Array} explicit set of rooms to check.
154+
* @param {Function} callback
154155
* @api public
155156
*/
156157

@@ -195,6 +196,18 @@ Adapter.prototype.clients = function(rooms, fn){
195196
if (fn) process.nextTick(fn.bind(null, null, sids));
196197
};
197198

199+
/**
200+
* Gets the list of rooms a given client has joined.
201+
*
202+
* @param {String} socket id
203+
* @param {Function} callback
204+
* @api public
205+
*/
206+
Adapter.prototype.clientRooms = function(id, fn){
207+
var rooms = this.sids[id];
208+
if (fn) process.nextTick(fn.bind(null, null, rooms ? Object.keys(rooms) : null));
209+
};
210+
198211
/**
199212
* Room constructor.
200213
*

0 commit comments

Comments
 (0)
Please sign in to comment.