From 8e1377ffaf480097a2ef9d2fef70ecf064bafa58 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Thu, 6 Mar 2014 16:48:16 +0100 Subject: [PATCH] Updated to latest version of webrtc.adapter.js. --- .../js/controllers/mediastreamcontroller.js | 2 +- static/js/libs/webrtc.adapter.js | 90 +++++++++++++++---- static/js/libs/webrtc.ice.js | 27 ------ static/js/main.js | 1 - 4 files changed, 76 insertions(+), 44 deletions(-) delete mode 100644 static/js/libs/webrtc.ice.js diff --git a/static/js/controllers/mediastreamcontroller.js b/static/js/controllers/mediastreamcontroller.js index 0fc24277..ec942391 100644 --- a/static/js/controllers/mediastreamcontroller.js +++ b/static/js/controllers/mediastreamcontroller.js @@ -18,7 +18,7 @@ * along with this program. If not, see . * */ -define(['underscore', 'bigscreen', 'moment', 'webrtc.adapter', 'webrtc.ice'], function(_, BigScreen, moment) { +define(['underscore', 'bigscreen', 'moment', 'webrtc.adapter'], function(_, BigScreen, moment) { return ["$scope", "$rootScope", "$window", "$timeout", "safeDisplayName", "safeApply", "mediaStream", "appData", "playSound", "desktopNotify", "alertify", "toastr", "translation", "fileDownload", function($scope, $rootScope, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload) { diff --git a/static/js/libs/webrtc.adapter.js b/static/js/libs/webrtc.adapter.js index c3d6c2d8..ca756533 100644 --- a/static/js/libs/webrtc.adapter.js +++ b/static/js/libs/webrtc.adapter.js @@ -36,7 +36,18 @@ var attachMediaStream = null; var reattachMediaStream = null; var webrtcDetectedBrowser = null; var webrtcDetectedVersion = null; -var createIceServer = null; + +function maybeFixConfiguration(pcConfig) { + if (pcConfig == null) { + return; + } + 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']; + } + } +} if (navigator.mozGetUserMedia) { console.log("This appears to be Firefox"); @@ -47,7 +58,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. + maybeFixConfiguration(pcConfig); + return new mozRTCPeerConnection(pcConfig, pcConstraints); + } // The RTCSessionDescription object. RTCSessionDescription = mozRTCSessionDescription; @@ -58,6 +73,7 @@ if (navigator.mozGetUserMedia) { // Get UserMedia (only difference is the prefix). // Code from Adam Barth. getUserMedia = navigator.mozGetUserMedia.bind(navigator); + navigator.getUserMedia = getUserMedia; // Creates iceServer from the url for FF. createIceServer = function(url, username, password) { @@ -72,22 +88,37 @@ if (navigator.mozGetUserMedia) { // Ignore the transport parameter from TURN url for FF version <=27. var turn_url_parts = url.split("?"); // Return null for createIceServer if transport=tcp. - if (turn_url_parts[1].indexOf('transport=udp') === 0) { - iceServer = { 'url': turn_url_parts[0], - 'credential': password, - 'username': username }; + if (turn_url_parts.length === 1 || + turn_url_parts[1].indexOf('transport=udp') === 0) { + 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"); @@ -101,13 +132,14 @@ if (navigator.mozGetUserMedia) { to.play(); }; - // Unify api for Firefox < 23. + // Fake get{Video,Audio}Tracks if (!MediaStream.prototype.getVideoTracks) { - // Fake get{Video,Audio}Tracks for Firefox < 23 MediaStream.prototype.getVideoTracks = function() { return []; }; + } + if (!MediaStream.prototype.getAudioTracks) { MediaStream.prototype.getAudioTracks = function() { return []; }; @@ -119,7 +151,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(':'); @@ -128,19 +160,47 @@ if (navigator.mozGetUserMedia) { iceServer = { 'url': url }; } else if (url_parts[0].indexOf('turn') === 0) { // Chrome M28 & above uses below TURN format. - iceServer = { 'url': url, + 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 iceServer; + return iceServers; }; // The RTCPeerConnection object. - RTCPeerConnection = webkitRTCPeerConnection; + var RTCPeerConnection = function(pcConfig, pcConstraints) { + // .urls is supported since Chrome M34. + if (webrtcDetectedVersion < 34) { + maybeFixConfiguration(pcConfig); + } + return new webkitRTCPeerConnection(pcConfig, pcConstraints); + } // Get UserMedia (only difference is the prefix). // Code from Adam Barth. getUserMedia = navigator.webkitGetUserMedia.bind(navigator); + navigator.getUserMedia = getUserMedia; // Attach a media stream to an element. attachMediaStream = function(element, stream) { diff --git a/static/js/libs/webrtc.ice.js b/static/js/libs/webrtc.ice.js deleted file mode 100644 index a684d5a8..00000000 --- a/static/js/libs/webrtc.ice.js +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Simple helper to handle ICE settings with multiple URLs until the browsers - * support it. - * See https://www.w3.org/Bugs/Public/show_bug.cgi?id=22347 - * and https://code.google.com/p/webrtc/issues/detail?id=2096 - * - * Copyright 2013-2014 struktur - http://www.struktur.de - * LICENSE: WTFPL - */ - -var createIceServers = null; - -if (navigator.mozGetUserMedia || navigator.webkitGetUserMedia) { - - // Creates iceServers list from the urls for Chrome and FF. - createIceServers = function(urls, username, credential) { - var iceServers = []; - for (var i=0; i