Browse Source

Updated to latest adapter.js - this drops support for Chrome < 34.

pull/176/head
Simon Eisenmann 11 years ago
parent
commit
3a50483040
  1. 165
      static/js/libs/webrtc.adapter.js

165
static/js/libs/webrtc.adapter.js

@ -37,117 +37,114 @@ var reattachMediaStream = null;
var webrtcDetectedBrowser = null; var webrtcDetectedBrowser = null;
var webrtcDetectedVersion = 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) { if (navigator.mozGetUserMedia) {
console.log("This appears to be Firefox"); console.log('This appears to be Firefox');
webrtcDetectedBrowser = "firefox"; webrtcDetectedBrowser = 'firefox';
webrtcDetectedVersion = webrtcDetectedVersion =
parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1], 10); parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1], 10);
// The RTCPeerConnection object. // The RTCPeerConnection object.
var RTCPeerConnection = function(pcConfig, pcConstraints) { window.RTCPeerConnection = function(pcConfig, pcConstraints) {
// .urls is not supported in FF yet. // .urls is not supported in FF yet.
maybeFixConfiguration(pcConfig); if (pcConfig && pcConfig.iceServers) {
return new mozRTCPeerConnection(pcConfig, pcConstraints); 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. // The RTCSessionDescription object.
RTCSessionDescription = mozRTCSessionDescription; window.RTCSessionDescription = mozRTCSessionDescription;
// The RTCIceCandidate object. // 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. // Code from Adam Barth.
getUserMedia = navigator.mozGetUserMedia.bind(navigator); getUserMedia = navigator.mozGetUserMedia.bind(navigator);
navigator.getUserMedia = getUserMedia; navigator.getUserMedia = getUserMedia;
// Creates iceServer from the url for FF. // Shim for MediaStreamTrack.getSources.
createIceServer = function(url, username, password) { 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 iceServer = null;
var url_parts = url.split(':'); var urlParts = url.split(':');
if (url_parts[0].indexOf('stun') === 0) { if (urlParts[0].indexOf('stun') === 0) {
// Create iceServer with stun url. // Create ICE server with STUN URL.
iceServer = { 'url': url }; iceServer = {
} else if (url_parts[0].indexOf('turn') === 0) { 'url': url
};
} else if (urlParts[0].indexOf('turn') === 0) {
if (webrtcDetectedVersion < 27) { if (webrtcDetectedVersion < 27) {
// Create iceServer with turn url. // Create iceServer with turn url.
// Ignore the transport parameter from TURN url for FF version <=27. // 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. // Return null for createIceServer if transport=tcp.
if (turn_url_parts.length === 1 || if (turnUrlParts.length === 1 ||
turn_url_parts[1].indexOf('transport=udp') === 0) { turnUrlParts[1].indexOf('transport=udp') === 0) {
iceServer = {'url': turn_url_parts[0], iceServer = {
'url': turnUrlParts[0],
'credential': password, 'credential': password,
'username': username}; 'username': username
};
} }
} else { } else {
// FF 27 and above supports transport parameters in TURN url, // FF 27 and above supports transport parameters in TURN url,
// So passing in the full url to create iceServer. // So passing in the full url to create iceServer.
iceServer = {'url': url, iceServer = {
'url': url,
'credential': password, 'credential': password,
'username': username}; 'username': username
};
} }
} }
return iceServer; return iceServer;
}; };
createIceServers = function(urls, username, password) { window.createIceServers = function(urls, username, password) {
var iceServers = []; var iceServers = [];
// Use .url for FireFox. // Use .url for FireFox.
for (i = 0; i < urls.length; i++) { for (var i = 0; i < urls.length; i++) {
var iceServer = createIceServer(urls[i], var iceServer =
username, window.createIceServer(urls[i], username, password);
password);
if (iceServer !== null) { if (iceServer !== null) {
iceServers.push(iceServer); iceServers.push(iceServer);
} }
} }
return iceServers; return iceServers;
} };
// Attach a media stream to an element. // Attach a media stream to an element.
attachMediaStream = function(element, stream) { attachMediaStream = function(element, stream) {
console.log("Attaching media stream"); console.log('Attaching media stream');
element.mozSrcObject = stream; element.mozSrcObject = stream;
element.play();
}; };
reattachMediaStream = function(to, from) { reattachMediaStream = function(to, from) {
console.log("Reattaching media stream"); console.log('Reattaching media stream');
to.mozSrcObject = from.mozSrcObject; 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) { } 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. // Temporary fix until crbug/374263 is fixed.
// Setting Chrome version to 999, if version is unavailable. // Setting Chrome version to 999, if version is unavailable.
var result = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); 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. // 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 iceServer = null;
var url_parts = url.split(':'); var urlParts = url.split(':');
if (url_parts[0].indexOf('stun') === 0) { if (urlParts[0].indexOf('stun') === 0) {
// Create iceServer with stun url. // Create iceServer with stun url.
iceServer = { 'url': url }; iceServer = {
} else if (url_parts[0].indexOf('turn') === 0) { 'url': url
};
} else if (urlParts[0].indexOf('turn') === 0) {
// Chrome M28 & above uses below TURN format. // Chrome M28 & above uses below TURN format.
iceServer = {'url': url, iceServer = {
'url': url,
'credential': password, 'credential': password,
'username': username}; 'username': username
};
} }
return iceServer; return iceServer;
}; };
// Creates iceServers from the urls for Chrome M34 and above. // Creates an ICEServer object from multiple URLs.
createIceServers = function(urls, username, password) { window.createIceServers = function(urls, username, password) {
var iceServers = []; return {
if (webrtcDetectedVersion >= 34) { 'urls': urls,
// .urls is supported since Chrome M34.
iceServers = [{'urls': urls,
'credential': password, 'credential': password,
'username': username }]; '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;
}; };
// The RTCPeerConnection object. // The RTCPeerConnection object.
var RTCPeerConnection = function(pcConfig, pcConstraints) { RTCPeerConnection = function(pcConfig, pcConstraints) {
// .urls is supported since Chrome M34.
if (webrtcDetectedVersion < 34) {
maybeFixConfiguration(pcConfig);
}
return new webkitRTCPeerConnection(pcConfig, pcConstraints); return new webkitRTCPeerConnection(pcConfig, pcConstraints);
} };
// Get UserMedia (only difference is the prefix). // Get UserMedia (only difference is the prefix).
// Code from Adam Barth. // Code from Adam Barth.
@ -225,5 +210,5 @@ if (navigator.mozGetUserMedia) {
to.src = from.src; to.src = from.src;
}; };
} else { } else {
console.log("Browser does not appear to be WebRTC-capable"); console.log('Browser does not appear to be WebRTC-capable');
} }

Loading…
Cancel
Save