Skip to content

Commit

Permalink
Merge branch 'master' of github.com:LearnBoost/socket.io
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchg committed Apr 1, 2012
2 parents 087c686 + 16205fc commit 02a3da4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,19 @@ Socket.prototype.disconnect = function () {
if (!this.disconnected) {
this.log.info('booting client');

if (this.manager.transports[this.id] && this.manager.transports[this.id].open) {
this.manager.transports[this.id].onForcedDisconnect();
if ('' === this.namespace.name) {
if (this.manager.transports[this.id] && this.manager.transports[this.id].open) {
this.manager.transports[this.id].onForcedDisconnect();
} else {
this.manager.onClientDisconnect(this.id);
this.manager.store.publish('disconnect:' + this.id);
}
} else {
this.manager.onClientDisconnect(this.id);
this.manager.store.publish('disconnect:' + this.id);
this.packet({type: 'disconnect'});
this.manager.onLeave(this.id, this.namespace.name);
this.$emit('disconnect', 'booted');
}

}

return this;
Expand Down
41 changes: 41 additions & 0 deletions test/namespace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,46 @@ module.exports = {
}
});
});
},
'disconnecting from namespace only': function (done) {
var cl = client(++ports)
, io = create(cl)
, ws1
, ws2;

io.of('/foo').on('connection', function (socket) {
socket.disconnect();
});

cl.handshake(function (sid) {
ws1 = websocket(cl, sid);
ws1.on('open', function () {
ws1.packet({
type: 'connect'
, endpoint: '/bar'
});
cl.handshake(function (sid) {
ws2 = websocket(cl, sid);
ws2.on('open', function () {
ws2.packet({
type: 'connect'
, endpoint: '/foo'
});
});
ws2.on('message', function (data) {
if ('disconnect' === data.type) {
cl.end();
ws1.finishClose();
ws2.finishClose();
io.server.close();

data.endpoint.should.eql('/foo');

done();
}
});
});
});
});
}
};

0 comments on commit 02a3da4

Please sign in to comment.