Skip to content

Commit

Permalink
changes according to Adapter's Room class
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzawa committed Dec 7, 2015
1 parent 3124d2b commit 2387733
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
29 changes: 5 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ function adapter(uri, opts){
Redis.prototype.add = function(id, room, fn){
debug('adding %s to %s ', id, room);
var self = this;
this.sids[id] = this.sids[id] || {};
this.sids[id][room] = true;
this.rooms[room] = this.rooms[room] || {};
this.rooms[room][id] = true;
Adapter.prototype.add.call(this, id, room);
var channel = prefix + '#' + this.nsp.name + '#' + room + '#';
sub.subscribe(channel, function(err){
if (err) {
Expand All @@ -175,13 +172,10 @@ function adapter(uri, opts){
debug('removing %s from %s', id, room);

var self = this;
this.sids[id] = this.sids[id] || {};
this.rooms[room] = this.rooms[room] || {};
delete this.sids[id][room];
delete this.rooms[room][id];
var hasRoom = this.rooms.hasOwnProperty(room);
Adapter.prototype.del.call(this, id, room);

if (this.rooms.hasOwnProperty(room) && !Object.keys(this.rooms[room]).length) {
delete this.rooms[room];
if (hasRoom && !this.rooms[room]) {
var channel = prefix + '#' + this.nsp.name + '#' + room + '#';
sub.unsubscribe(channel, function(err){
if (err) {
Expand Down Expand Up @@ -216,20 +210,7 @@ function adapter(uri, opts){
}

async.forEach(Object.keys(rooms), function(room, next){
if (rooms.hasOwnProperty(room)) {
delete self.rooms[room][id];
}

if (self.rooms.hasOwnProperty(room) && !Object.keys(self.rooms[room]).length) {
delete self.rooms[room];
var channel = prefix + '#' + self.nsp.name + '#' + room + '#';
return sub.unsubscribe(channel, function(err){
if (err) return self.emit('error', err);
next();
});
} else {
process.nextTick(next);
}
self.del(id, room, next);
}, function(err){
if (err) {
self.emit('error', err);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"debug": "2.2.0",
"msgpack-js": "0.3.0",
"redis": "2.3.0",
"socket.io-adapter": "automattic/socket.io-adapter#de5cba",
"socket.io-adapter": "0.4.0",
"uid2": "0.0.3"
},
"devDependencies": {
"socket.io": "1.0.2",
"socket.io-client": "1.0.2",
"socket.io": "socketio/socket.io",
"socket.io-client": "socketio/socket.io-client",
"mocha": "1.18.0",
"expect.js": "0.3.1"
}
Expand Down

0 comments on commit 2387733

Please sign in to comment.