Skip to content

Commit

Permalink
[feature] Add clientRooms method (#41)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
darrachequesne committed Nov 20, 2016
1 parent 915af31 commit ffadfa6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Expand Up @@ -151,6 +151,7 @@ Adapter.prototype.broadcast = function(packet, opts){
* Gets a list of clients by sid.
*
* @param {Array} explicit set of rooms to check.
* @param {Function} callback
* @api public
*/

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

/**
* Gets the list of rooms a given client has joined.
*
* @param {String} socket id
* @param {Function} callback
* @api public
*/
Adapter.prototype.clientRooms = function(id, fn){
var rooms = this.sids[id];
if (fn) process.nextTick(fn.bind(null, null, rooms ? Object.keys(rooms) : null));
};

/**
* Room constructor.
*
Expand Down

0 comments on commit ffadfa6

Please sign in to comment.