AppRTC Sample: Switch AppRTC to use RTCIceServer.urls.
BUG=2832 TEST=Manual Test R=juberti@google.com Review URL: https://webrtc-codereview.appspot.com/7739004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5599 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
55fcd716f3
commit
bc0470f559
@ -60,10 +60,10 @@ def make_pc_config(stun_server, turn_server, ts_pwd):
|
||||
servers = []
|
||||
if turn_server:
|
||||
turn_config = 'turn:{}'.format(turn_server)
|
||||
servers.append({'url':turn_config, 'credential':ts_pwd})
|
||||
servers.append({'urls':turn_config, 'credential':ts_pwd})
|
||||
if stun_server:
|
||||
stun_config = 'stun:{}'.format(stun_server)
|
||||
servers.append({'url':stun_config})
|
||||
servers.append({'urls':stun_config})
|
||||
return {'iceServers':servers}
|
||||
|
||||
def create_channel(room, user, duration_minutes):
|
||||
|
@ -71,13 +71,14 @@ function openChannel() {
|
||||
}
|
||||
|
||||
function maybeRequestTurn() {
|
||||
// Allow to skip turn by passing ts=false to apprtc.
|
||||
if (turnUrl == '') {
|
||||
turnDone = true;
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0, len = pcConfig.iceServers.length; i < len; i++) {
|
||||
if (pcConfig.iceServers[i].url.substr(0, 5) === 'turn:') {
|
||||
if (pcConfig.iceServers[i].urls.substr(0, 5) === 'turn:') {
|
||||
turnDone = true;
|
||||
return;
|
||||
}
|
||||
@ -104,14 +105,12 @@ function onTurnResult() {
|
||||
|
||||
if (xmlhttp.status === 200) {
|
||||
var turnServer = JSON.parse(xmlhttp.responseText);
|
||||
for (i = 0; i < turnServer.uris.length; i++) {
|
||||
// Create a turnUri using the polyfill (adapter.js).
|
||||
var iceServer = createIceServer(turnServer.uris[i],
|
||||
// Create turnUris using the polyfill (adapter.js).
|
||||
var iceServers = createIceServers(turnServer.uris,
|
||||
turnServer.username,
|
||||
turnServer.password);
|
||||
if (iceServer !== null) {
|
||||
pcConfig.iceServers.push(iceServer);
|
||||
}
|
||||
if (iceServers !== null) {
|
||||
pcConfig.iceServers = pcConfig.iceServers.concat(iceServers);
|
||||
}
|
||||
} else {
|
||||
messageError('No TURN server; unlikely that media will traverse networks. '
|
||||
|
@ -12,6 +12,15 @@ function trace(text) {
|
||||
}
|
||||
console.log((performance.now() / 1000).toFixed(3) + ": " + text);
|
||||
}
|
||||
function maybeFixConfiguration(pcConfig) {
|
||||
for (var i = 0; i < pcConfig.iceServers.length; i++) {
|
||||
if (pcConfig.iceServers[i].hasOwnProperty('urls')){
|
||||
pcConfig.iceServers[i]['url'] = pcConfig.iceServers[i]['urls'];
|
||||
delete pcConfig.iceServers[i]['urls'];
|
||||
}
|
||||
}
|
||||
return pcConfig;
|
||||
}
|
||||
|
||||
if (navigator.mozGetUserMedia) {
|
||||
console.log("This appears to be Firefox");
|
||||
@ -22,7 +31,11 @@ if (navigator.mozGetUserMedia) {
|
||||
parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1], 10);
|
||||
|
||||
// The RTCPeerConnection object.
|
||||
RTCPeerConnection = mozRTCPeerConnection;
|
||||
var RTCPeerConnection = function(pcConfig, pcConstraints) {
|
||||
// .urls is not supported in FF yet.
|
||||
pcConfig = maybeFixConfiguration(pcConfig);
|
||||
return new mozRTCPeerConnection(pcConfig, pcConstraints);
|
||||
}
|
||||
|
||||
// The RTCSessionDescription object.
|
||||
RTCSessionDescription = mozRTCSessionDescription;
|
||||
@ -50,21 +63,35 @@ if (navigator.mozGetUserMedia) {
|
||||
// Return null for createIceServer if transport=tcp.
|
||||
if (turn_url_parts.length === 1 ||
|
||||
turn_url_parts[1].indexOf('transport=udp') === 0) {
|
||||
iceServer = { 'url': turn_url_parts[0],
|
||||
'credential': password,
|
||||
'username': username };
|
||||
iceServer = {'url': turn_url_parts[0],
|
||||
'credential': password,
|
||||
'username': username};
|
||||
}
|
||||
} else {
|
||||
// FF 27 and above supports transport parameters in TURN url,
|
||||
// So passing in the full url to create iceServer.
|
||||
iceServer = { 'url': url,
|
||||
'credential': password,
|
||||
'username': username };
|
||||
iceServer = {'url': url,
|
||||
'credential': password,
|
||||
'username': username};
|
||||
}
|
||||
}
|
||||
return iceServer;
|
||||
};
|
||||
|
||||
createIceServers = function(urls, username, password) {
|
||||
var iceServers = [];
|
||||
// Use .url for FireFox.
|
||||
for (i = 0; i < urls.length; i++) {
|
||||
var iceServer = createIceServer(urls[i],
|
||||
username,
|
||||
password);
|
||||
if (iceServer !== null) {
|
||||
iceServers.push(iceServer);
|
||||
}
|
||||
}
|
||||
return iceServers;
|
||||
}
|
||||
|
||||
// Attach a media stream to an element.
|
||||
attachMediaStream = function(element, stream) {
|
||||
console.log("Attaching media stream");
|
||||
@ -97,7 +124,7 @@ if (navigator.mozGetUserMedia) {
|
||||
webrtcDetectedVersion =
|
||||
parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2], 10);
|
||||
|
||||
// Creates iceServer from the url for Chrome.
|
||||
// Creates iceServer from the url for Chrome M33 and earlier.
|
||||
createIceServer = function(url, username, password) {
|
||||
var iceServer = null;
|
||||
var url_parts = url.split(':');
|
||||
@ -106,15 +133,42 @@ if (navigator.mozGetUserMedia) {
|
||||
iceServer = { 'url': url };
|
||||
} else if (url_parts[0].indexOf('turn') === 0) {
|
||||
// Chrome M28 & above uses below TURN format.
|
||||
iceServer = { 'url': url,
|
||||
'credential': password,
|
||||
'username': username };
|
||||
iceServer = {'url': url,
|
||||
'credential': password,
|
||||
'username': username};
|
||||
}
|
||||
return iceServer;
|
||||
};
|
||||
|
||||
// Creates iceServers from the urls for Chrome M34 and above.
|
||||
createIceServers = function(urls, username, password) {
|
||||
var iceServers = [];
|
||||
if (webrtcDetectedVersion >= 34) {
|
||||
// .urls is supported since Chrome M34.
|
||||
iceServers = {'urls': urls,
|
||||
'credential': password,
|
||||
'username': username };
|
||||
} else {
|
||||
for (i = 0; i < urls.length; i++) {
|
||||
var iceServer = createIceServer(urls[i],
|
||||
username,
|
||||
password);
|
||||
if (iceServer !== null) {
|
||||
iceServers.push(iceServer);
|
||||
}
|
||||
}
|
||||
}
|
||||
return iceServers;
|
||||
};
|
||||
|
||||
// The RTCPeerConnection object.
|
||||
RTCPeerConnection = webkitRTCPeerConnection;
|
||||
var RTCPeerConnection = function(pcConfig, pcConstraints) {
|
||||
// .urls is supported since Chrome M34.
|
||||
if (webrtcDetectedVersion < 34) {
|
||||
pcConfig = maybeFixConfiguration(pcConfig);
|
||||
}
|
||||
return new webkitRTCPeerConnection(pcConfig, pcConstraints);
|
||||
}
|
||||
|
||||
// Get UserMedia (only difference is the prefix).
|
||||
// Code from Adam Barth.
|
||||
|
Loading…
x
Reference in New Issue
Block a user