Skip to content

Commit

Permalink
[fix] Properly emit 'connect' when using a custom namespace (socketio…
Browse files Browse the repository at this point in the history
…#3197)

When using a custom namespace with a middleware, the client did not receive the 'connect' event.

Fixes socketio#3082
  • Loading branch information
darrachequesne committed Mar 10, 2018
1 parent 5c7af4c commit f798a2e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/namespace.js
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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": {
Expand Down
17 changes: 17 additions & 0 deletions test/socket.io.js
Expand Up @@ -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){
Expand Down

0 comments on commit f798a2e

Please sign in to comment.