Skip to content

Commit

Permalink
Allow using a JsSIP.URI instance everywhere specting a destination.
Browse files Browse the repository at this point in the history
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 7867baf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/UA.js
Expand Up @@ -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);
Expand Down
36 changes: 13 additions & 23 deletions src/Utils.js
Expand Up @@ -31,7 +31,7 @@ JsSIP.Utils= {
return UUID;
},

createURI: function(uri) {
parseURI: function(uri) {
if (!/^sip:/.test(uri)) {
uri = JsSIP.C.SIP +':'+ uri;
}
Expand Down Expand Up @@ -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);
}
},

Expand Down
10 changes: 1 addition & 9 deletions src/grammar/src/grammar.pegjs
Expand Up @@ -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
Copy link
Contributor

@saghul saghul commented on 7867baf Feb 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah! 🍰

Please sign in to comment.