Updated apprtc to use new TURN format for chrome versions M28 & above.
R=dutton@google.com, juberti@google.com
Review URL: https://webrtc-codereview.appspot.com/1563004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@4139 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/samples/js/apprtc/js/main.js b/samples/js/apprtc/js/main.js
index 89a2bfd..e0402f4 100644
--- a/samples/js/apprtc/js/main.js
+++ b/samples/js/apprtc/js/main.js
@@ -75,10 +75,10 @@
function onTurnResult() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var turnServer = JSON.parse(xmlhttp.responseText);
- pcConfig.iceServers.push({
- 'url': 'turn:' + turnServer.username + '@' + turnServer.turn,
- 'credential': turnServer.password
- });
+ // Create a turnUri using the polyfill (adapter.js).
+ var iceServer = createIceServer(turnServer.uris[0], turnServer.username,
+ turnServer.password);
+ pcConfig.iceServers.push(iceServer);
} else {
console.log("Request for TURN server failed.")
}
diff --git a/samples/js/base/adapter.js b/samples/js/base/adapter.js
index 77d92b1..62978f2 100644
--- a/samples/js/base/adapter.js
+++ b/samples/js/base/adapter.js
@@ -3,6 +3,7 @@
var attachMediaStream = null;
var reattachMediaStream = null;
var webrtcDetectedBrowser = null;
+var webrtcDetectedVersion = null;
function trace(text) {
// This function is used for logging.
@@ -30,6 +31,14 @@
// Code from Adam Barth.
getUserMedia = navigator.mozGetUserMedia.bind(navigator);
+ // Creates Turn Uri with new turn format.
+ createIceServer = function(turn_url, username, password) {
+ var iceServer = { 'url': turn_url,
+ 'credential': password,
+ 'username': username };
+ return iceServer;
+ };
+
// Attach a media stream to an element.
attachMediaStream = function(element, stream) {
console.log("Attaching media stream");
@@ -55,6 +64,24 @@
console.log("This appears to be Chrome");
webrtcDetectedBrowser = "chrome";
+ webrtcDetectedVersion =
+ parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]);
+
+ // For pre-M28 chrome versions use old turn format, else use the new format.
+ if (webrtcDetectedVersion < 28) {
+ createIceServer = function(turn_url, username, password) {
+ var iceServer = { 'url': 'turn:' + username + '@' + turn_url,
+ 'credential': password };
+ return iceServer;
+ };
+ } else {
+ createIceServer = function(turn_url, username, password) {
+ var iceServer = { 'url': turn_url,
+ 'credential': password,
+ 'username': username };
+ return iceServer;
+ };
+ }
// The RTCPeerConnection object.
RTCPeerConnection = webkitRTCPeerConnection;