Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

socket: improve keeping track of connected state

  • Loading branch information...
commit 558f8b26266a868b98691bc7258b33c445f8c7e0 1 parent a2f1729
@rauchg rauchg authored
Showing with 11 additions and 10 deletions.
  1. +11 −10 lib/socket.js
View
21 lib/socket.js
@@ -48,6 +48,7 @@ function Socket(io, nsp){
this.open();
this.buffer = [];
this.connected = false;
+ this.disconnected = true;
}
/**
@@ -170,6 +171,8 @@ Socket.prototype.onopen = function(){
Socket.prototype.onclose = function(reason){
debug('close (%s)', reason);
+ this.connected = false;
+ this.disconnected = true;
this.emit('disconnect', reason);
};
@@ -272,8 +275,9 @@ Socket.prototype.onack = function(packet){
*/
Socket.prototype.onconnect = function(){
- this.emit('connect');
this.connected = true;
+ this.disconnected = false;
+ this.emit('connect');
this.emitBuffered();
};
@@ -299,6 +303,7 @@ Socket.prototype.emitBuffered = function(){
Socket.prototype.ondisconnect = function(){
debug('server disconnect (%s)', this.nsp);
this.destroy();
+ this.onclose('io server disconnect');
};
/**
@@ -328,17 +333,13 @@ Socket.prototype.destroy = function(){
Socket.prototype.close =
Socket.prototype.disconnect = function(){
- debug('performing disconnect (%s)', this.nsp);
+ if (!this.connected) return this;
- this.packet(parser.PACKET_DISCONNECT);
-
- // manual close means no reconnect
- for (var i = 0; i < this.subs.length; i++) {
- this.subs[i].destroy();
- }
+ debug('performing disconnect (%s)', this.nsp);
+ this.packet({ type: parser.PACKET_DISCONNECT });
- // notify manager
- this.io.destroy(this);
+ // destroy subscriptions
+ this.destroy();
// fire events
this.onclose('io client disconnect');
Please sign in to comment.
Something went wrong with that request. Please try again.