Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
, 'sync disconnect on unload': true
, 'auto connect': true
, 'flash policy port': 10843
, orphan:false
};

io.util.merge(this.options, options);
Expand All @@ -48,6 +49,8 @@
this.buffer = [];
this.doBuffer = false;

if(this.options.orphan) return;

if (this.options['sync disconnect on unload'] &&
(!this.isXDomain() || io.util.ua.hasCORS)) {
var self = this;
Expand Down Expand Up @@ -93,6 +96,8 @@
*/

Socket.prototype.publish = function () {
if(this.options.orphan) return;

this.emit.apply(this, arguments);

var nsp;
Expand Down Expand Up @@ -211,7 +216,7 @@
self.setHeartbeatTimeout();

function connect (transports){
if (self.transport) self.transport.clearTimeouts();
if (self.transport) self.transport.detach();

self.transport = self.getTransport(transports);
if (!self.transport) return self.publish('connect_failed');
Expand Down Expand Up @@ -423,6 +428,8 @@
*/

Socket.prototype.onError = function (err) {
if(this.options.orphan) return;

if (err && err.advice) {
if (err.advice === 'reconnect' && (this.connected || this.connecting)) {
this.disconnect();
Expand Down
11 changes: 11 additions & 0 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@
}
};

/**
* To detach/isolate transport from the associated socket
* useful to avoid the effect of this transport when
* socket already fallback/connecting/connected to other transport
*/
Transport.prototype.detach = function () {
this.socket = new io.Socket({orphan:true, reconnect:false});
this.clearTimeouts();
this.close();
};

/**
* Sends a packet
*
Expand Down