Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Disconnect socket once all namespaces are disconnected #503

Closed
wants to merge 1 commit into from

1 participant

@kanongil

In order to support this, only user requested namespaces are registered.

This will also fix an issue where explicitly disconnected namespaces
don't stop receiving events through Socket#publish().

@kanongil kanongil Disconnect socket once all namespaces are disconnected
In order to support this, only user requested namespaces are registered.
This will also fix an issue where explicitly disconnected namespaces
don't stop receiving events through Socket#publish().
9b1ba7e
@kanongil

ping?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 10, 2012
  1. @kanongil

    Disconnect socket once all namespaces are disconnected

    kanongil authored
    In order to support this, only user requested namespaces are registered.
    This will also fix an issue where explicitly disconnected namespaces
    don't stop receiving events through Socket#publish().
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 4 deletions.
  1. +1 −2  lib/namespace.js
  2. +24 −2 lib/socket.js
View
3  lib/namespace.js
@@ -123,8 +123,7 @@
if (this.name === '') {
this.socket.disconnect();
} else {
- this.packet({ type: 'disconnect' });
- this.$emit('disconnect');
+ this.socket.disconnectNamespace(this.name);
}
return this;
View
26 lib/socket.js
@@ -87,6 +87,26 @@
};
/**
+ * Disconnects a namespace, and the socket connection if all namespaces have
+ * been disconnected.
+ *
+ * @api private
+ */
+
+ Socket.prototype.disconnectNamespace = function (name) {
+ if (this.namespaces[name]) {
+ var nsp = this.of(name);
+ nsp.packet({ type: 'disconnect' });
+ nsp.$emit('disconnect');
+ delete this.namespaces[name];
+
+ if (Object.keys(this.namespaces).length === 0) {
+ this.disconnect();
+ }
+ }
+ };
+
+ /**
* Emits the given event to the Socket and all namespaces
*
* @api private
@@ -339,7 +359,7 @@
Socket.prototype.disconnect = function () {
if (this.connected || this.connecting) {
if (this.open) {
- this.of('').packet({ type: 'disconnect' });
+ this.packet({ type: 'disconnect' });
}
// handle disconnection immediately
@@ -440,7 +460,9 @@
*/
Socket.prototype.onPacket = function (packet) {
- this.of(packet.endpoint).onPacket(packet);
+ if (this.namespaces[packet.endpoint]) {
+ this.of(packet.endpoint).onPacket(packet);
+ }
};
/**
Something went wrong with that request. Please try again.