Skip to content
Permalink
Browse files

Enhance transport error handling

- Add disconnection 'cause' and 'code' properties to UA 'disconnection' event handler
- Emit UA 'disconnected' event every time UA is noticed about a transport disconnection regardles there are other servers to reconnect.
  • Loading branch information
jmillan committed Jan 28, 2013
1 parent eb1aa63 commit aec55a22c71791ab6c2a64ca46f8b8231f304df6
Showing with 18 additions and 3 deletions.
  1. +9 −0 src/Transport.js
  2. +9 −3 src/UA.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
@@ -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) {

0 comments on commit aec55a2

Please sign in to comment.
You can’t perform that action at this time.