From 624e7cb14f2175cbbe3564b657ceff703706aef0 Mon Sep 17 00:00:00 2001 From: Tony Kovanen Date: Fri, 1 Aug 2014 10:18:27 +0200 Subject: [PATCH] Fix splice arguments and `socket.rooms` value update in `socket.leaveAll`. Hat tip @Marreck --- lib/socket.js | 3 ++- test/socket.io.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/socket.js b/lib/socket.js index 82975aca..5c756e8c 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -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 = []; }; /** diff --git a/test/socket.io.js b/test/socket.io.js index b5c23c92..5dda293b 100644 --- a/test/socket.io.js +++ b/test/socket.io.js @@ -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(); + }); }); }); });