diff --git a/static/js/libs/webrtc.adapter.js b/static/js/libs/webrtc.adapter.js index b4d0629c..6f1c14af 100644 --- a/static/js/libs/webrtc.adapter.js +++ b/static/js/libs/webrtc.adapter.js @@ -37,117 +37,114 @@ var reattachMediaStream = null; var webrtcDetectedBrowser = null; var webrtcDetectedVersion = null; -function maybeFixConfiguration(pcConfig) { - if (!pcConfig) { - 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"); + console.log('This appears to be Firefox'); - webrtcDetectedBrowser = "firefox"; + webrtcDetectedBrowser = 'firefox'; webrtcDetectedVersion = - parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1], 10); + parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1], 10); // The RTCPeerConnection object. - var RTCPeerConnection = function(pcConfig, pcConstraints) { + window.RTCPeerConnection = function(pcConfig, pcConstraints) { // .urls is not supported in FF yet. - maybeFixConfiguration(pcConfig); + if (pcConfig && pcConfig.iceServers) { + 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 new mozRTCPeerConnection(pcConfig, pcConstraints); - } + }; // The RTCSessionDescription object. - RTCSessionDescription = mozRTCSessionDescription; + window.RTCSessionDescription = mozRTCSessionDescription; // The RTCIceCandidate object. - RTCIceCandidate = mozRTCIceCandidate; + window.RTCIceCandidate = mozRTCIceCandidate; - // Get UserMedia (only difference is the prefix). + // getUserMedia shim (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) { + // Shim for MediaStreamTrack.getSources. + MediaStreamTrack.getSources = function(successCb) { + setTimeout(function() { + var infos = [ + {kind: 'audio', id: 'default', label:'', facing:''}, + {kind: 'video', id: 'default', label:'', facing:''} + ]; + successCb(infos); + }, 0); + }; + + // Creates ICE server from the URL for FF. + window.createIceServer = function(url, username, password) { var iceServer = null; - var url_parts = url.split(':'); - if (url_parts[0].indexOf('stun') === 0) { - // Create iceServer with stun url. - iceServer = { 'url': url }; - } else if (url_parts[0].indexOf('turn') === 0) { + var urlParts = url.split(':'); + if (urlParts[0].indexOf('stun') === 0) { + // Create ICE server with STUN URL. + iceServer = { + 'url': url + }; + } else if (urlParts[0].indexOf('turn') === 0) { if (webrtcDetectedVersion < 27) { // Create iceServer with turn url. // Ignore the transport parameter from TURN url for FF version <=27. - var turn_url_parts = url.split("?"); + var turnUrlParts = url.split('?'); // 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}; + if (turnUrlParts.length === 1 || + turnUrlParts[1].indexOf('transport=udp') === 0) { + iceServer = { + 'url': turnUrlParts[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) { + window.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); + for (var i = 0; i < urls.length; i++) { + var iceServer = + window.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"); + console.log('Attaching media stream'); element.mozSrcObject = stream; - element.play(); }; reattachMediaStream = function(to, from) { - console.log("Reattaching media stream"); + console.log('Reattaching media stream'); to.mozSrcObject = from.mozSrcObject; - to.play(); }; - // Fake get{Video,Audio}Tracks - if (!MediaStream.prototype.getVideoTracks) { - MediaStream.prototype.getVideoTracks = function() { - return []; - }; - } - - if (!MediaStream.prototype.getAudioTracks) { - MediaStream.prototype.getAudioTracks = function() { - return []; - }; - } } else if (navigator.webkitGetUserMedia) { - console.log("This appears to be Chrome"); + console.log('This appears to be Chrome'); - webrtcDetectedBrowser = "chrome"; + webrtcDetectedBrowser = 'chrome'; // Temporary fix until crbug/374263 is fixed. // Setting Chrome version to 999, if version is unavailable. var result = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); @@ -158,50 +155,38 @@ if (navigator.mozGetUserMedia) { } // Creates iceServer from the url for Chrome M33 and earlier. - createIceServer = function(url, username, password) { + window.createIceServer = function(url, username, password) { var iceServer = null; - var url_parts = url.split(':'); - if (url_parts[0].indexOf('stun') === 0) { + var urlParts = url.split(':'); + if (urlParts[0].indexOf('stun') === 0) { // Create iceServer with stun url. - iceServer = { 'url': url }; - } else if (url_parts[0].indexOf('turn') === 0) { + iceServer = { + 'url': url + }; + } else if (urlParts[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; + // Creates an ICEServer object from multiple URLs. + window.createIceServers = function(urls, username, password) { + return { + 'urls': urls, + 'credential': password, + 'username': username + }; }; // The RTCPeerConnection object. - var RTCPeerConnection = function(pcConfig, pcConstraints) { - // .urls is supported since Chrome M34. - if (webrtcDetectedVersion < 34) { - maybeFixConfiguration(pcConfig); - } + RTCPeerConnection = function(pcConfig, pcConstraints) { return new webkitRTCPeerConnection(pcConfig, pcConstraints); - } + }; // Get UserMedia (only difference is the prefix). // Code from Adam Barth. @@ -225,5 +210,5 @@ if (navigator.mozGetUserMedia) { to.src = from.src; }; } else { - console.log("Browser does not appear to be WebRTC-capable"); + console.log('Browser does not appear to be WebRTC-capable'); }