Skip to content

Commit

Permalink
New way to handle InvalidTargetErorr and WebRtcNotSupportedError
Browse files Browse the repository at this point in the history
.. 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 659c331
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 29 deletions.
13 changes: 11 additions & 2 deletions src/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
9 changes: 0 additions & 9 deletions src/Exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 13 additions & 4 deletions src/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ JsSIP.Message.prototype.send = function(target, body, options) {
'failed'
];

JsSIP.Utils.checkUAStatus(this.ua);

this.initEvents(events);

// Get call options
Expand All @@ -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';
Expand Down Expand Up @@ -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();
}
};

/**
Expand Down
24 changes: 13 additions & 11 deletions src/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
};

/**
Expand Down
3 changes: 0 additions & 3 deletions src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 659c331

Please sign in to comment.