Skip to content

Commit

Permalink
New stun_servers and turn_servers parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jan 25, 2013
1 parent 22f5964 commit d0dbde3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
19 changes: 11 additions & 8 deletions src/MediaSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,20 @@ JsSIP.MediaSession.prototype = {
* @param {Function} onSuccess Fired when there are no more ICE candidates
*/
start: function(onSuccess) {
var
var idx, server,
session = this,
sent = false,
stun_uri = this.session.ua.configuration.stun_server,
turn_uri = this.session.ua.configuration.turn_uri,
turn_password = this.session.ua.configuration.turn_password,
servers = [ {"url": stun_uri} ];
servers = [];

if (turn_uri) {
servers.push({"url": turn_uri, "credential": turn_password});
}
for (idx in this.session.ua.configuration.stun_servers) {
server = this.session.ua.configuration.stun_server[idx];
servers.push({'url': server});
}

for (idx in this.session.ua.configuration.turn_servers) {
server = this.session.ua.configuration.turn_servers[idx];
servers.push({'url': server.username +'@'+ server.server, 'credential': server.password});
}

this.peerConnection = new webkitRTCPeerConnection({"iceServers": servers});

Expand Down
89 changes: 43 additions & 46 deletions src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ JsSIP.UA.prototype.loadConfig = function(configuration) {

// Session parameters
no_answer_timeout: 60,
stun_server: 'stun:stun.l.google.com:19302',
stun_servers: ['stun:stun.l.google.com:19302'],

// Logging parameters
trace_sip: false,
Expand Down Expand Up @@ -693,14 +693,6 @@ JsSIP.UA.prototype.loadConfig = function(configuration) {
return false;
}

// Turn
if (settings.turn_server) {
if (!settings.turn_username || !settings.turn_password) {
console.error('TURN username and password must be specified');
return false;
}
}

// Post Configuration Process

// Instance-id for GRUU
Expand Down Expand Up @@ -746,19 +738,19 @@ JsSIP.UA.prototype.loadConfig = function(configuration) {

}

// TURN URI
if (settings.turn_server) {
uri = JsSIP.grammar.parse(settings.turn_server, 'turn_URI');
settings.turn_uri = uri.scheme + ':';
settings.turn_uri += settings.turn_username + '@';
settings.turn_uri += settings.turn_server.substr(uri.scheme.length + 1);
}

contact = {
uri: {value: 'sip:' + uri.user + '@' + settings.via_host + ';transport=ws', writable: false, configurable: false}
};
Object.defineProperties(this.contact, contact);

// Stun servers
for (idx in configuration.stun_servers) {
uri = configuration.stun_servers[idx];
if (!(/^stuns?:/.test(uri))){
configuration.stun_servers[idx] = 'stun:' + uri;
}
}

// Fill the value of the configuration_skeleton
for(attribute in settings) {
JsSIP.UA.configuration_skeleton[attribute].value = settings[attribute];
Expand Down Expand Up @@ -807,11 +799,8 @@ JsSIP.UA.configuration_skeleton = (function() {
"hack_via_tcp", // false.
"hack_ip_in_contact", //false
"password",
"stun_server",
"turn_server",
"turn_username",
"turn_password",
"turn_uri",
"stun_servers",
"turn_servers",
"no_answer_timeout", // 30 seconds.
"register_expires", // 600 seconds.
"trace_sip",
Expand Down Expand Up @@ -929,33 +918,41 @@ JsSIP.UA.configuration_check = {
return true;
}
},
stun_server: function(stun_server) {
if(JsSIP.grammar.parse(stun_server, 'stun_URI') === -1) {
return false;
} else {
return true;
}
},
turn_server: function(turn_server) {
if(JsSIP.grammar.parse(turn_server, 'turn_URI') === -1) {
return false;
} else {
return true;
}
},
turn_username: function(turn_username) {
if(JsSIP.grammar.parse(turn_username, 'user') === -1) {
return false;
} else {
return true;
stun_servers: function(stun_servers) {
var idx, stun_server;

for (idx in stun_servers) {
stun_server = stun_servers[idx];
if (!(/^stuns?:/.test(stun_server))){
stun_server = 'stun:' + stun_server;
}

if(JsSIP.grammar.parse(stun_server, 'stun_URI') === -1) {
return false;
}
}
return true;
},
turn_password: function(turn_password) {
if(JsSIP.grammar.parse(turn_password, 'password') === -1) {
return false;
} else {
return true;
turn_servers: function(turn_servers) {
var idx, turn_server;

for (idx in turn_servers) {
turn_server = turn_servers[idx];
if (!turn_server.server || !turn_server.username || !turn_server.password) {
return false;
} else if (!(/^turns?:/.test(turn_server.server))){
turn_server.server = 'turn:' + turn_server.server;
}

if(JsSIP.grammar.parse(turn_server.server, 'turn_URI') === -1) {
return false;
} else if(JsSIP.grammar.parse(turn_server.username, 'user') === -1) {
return false;
} else if(JsSIP.grammar.parse(turn_server.password, 'password') === -1) {
return false;
}
}
return true;
},
no_answer_timeout: function(no_answer_timeout) {
if(!Number(no_answer_timeout)) {
Expand Down

0 comments on commit d0dbde3

Please sign in to comment.