Skip to content
Permalink
Browse files

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.
  • Loading branch information
jmillan committed Feb 12, 2013
1 parent d3bc91a commit 659c331388d2651a8b1ed527296d7daeffcce4b0
Showing with 37 additions and 29 deletions.
  1. +11 −2 src/Constants.js
  2. +0 −9 src/Exceptions.js
  3. +13 −4 src/Message.js
  4. +13 −11 src/Session.js
  5. +0 −3 src/UA.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',
@@ -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;
@@ -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();
}
};

/**
@@ -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);
}
};

/**
@@ -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) {

0 comments on commit 659c331

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