Skip to content
Permalink
Browse files

Add turn configuration parameters for RTCPeerConnection

* new configuration parameters: turn_server, turn_username, turn_password
  • Loading branch information
jmillan committed Dec 13, 2012
1 parent 9fccaf5 commit 3acc4745b9bfaec27f7ab180249bb8e63dd77052
Showing with 82 additions and 9 deletions.
  1. +8 −2 src/MediaSession.js
  2. +43 −7 src/UA.js
  3. +31 −0 src/grammar/src/grammar.pegjs
@@ -105,8 +105,14 @@ JsSIP.MediaSession.prototype = {
var
session = this,
sent = false,
stun_config = 'stun:'+this.session.ua.configuration.stun_server,
servers = [{"url": stun_config}];
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} ];

if (turn_uri) {
servers.push({"url": turn_uri, "credential": turn_password});
}

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

@@ -631,7 +631,7 @@ JsSIP.UA.prototype.loadConfig = function(configuration) {

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

// Loggin parameters
trace_sip: false,
@@ -696,6 +696,14 @@ 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
@@ -741,6 +749,14 @@ 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}
};
@@ -795,6 +811,10 @@ JsSIP.UA.configuration_skeleton = (function() {
"hack_ip_in_contact", //false
"password",
"stun_server",
"turn_server",
"turn_username",
"turn_password",
"turn_uri",
"no_answer_timeout", // 30 seconds.
"register_expires", // 600 seconds.
"trace_sip",
@@ -913,12 +933,28 @@ JsSIP.UA.configuration_check = {
}
},
stun_server: function(stun_server) {
var parsed;

parsed = JsSIP.grammar.parse(stun_server, 'hostport');

if(parsed === -1) {
console.log(JsSIP.c.LOG_UA +'Invalid stun_server: ' + 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;
}
},
turn_password: function(turn_password) {
if(JsSIP.grammar.parse(turn_password, 'password') === -1) {
return false;
} else {
return true;
@@ -688,6 +688,37 @@ header_value = (TEXT_UTF8char / UTF8_CONT / LWS)*

message_body = OCTET*


// STUN URI (draft-nandakumar-rtcweb-stun-uri)

stun_URI = stun_scheme ":" stun_host_port

stun_scheme = scheme: ("stuns" / "stun") {
data.scheme = scheme; }

stun_host_port = stun_host ( ":" port )?

stun_host = host: (reg_name / IPv4address / IPv6reference) {
data.host = host.join(''); }

reg_name = ( stun_unreserved / escaped / sub_delims )*

stun_unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"

sub_delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="


// TURN URI (draft-petithuguenin-behave-turn-uris)

turn_URI = turn_scheme ":" stun_host_port ( "?transport=" transport )?

turn_scheme = scheme: ("turns" / "turn") {
data.scheme = scheme; }

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


// Lazy uri

lazy_uri = (uri_scheme ':')? user ('@' hostport)? uri_parameters

0 comments on commit 3acc474

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