Skip to content

Commit

Permalink
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/Transport.js
Original file line number Diff line number Diff line change
@@ -64,6 +64,16 @@ Transport.prototype = {
console.log(LOG_PREFIX +'closing WebSocket ' + this.server.ws_uri);
this.ws.close();
}

if (this.reconnectTimer !== null) {
window.clearTimeout(this.reconnectTimer);
this.reconnectTimer = null;
this.ua.emit('disconnected', this.ua, {
transport: this,
code: this.lastTransportError.code,
reason: this.lastTransportError.reason
});
}
},

/**
@@ -119,7 +129,12 @@ Transport.prototype = {

console.log(LOG_PREFIX +'WebSocket ' + this.server.ws_uri + ' connected');
// Clear reconnectTimer since we are not disconnected
window.clearTimeout(this.reconnectTimer);
if (this.reconnectTimer !== null) {
window.clearTimeout(this.reconnectTimer);
this.reconnectTimer = null;
}
// Reset reconnection_attempts
this.reconnection_attempts = 0;
// Disable closed
this.closed = false;
// Trigger onTransportConnected callback
@@ -146,8 +161,6 @@ Transport.prototype = {
this.ua.onTransportClosed(this);
// Check whether the user requested to close.
if(!this.closed) {
// Reset reconnection_attempts
this.reconnection_attempts = 0;
this.reConnect();
} else {
this.ua.emit('disconnected', this.ua, {
@@ -261,7 +274,9 @@ Transport.prototype = {
console.log(LOG_PREFIX +'trying to reconnect to WebSocket ' + this.server.ws_uri + ' (reconnection attempt ' + this.reconnection_attempts + ')');

this.reconnectTimer = window.setTimeout(function() {
transport.connect();}, this.ua.configuration.ws_server_reconnection_timeout * 1000);
transport.connect();
transport.reconnectTimer = null;
}, this.ua.configuration.ws_server_reconnection_timeout * 1000);
}
}
};

0 comments on commit 2f3769b

Please sign in to comment.