Skip to content

Commit

Permalink
Merge pull request socketio#809 from DanielBaulig/issue795-fix
Browse files Browse the repository at this point in the history
Issue795 fix
  • Loading branch information
rauchg committed Mar 28, 2012
2 parents a232159 + 00694a8 commit 16205fc
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
@@ -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;
41 changes: 41 additions & 0 deletions test/namespace.test.js
Original file line number Diff line number Diff line change
@@ -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 16205fc

Please sign in to comment.