From 659c331388d2651a8b1ed527296d7daeffcce4b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Tue, 12 Feb 2013 17:24:55 +0100 Subject: [PATCH] New way to handle InvalidTargetErorr and WebRtcNotSupportedError .. in UA.call() and UA.newMessage() - Do now throw an exception but handle in Session and Message 'failed' event. --- src/Constants.js | 13 +++++++++++-- src/Exceptions.js | 9 --------- src/Message.js | 17 +++++++++++++---- src/Session.js | 24 +++++++++++++----------- src/UA.js | 3 --- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/Constants.js b/src/Constants.js index 1684a9a23..a1993ba7f 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -43,6 +43,9 @@ JsSIP.C= { // SIP schemes SIP: 'sip', + // Invalid target + INVALID_TARGET: 'sip:invalid@invalid', + // Transaction states TRANSACTION_TRYING: 1, TRANSACTION_PROCEEDING: 2, @@ -71,8 +74,14 @@ JsSIP.C= { CONNECTION_ERROR: 1, REQUEST_TIMEOUT: 2, - // Invite session end causes + // End and failure causes causes: { + + // Generic error causes + INVALID_TARGET: 'Invalid target', + WEBRTC_NOT_SUPPORTED: 'WebRTC not supported', + + // Invite session end causes BYE: 'Terminated', CANCELED: 'Canceled', NO_ANSWER: 'No Answer', @@ -85,7 +94,7 @@ JsSIP.C= { IN_DIALOG_408_OR_481: 'In-dialog 408 or 481', SIP_FAILURE_CODE: 'SIP Failure Code', - // SIP ERROR CAUSES + // SIP error causes BUSY: 'Busy', REJECTED: 'Rejected', REDIRECTED: 'Redirected', diff --git a/src/Exceptions.js b/src/Exceptions.js index aba5c9687..a7036a2a5 100644 --- a/src/Exceptions.js +++ b/src/Exceptions.js @@ -43,15 +43,6 @@ JsSIP.Exceptions= { return exception; }()), - WebRtcNotSupportedError: (function(){ - var exception = function(){ - this.code = 4; - this.name = 'WEBRTC_NO_SUPPORTED_ERROR'; - }; - exception.prototype = new Error(); - return exception; - }()), - InvalidStateError: (function(){ var exception = function(status) { this.code = 5; diff --git a/src/Message.js b/src/Message.js index f7151b5f8..7cd52599e 100644 --- a/src/Message.js +++ b/src/Message.js @@ -26,8 +26,6 @@ JsSIP.Message.prototype.send = function(target, body, options) { 'failed' ]; - JsSIP.Utils.checkUAStatus(this.ua); - this.initEvents(events); // Get call options @@ -42,7 +40,11 @@ JsSIP.Message.prototype.send = function(target, body, options) { } // Check target validity - target = JsSIP.Utils.normalizeURI(target, this.ua.configuration.domain); + try { + target = JsSIP.Utils.normalizeURI(target, this.ua.configuration.domain); + } catch(e) { + target = JsSIP.C.INVALID_TARGET; + } // Message parameter initialization this.direction = 'outgoing'; @@ -73,7 +75,14 @@ JsSIP.Message.prototype.send = function(target, body, options) { request: this.request }); - request_sender.send(); + if (target === JsSIP.C.INVALID_TARGET) { + this.emit('failed', this, { + originator: 'local', + cause: JsSIP.C.causes.INVALID_TARGET + }); + } else { + request_sender.send(); + } }; /** diff --git a/src/Session.js b/src/Session.js index bc81e49bd..9b12b4b37 100644 --- a/src/Session.js +++ b/src/Session.js @@ -76,15 +76,6 @@ JsSIP.Session.prototype.init_incoming = function(request) { JsSIP.Session.prototype.connect = function(target, views, options) { var event, eventHandlers, request, selfView, remoteView, mediaTypes, extraHeaders, requestParams; - // Check UA Status - JsSIP.Utils.checkUAStatus(this.ua); - - // Check WebRTC support - if(!JsSIP.WebRTC.isSupported) { - console.log(JsSIP.C.LOG_UA +'WebRTC not supported.'); - throw new JsSIP.Exceptions.WebRtcNotSupportedError(); - } - // Check Session Status if (this.status !== JsSIP.C.SESSION_NULL) { throw new JsSIP.Exceptions.InvalidStateError(this.status); @@ -110,7 +101,11 @@ JsSIP.Session.prototype.connect = function(target, views, options) { } // Check target validity - target = JsSIP.Utils.normalizeURI(target, this.ua.configuration.domain); + try { + target = JsSIP.Utils.normalizeURI(target, this.ua.configuration.domain); + } catch(e) { + target = JsSIP.C.INVALID_TARGET; + } // Session parameter initialization this.from_tag = JsSIP.Utils.newTag(); @@ -152,7 +147,14 @@ JsSIP.Session.prototype.connect = function(target, views, options) { this.newSession('local', request, target); this.connecting('local', request, target); - this.sendInitialRequest(mediaTypes); + + if (target === JsSIP.C.INVALID_TARGET) { + this.failed('local', null, JsSIP.C.causes.INVALID_TARGET); + } else if (!JsSIP.WebRTC.isSupported) { + this.failed('local', null, JsSIP.C.causes.WEBRTC_NOT_SUPPORTED); + } else { + this.sendInitialRequest(mediaTypes); + } }; /** diff --git a/src/UA.js b/src/UA.js index b8b2d0212..e16a7b976 100644 --- a/src/UA.js +++ b/src/UA.js @@ -133,8 +133,6 @@ JsSIP.UA.prototype.isConnected = function() { * @param {Object} videoViews * * @throws {JsSIP.Exceptions.NotReadyError} If JsSIP.UA is not ready (see JsSIP.UA.status, JsSIP.UA.error parameters). - * @throws {JsSIP.Exceptions.WebRtcNotSupportedError} If WebRTC is not supported by the client. - * @throws {JsSIP.Exceptions.InvalidTargetError} If the calling target is invalid. * */ JsSIP.UA.prototype.call = function(target, views, options) { @@ -152,7 +150,6 @@ JsSIP.UA.prototype.call = function(target, views, options) { * @param {Object} [eventHandlers] * * @throws {JsSIP.Exceptions.NotReadyError} If JsSIP.UA is not ready (see JsSIP.UA.status, JsSIP.UA.error parameters). - * @throws {JsSIP.Exceptions.InvalidTargetError} If the calling target is invalid. * */ JsSIP.UA.prototype.sendMessage = function(target, body, options) {