Merge pull request #1700 from rase-/fix/rooms

Fix splice arguments and `socket.rooms` value update in `socket.leaveAll`
This commit is contained in:
Guillermo Rauch
2014-08-01 13:45:01 +01:00
2 changed files with 10 additions and 4 deletions

View File

@@ -242,7 +242,7 @@ Socket.prototype.leave = function(room, fn){
this.adapter.del(this.id, room, function(err){
if (err) return fn && fn(err);
debug('left room %s', room);
self.rooms.splice(self.rooms.indexOf(room, 1));
self.rooms.splice(self.rooms.indexOf(room), 1);
fn && fn(null);
});
return this;
@@ -256,6 +256,7 @@ Socket.prototype.leave = function(room, fn){
Socket.prototype.leaveAll = function(){
this.adapter.delAll(this.id);
this.rooms = [];
};
/**

View File

@@ -1240,9 +1240,14 @@ describe('socket.io', function(){
expect(s.rooms).to.eql([s.id, 'a']);
s.join('b', function(){
expect(s.rooms).to.eql([s.id, 'a', 'b']);
s.leave('b', function(){
expect(s.rooms).to.eql([s.id, 'a']);
done();
s.join( 'c', function(){
expect(s.rooms).to.eql([s.id, 'a', 'b', 'c']);
s.leave('b', function(){
expect(s.rooms).to.eql([s.id, 'a', 'c']);
s.leaveAll();
expect(s.rooms).to.eql([]);
done();
});
});
});
});