Skip to content
Permalink
Browse files

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,..)
  • Loading branch information
jmillan committed Feb 6, 2013
1 parent a370c78 commit 7867bafac43dfacb095dd94c196dd107062eb0ee
Showing with 15 additions and 33 deletions.
  1. +1 −1 src/UA.js
  2. +13 −23 src/Utils.js
  3. +1 −9 src/grammar/src/grammar.pegjs
@@ -823,7 +823,7 @@ JsSIP.UA.configuration_check = {
uri: function(uri) {
var parsed;

parsed = JsSIP.Utils.createURI(uri);
parsed = JsSIP.Utils.parseURI(uri);

if(!parsed) {
console.log(JsSIP.C.LOG_UA +'Invalid uri: ' + uri);
@@ -31,7 +31,7 @@ JsSIP.Utils= {
return UUID;
},

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

if (target) {
uri = JsSIP.grammar.parse(target, 'lazy_uri');

if (uri === -1) {
console.log(JsSIP.C.LOG_UTILS + 'Invalid target: '+ target);
return;
}

if (!uri.host && !domain) {
console.log(JsSIP.C.LOG_UTILS + 'No domain specified in target nor as function parameter');
return;
if (!target) {
return;
} else if (target instanceof JsSIP.URI) {
return target;
} else if (typeof target === 'string') {
if (target.indexOf('@') === -1) {
if (domain) {
target += '@'+ domain;
} else {
return;
}
}

string = (uri.scheme || JsSIP.C.SIP) + ':';
string += uri.user;
string += '@' + (uri.host || domain);
string += (uri.port)? ':' + uri.port : '';

for (parameter in uri.params) {
string += ';'+ parameter;
string += (uri.params[parameter] === undefined)? '' : '='+ uri.params[parameter];
}
return string;
return JsSIP.Utils.parseURI(target);
}
},

@@ -744,12 +744,4 @@ turn_scheme = scheme: ("turns"i / "turn"i) {
data.scheme = scheme; }

turn_transport = transport ("udp"i / "tcp"i / unreserved*) {
data.transport = transport; }


// Lazy uri

lazy_uri = (uri_scheme ':')? user (':' password)? ('@' hostport)? {
if (data.password) {
data.user = data.user +':'+ data.password;
}}
data.transport = transport; }

1 comment on commit 7867baf

@saghul

This comment has been minimized.

Copy link
Contributor

saghul commented on 7867baf Feb 6, 2013

yeah! 🍰

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