From f798a2e110fa9c694f6a48915c897c9d21aab472 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Sat, 10 Mar 2018 08:51:22 +0100 Subject: [PATCH] [fix] Properly emit 'connect' when using a custom namespace (#3197) When using a custom namespace with a middleware, the client did not receive the 'connect' event. Fixes #3082 --- lib/namespace.js | 2 +- package.json | 2 +- test/socket.io.js | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/namespace.js b/lib/namespace.js index 587dad8649..6d0ac17065 100644 --- a/lib/namespace.js +++ b/lib/namespace.js @@ -100,7 +100,7 @@ Namespace.prototype.initAdapter = function(){ */ Namespace.prototype.use = function(fn){ - if (this.server.eio) { + if (this.server.eio && this.name === '/') { debug('removing initial packet'); delete this.server.eio.initialPacket; } diff --git a/package.json b/package.json index 4028122cdb..6e88b231b5 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "engine.io": "~3.2.0", "has-binary2": "~1.0.2", "socket.io-adapter": "~1.1.0", - "socket.io-client": "2.0.4", + "socket.io-client": "socketio/socket.io-client", "socket.io-parser": "~3.2.0" }, "devDependencies": { diff --git a/test/socket.io.js b/test/socket.io.js index ae8cdcfab8..e0ff36f22d 100644 --- a/test/socket.io.js +++ b/test/socket.io.js @@ -2352,6 +2352,23 @@ describe('socket.io', function(){ done(); }); }); + + it('should work with a custom namespace', (done) => { + var srv = http(); + var sio = io(); + sio.listen(srv); + sio.of('/chat').use(function(socket, next){ + next(); + }); + + var count = 0; + client(srv, '/').on('connect', () => { + if (++count === 2) done(); + }); + client(srv, '/chat').on('connect', () => { + if (++count === 2) done(); + }); + }); }); describe('socket middleware', function(done){