diff --git a/src/Transport.js b/src/Transport.js index 5bac408c1..545f7e69e 100644 --- a/src/Transport.js +++ b/src/Transport.js @@ -20,6 +20,7 @@ JsSIP.Transport = function(ua, server) { this.closed = false; this.connected = false; this.reconnectTimer = null; + this.lastTransportError = {}; this.ua.transport = this; @@ -127,6 +128,8 @@ JsSIP.Transport.prototype = { var connected_before = this.connected; this.connected = false; + this.lastTransportError.code = e.code; + this.lastTransportError.reason = e.reason; console.warn(JsSIP.c.LOG_TRANSPORT +'WebSocket disconnected: code=' + e.code + (e.reason? ', reason=' + e.reason : '')); if(e.wasClean === false) { @@ -140,6 +143,12 @@ JsSIP.Transport.prototype = { // Reset reconnection_attempts this.reconnection_attempts = 0; this.reConnect(); + } else { + this.ua.emit('disconnected', this.ua, { + transport: this, + code: this.lastTransportError.code, + reason: this.lastTransportError.reason + }); } } else { // This is the first connection attempt diff --git a/src/UA.js b/src/UA.js index b9282ccb7..e177dfd7e 100644 --- a/src/UA.js +++ b/src/UA.js @@ -301,6 +301,12 @@ JsSIP.UA.prototype.onTransportError = function(transport) { transport.server.status = JsSIP.c.WS_SERVER_ERROR; console.log(JsSIP.c.LOG_UA +'connection status set to: '+ JsSIP.c.WS_SERVER_ERROR); + this.emit('disconnected', this, { + transport: transport, + code: transport.lastTransportError.code, + reason: transport.lastTransportError.reason + }); + server = this.getNextWsServer(); if(server) { @@ -310,9 +316,7 @@ JsSIP.UA.prototype.onTransportError = function(transport) { if (!this.error || this.error !== JsSIP.c.UA_NETWORK_ERROR) { this.status = JsSIP.c.UA_STATUS_NOT_READY; this.error = JsSIP.c.UA_NETWORK_ERROR; - this.emit('disconnected'); } - // Transport Recovery process this.recoverTransport(); } @@ -339,7 +343,9 @@ JsSIP.UA.prototype.onTransportConnected = function(transport) { this.status = JsSIP.c.UA_STATUS_READY; this.error = null; - this.emit('connected', this); + this.emit('connected', this, { + transport: transport + }); if(this.configuration.register) { if(this.registrator) {