Permalink
Browse files

Merge branch 'master' of github.com:LearnBoost/socket.io

  • Loading branch information...
2 parents 087c686 + 16205fc commit 02a3da487c99a9e76a9cb450f8b019adf1eb6be4 @rauchg rauchg committed Apr 1, 2012
Showing with 52 additions and 4 deletions.
  1. +11 −4 lib/socket.js
  2. +41 −0 test/namespace.test.js
View
15 lib/socket.js
@@ -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;
View
41 test/namespace.test.js
@@ -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.