Browse Source

Updated to latest version of webrtc.adapter.js.

pull/3/head
Simon Eisenmann 12 years ago
parent
commit
8e1377ffaf
  1. 2
      static/js/controllers/mediastreamcontroller.js
  2. 90
      static/js/libs/webrtc.adapter.js
  3. 27
      static/js/libs/webrtc.ice.js
  4. 1
      static/js/main.js

2
static/js/controllers/mediastreamcontroller.js

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
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) {

90
static/js/libs/webrtc.adapter.js

@ -36,7 +36,18 @@ var attachMediaStream = null; @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) {

27
static/js/libs/webrtc.ice.js

@ -1,27 +0,0 @@ @@ -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<urls.length; i++) {
var ic = createIceServer(urls[i], username, credential);
if (ic) {
iceServers.push(ic);
}
}
return iceServers;
};
}

1
static/js/main.js

@ -27,7 +27,6 @@ require.config({ @@ -27,7 +27,6 @@ require.config({
"underscore": 'libs/lodash.min', // alternative to underscore
"modernizr": 'libs/modernizr',
'webrtc.adapter': 'libs/webrtc.adapter',
'webrtc.ice': 'libs/webrtc.ice',
'angular': 'libs/angular/angular.min',
'ui-bootstrap': 'libs/angular/ui-bootstrap-tpls.min',
'ua-parser': 'libs/ua-parser',

Loading…
Cancel
Save