mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Merge pull request #1700 from rase-/fix/rooms
Fix splice arguments and `socket.rooms` value update in `socket.leaveAll`
This commit is contained in:
@@ -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 = [];
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user