Skip to content

Commit

Permalink
[fix] Properly emit 'connect' when using a custom namespace
Browse files Browse the repository at this point in the history
When using a custom namespace with a middleware, the client did not receive the 'connect' event.
  • Loading branch information
darrachequesne committed Mar 10, 2018
1 parent be61ba0 commit 42466e4
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,23 @@ describe('socket.io', function(){
done();
});
});

it('should work with a custom namespace', (done) => {
const srv = http();
const sio = io();
sio.listen(srv);
sio.of('/chat').use(function(socket, next){
next();
});

let 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 42466e4

Please sign in to comment.