Skip to content

Commit

Permalink
[feat] Add addAll method (#49)
Browse files Browse the repository at this point in the history
That will allow to efficiently join a list of rooms.
  • Loading branch information
darrachequesne committed Feb 26, 2017
1 parent b983377 commit f627cd2
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions index.js
Expand Up @@ -41,10 +41,26 @@ Adapter.prototype.__proto__ = Emitter.prototype;
*/

Adapter.prototype.add = function(id, room, fn){
this.sids[id] = this.sids[id] || {};
this.sids[id][room] = true;
this.rooms[room] = this.rooms[room] || Room();
this.rooms[room].add(id);
return this.addAll(id, [ room ], fn);
};

/**
* Adds a socket to a list of room.
*
* @param {String} socket id
* @param {String} rooms
* @param {Function} callback
* @api public
*/

Adapter.prototype.addAll = function(id, rooms, fn){
for (var i = 0; i < rooms.length; i++) {
var room = rooms[i];
this.sids[id] = this.sids[id] || {};
this.sids[id][room] = true;
this.rooms[room] = this.rooms[room] || Room();
this.rooms[room].add(id);
}
if (fn) process.nextTick(fn.bind(null, null));
};

Expand Down

0 comments on commit f627cd2

Please sign in to comment.