Skip to content

Commit 624e7cb

Browse files
author
Tony Kovanen
committed
Fix splice arguments and socket.rooms value update in socket.leaveAll.
Hat tip @Marreck
1 parent 9c80317 commit 624e7cb

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/socket.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Socket.prototype.leave = function(room, fn){
242242
this.adapter.del(this.id, room, function(err){
243243
if (err) return fn && fn(err);
244244
debug('left room %s', room);
245-
self.rooms.splice(self.rooms.indexOf(room, 1));
245+
self.rooms.splice(self.rooms.indexOf(room), 1);
246246
fn && fn(null);
247247
});
248248
return this;
@@ -256,6 +256,7 @@ Socket.prototype.leave = function(room, fn){
256256

257257
Socket.prototype.leaveAll = function(){
258258
this.adapter.delAll(this.id);
259+
this.rooms = [];
259260
};
260261

261262
/**

test/socket.io.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,9 +1240,14 @@ describe('socket.io', function(){
12401240
expect(s.rooms).to.eql([s.id, 'a']);
12411241
s.join('b', function(){
12421242
expect(s.rooms).to.eql([s.id, 'a', 'b']);
1243-
s.leave('b', function(){
1244-
expect(s.rooms).to.eql([s.id, 'a']);
1245-
done();
1243+
s.join( 'c', function(){
1244+
expect(s.rooms).to.eql([s.id, 'a', 'b', 'c']);
1245+
s.leave('b', function(){
1246+
expect(s.rooms).to.eql([s.id, 'a', 'c']);
1247+
s.leaveAll();
1248+
expect(s.rooms).to.eql([]);
1249+
done();
1250+
});
12461251
});
12471252
});
12481253
});

0 commit comments

Comments
 (0)