Skip to content

Commit 7867baf

Browse files
committed
Allow using a JsSIP.URI instance everywhere specting a destination.
Do not limit the target to be only a String. Ie: - ua.call(target,..) - ua.sendMessage(target,..)
1 parent a370c78 commit 7867baf

File tree

3 files changed

+15
-33
lines changed

3 files changed

+15
-33
lines changed

src/UA.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ JsSIP.UA.configuration_check = {
823823
uri: function(uri) {
824824
var parsed;
825825

826-
parsed = JsSIP.Utils.createURI(uri);
826+
parsed = JsSIP.Utils.parseURI(uri);
827827

828828
if(!parsed) {
829829
console.log(JsSIP.C.LOG_UA +'Invalid uri: ' + uri);

src/Utils.js

+13-23
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ JsSIP.Utils= {
3131
return UUID;
3232
},
3333

34-
createURI: function(uri) {
34+
parseURI: function(uri) {
3535
if (!/^sip:/.test(uri)) {
3636
uri = JsSIP.C.SIP +':'+ uri;
3737
}
@@ -66,31 +66,21 @@ JsSIP.Utils= {
6666
* @param {String} [domain]
6767
*/
6868
normalizeURI: function(target, domain) {
69-
var uri, parameter, string;
7069

71-
if (target) {
72-
uri = JsSIP.grammar.parse(target, 'lazy_uri');
73-
74-
if (uri === -1) {
75-
console.log(JsSIP.C.LOG_UTILS + 'Invalid target: '+ target);
76-
return;
77-
}
78-
79-
if (!uri.host && !domain) {
80-
console.log(JsSIP.C.LOG_UTILS + 'No domain specified in target nor as function parameter');
81-
return;
70+
if (!target) {
71+
return;
72+
} else if (target instanceof JsSIP.URI) {
73+
return target;
74+
} else if (typeof target === 'string') {
75+
if (target.indexOf('@') === -1) {
76+
if (domain) {
77+
target += '@'+ domain;
78+
} else {
79+
return;
80+
}
8281
}
8382

84-
string = (uri.scheme || JsSIP.C.SIP) + ':';
85-
string += uri.user;
86-
string += '@' + (uri.host || domain);
87-
string += (uri.port)? ':' + uri.port : '';
88-
89-
for (parameter in uri.params) {
90-
string += ';'+ parameter;
91-
string += (uri.params[parameter] === undefined)? '' : '='+ uri.params[parameter];
92-
}
93-
return string;
83+
return JsSIP.Utils.parseURI(target);
9484
}
9585
},
9686

src/grammar/src/grammar.pegjs

+1-9
Original file line numberDiff line numberDiff line change
@@ -744,12 +744,4 @@ turn_scheme = scheme: ("turns"i / "turn"i) {
744744
data.scheme = scheme; }
745745

746746
turn_transport = transport ("udp"i / "tcp"i / unreserved*) {
747-
data.transport = transport; }
748-
749-
750-
// Lazy uri
751-
752-
lazy_uri = (uri_scheme ':')? user (':' password)? ('@' hostport)? {
753-
if (data.password) {
754-
data.user = data.user +':'+ data.password;
755-
}}
747+
data.transport = transport; }

0 commit comments

Comments
 (0)