Skip to content

Commit 659c331

Browse files
committed
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.
1 parent d3bc91a commit 659c331

File tree

5 files changed

+37
-29
lines changed

5 files changed

+37
-29
lines changed

src/Constants.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ JsSIP.C= {
4343
// SIP schemes
4444
SIP: 'sip',
4545

46+
// Invalid target
47+
INVALID_TARGET: 'sip:invalid@invalid',
48+
4649
// Transaction states
4750
TRANSACTION_TRYING: 1,
4851
TRANSACTION_PROCEEDING: 2,
@@ -71,8 +74,14 @@ JsSIP.C= {
7174
CONNECTION_ERROR: 1,
7275
REQUEST_TIMEOUT: 2,
7376

74-
// Invite session end causes
77+
// End and failure causes
7578
causes: {
79+
80+
// Generic error causes
81+
INVALID_TARGET: 'Invalid target',
82+
WEBRTC_NOT_SUPPORTED: 'WebRTC not supported',
83+
84+
// Invite session end causes
7685
BYE: 'Terminated',
7786
CANCELED: 'Canceled',
7887
NO_ANSWER: 'No Answer',
@@ -85,7 +94,7 @@ JsSIP.C= {
8594
IN_DIALOG_408_OR_481: 'In-dialog 408 or 481',
8695
SIP_FAILURE_CODE: 'SIP Failure Code',
8796

88-
// SIP ERROR CAUSES
97+
// SIP error causes
8998
BUSY: 'Busy',
9099
REJECTED: 'Rejected',
91100
REDIRECTED: 'Redirected',

src/Exceptions.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ JsSIP.Exceptions= {
4343
return exception;
4444
}()),
4545

46-
WebRtcNotSupportedError: (function(){
47-
var exception = function(){
48-
this.code = 4;
49-
this.name = 'WEBRTC_NO_SUPPORTED_ERROR';
50-
};
51-
exception.prototype = new Error();
52-
return exception;
53-
}()),
54-
5546
InvalidStateError: (function(){
5647
var exception = function(status) {
5748
this.code = 5;

src/Message.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ JsSIP.Message.prototype.send = function(target, body, options) {
2626
'failed'
2727
];
2828

29-
JsSIP.Utils.checkUAStatus(this.ua);
30-
3129
this.initEvents(events);
3230

3331
// Get call options
@@ -42,7 +40,11 @@ JsSIP.Message.prototype.send = function(target, body, options) {
4240
}
4341

4442
// Check target validity
45-
target = JsSIP.Utils.normalizeURI(target, this.ua.configuration.domain);
43+
try {
44+
target = JsSIP.Utils.normalizeURI(target, this.ua.configuration.domain);
45+
} catch(e) {
46+
target = JsSIP.C.INVALID_TARGET;
47+
}
4648

4749
// Message parameter initialization
4850
this.direction = 'outgoing';
@@ -73,7 +75,14 @@ JsSIP.Message.prototype.send = function(target, body, options) {
7375
request: this.request
7476
});
7577

76-
request_sender.send();
78+
if (target === JsSIP.C.INVALID_TARGET) {
79+
this.emit('failed', this, {
80+
originator: 'local',
81+
cause: JsSIP.C.causes.INVALID_TARGET
82+
});
83+
} else {
84+
request_sender.send();
85+
}
7786
};
7887

7988
/**

src/Session.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ JsSIP.Session.prototype.init_incoming = function(request) {
7676
JsSIP.Session.prototype.connect = function(target, views, options) {
7777
var event, eventHandlers, request, selfView, remoteView, mediaTypes, extraHeaders, requestParams;
7878

79-
// Check UA Status
80-
JsSIP.Utils.checkUAStatus(this.ua);
81-
82-
// Check WebRTC support
83-
if(!JsSIP.WebRTC.isSupported) {
84-
console.log(JsSIP.C.LOG_UA +'WebRTC not supported.');
85-
throw new JsSIP.Exceptions.WebRtcNotSupportedError();
86-
}
87-
8879
// Check Session Status
8980
if (this.status !== JsSIP.C.SESSION_NULL) {
9081
throw new JsSIP.Exceptions.InvalidStateError(this.status);
@@ -110,7 +101,11 @@ JsSIP.Session.prototype.connect = function(target, views, options) {
110101
}
111102

112103
// Check target validity
113-
target = JsSIP.Utils.normalizeURI(target, this.ua.configuration.domain);
104+
try {
105+
target = JsSIP.Utils.normalizeURI(target, this.ua.configuration.domain);
106+
} catch(e) {
107+
target = JsSIP.C.INVALID_TARGET;
108+
}
114109

115110
// Session parameter initialization
116111
this.from_tag = JsSIP.Utils.newTag();
@@ -152,7 +147,14 @@ JsSIP.Session.prototype.connect = function(target, views, options) {
152147

153148
this.newSession('local', request, target);
154149
this.connecting('local', request, target);
155-
this.sendInitialRequest(mediaTypes);
150+
151+
if (target === JsSIP.C.INVALID_TARGET) {
152+
this.failed('local', null, JsSIP.C.causes.INVALID_TARGET);
153+
} else if (!JsSIP.WebRTC.isSupported) {
154+
this.failed('local', null, JsSIP.C.causes.WEBRTC_NOT_SUPPORTED);
155+
} else {
156+
this.sendInitialRequest(mediaTypes);
157+
}
156158
};
157159

158160
/**

src/UA.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ JsSIP.UA.prototype.isConnected = function() {
133133
* @param {Object} videoViews
134134
*
135135
* @throws {JsSIP.Exceptions.NotReadyError} If JsSIP.UA is not ready (see JsSIP.UA.status, JsSIP.UA.error parameters).
136-
* @throws {JsSIP.Exceptions.WebRtcNotSupportedError} If WebRTC is not supported by the client.
137-
* @throws {JsSIP.Exceptions.InvalidTargetError} If the calling target is invalid.
138136
*
139137
*/
140138
JsSIP.UA.prototype.call = function(target, views, options) {
@@ -152,7 +150,6 @@ JsSIP.UA.prototype.call = function(target, views, options) {
152150
* @param {Object} [eventHandlers]
153151
*
154152
* @throws {JsSIP.Exceptions.NotReadyError} If JsSIP.UA is not ready (see JsSIP.UA.status, JsSIP.UA.error parameters).
155-
* @throws {JsSIP.Exceptions.InvalidTargetError} If the calling target is invalid.
156153
*
157154
*/
158155
JsSIP.UA.prototype.sendMessage = function(target, body, options) {

0 commit comments

Comments
 (0)