From fddf6be33980b43b18d3c3cbee76321777063fff Mon Sep 17 00:00:00 2001 From: "vikasmarwaha@webrtc.org" Date: Wed, 29 May 2013 22:13:19 +0000 Subject: [PATCH] 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 --- samples/js/apprtc/js/main.js | 8 ++++---- samples/js/base/adapter.js | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/samples/js/apprtc/js/main.js b/samples/js/apprtc/js/main.js index 89a2bfdc1c..e0402f42ac 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 77d92b1ad3..62978f20f4 100644 --- a/samples/js/base/adapter.js +++ b/samples/js/base/adapter.js @@ -3,6 +3,7 @@ var getUserMedia = null; 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 @@ if (navigator.mozGetUserMedia) { // 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 @@ if (navigator.mozGetUserMedia) { 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;