Skip to content

Commit

Permalink
Rename 'outbound_proxy_set' parameter by 'ws_servers'
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillan committed Feb 1, 2013
1 parent 9713c2c commit 5616837
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/Transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @augments JsSIP
* @class Transport
* @param {JsSIP.UA} ua
* @param {Object} server outbound_proxy_set Object
* @param {Object} server ws_server Object
*/

JsSIP.Transport = function(ua, server) {
Expand Down
73 changes: 36 additions & 37 deletions src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,25 +531,24 @@ JsSIP.UA.prototype.findDialog = function(request) {
/**
* Retrieve the next server to which connect.
* @private
* @returns {Object} outbound_proxy_set
* @returns {Object} ws_server
*/
JsSIP.UA.prototype.getNextWsServer = function() {
// Order servers by weight
var idx, outbound_proxy_set,
var idx, ws_server,
candidates = [];

for (idx in this.configuration.outbound_proxy_set) {
outbound_proxy_set = this.configuration.outbound_proxy_set[idx];
for (idx in this.configuration.ws_servers) {
ws_server = this.configuration.ws_servers[idx];

if (outbound_proxy_set.status === 2) {
if (ws_server.status === 2) {
continue;
} else if (candidates.length === 0) {
candidates.push(outbound_proxy_set);
} else if (outbound_proxy_set.weight > candidates[0].weight) {
candidates = [];
candidates.push(outbound_proxy_set);
} else if (outbound_proxy_set.weight === candidates[0].weight) {
candidates.push(outbound_proxy_set);
candidates.push(ws_server);
} else if (ws_server.weight > candidates[0].weight) {
candidates = [ws_server];
} else if (ws_server.weight === candidates[0].weight) {
candidates.push(ws_server);
}
}

Expand Down Expand Up @@ -581,8 +580,8 @@ JsSIP.UA.prototype.recoverTransport = function(ua) {
ua = ua || this;
count = ua.transportRecoverAttempts;

for (idx in ua.configuration.outbound_proxy_set) {
ua.configuration.outbound_proxy_set[idx].status = 0;
for (idx in ua.configuration.ws_servers) {
ua.configuration.ws_servers[idx].status = 0;
}

server = ua.getNextWsServer();
Expand Down Expand Up @@ -650,18 +649,18 @@ JsSIP.UA.prototype.loadConfig = function(configuration) {

// Pre-Configuration

/* Allow defining outbound_proxy_set parameter as:
/* Allow defining ws_servers parameter as:
* String: "host"
* Array of Strings: ["host1", "host2"]
* Array of Objects: [{ws_uri:"host1", weight:1}, {ws_uri:"host2", weight:0}]
* Array of Objects and Strings: [{ws_uri:"host1"}, "host2"]
*/
if (typeof configuration.outbound_proxy_set === 'string'){
configuration.outbound_proxy_set = [{ws_uri:configuration.outbound_proxy_set}];
} else if (configuration.outbound_proxy_set instanceof Array) {
for(idx in configuration.outbound_proxy_set) {
if (typeof configuration.outbound_proxy_set[idx] === 'string'){
configuration.outbound_proxy_set[idx] = {ws_uri:configuration.outbound_proxy_set[idx]};
if (typeof configuration.ws_servers === 'string'){
configuration.ws_servers = [{ws_uri:configuration.ws_servers}];
} else if (configuration.ws_servers instanceof Array) {
for(idx in configuration.ws_servers) {
if (typeof configuration.ws_servers[idx] === 'string'){
configuration.ws_servers[idx] = {ws_uri:configuration.ws_servers[idx]};
}
}
}
Expand Down Expand Up @@ -736,17 +735,17 @@ JsSIP.UA.prototype.loadConfig = function(configuration) {
}

// Transports
for (idx in configuration.outbound_proxy_set) {
ws_uri = JsSIP.grammar.parse(settings.outbound_proxy_set[idx].ws_uri, 'absoluteURI');
for (idx in configuration.ws_servers) {
ws_uri = JsSIP.grammar.parse(settings.ws_servers[idx].ws_uri, 'absoluteURI');

settings.outbound_proxy_set[idx].sip_uri = '<sip:' + ws_uri.host + (ws_uri.port ? ':' + ws_uri.port : '') + ';transport=ws;lr>';
settings.ws_servers[idx].sip_uri = '<sip:' + ws_uri.host + (ws_uri.port ? ':' + ws_uri.port : '') + ';transport=ws;lr>';

if (!settings.outbound_proxy_set[idx].weight) {
settings.outbound_proxy_set[idx].weight = 0;
if (!settings.ws_servers[idx].weight) {
settings.ws_servers[idx].weight = 0;
}

settings.outbound_proxy_set[idx].status = 0;
settings.outbound_proxy_set[idx].scheme = ws_uri.scheme.toUpperCase();
settings.ws_servers[idx].status = 0;
settings.ws_servers[idx].scheme = ws_uri.scheme.toUpperCase();

}

Expand Down Expand Up @@ -802,7 +801,7 @@ JsSIP.UA.configuration_skeleton = (function() {
"register_min_expires",

// Mandatory user configurable parameters
"outbound_proxy_set",
"ws_servers",
"uri",

// Optional user configurable parameters
Expand Down Expand Up @@ -850,27 +849,27 @@ JsSIP.UA.configuration_skeleton = (function() {
*/
JsSIP.UA.configuration_check = {
mandatory: {
outbound_proxy_set: function(outbound_proxy_set) {
ws_servers: function(ws_servers) {
var idx, url;

if (outbound_proxy_set.length === 0) {
if (ws_servers.length === 0) {
return false;
}

for (idx in outbound_proxy_set) {
if (!outbound_proxy_set[idx].ws_uri) {
console.log(JsSIP.C.LOG_UA +'Missing "ws_uri" attribute in outbound_proxy_set parameter');
for (idx in ws_servers) {
if (!ws_servers[idx].ws_uri) {
console.log(JsSIP.C.LOG_UA +'Missing "ws_uri" attribute in ws_servers parameter');
return false;
}
if (outbound_proxy_set[idx].weight && !Number(outbound_proxy_set[idx].weight)) {
console.log(JsSIP.C.LOG_UA +'"weight" attribute in outbound_proxy_set parameter must be a Number');
if (ws_servers[idx].weight && !Number(ws_servers[idx].weight)) {
console.log(JsSIP.C.LOG_UA +'"weight" attribute in ws_servers parameter must be a Number');
return false;
}

url = JsSIP.grammar.parse(outbound_proxy_set[idx].ws_uri, 'absoluteURI');
url = JsSIP.grammar.parse(ws_servers[idx].ws_uri, 'absoluteURI');

if(url === -1) {
console.log(JsSIP.C.LOG_UA +'Invalid "ws_uri" attribute in outbound_proxy_set parameter: ' + outbound_proxy_set[idx].ws_uri);
console.log(JsSIP.C.LOG_UA +'Invalid "ws_uri" attribute in ws_servers parameter: ' + ws_servers[idx].ws_uri);
return false;
} else if(url.scheme !== 'wss' && url.scheme !== 'ws') {
console.log(JsSIP.C.LOG_UA +'Invalid url scheme: ' + url.scheme);
Expand Down

0 comments on commit 5616837

Please sign in to comment.