webrtc-adapter
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -51,58 +51,2 @@ 'use strict'; | ||
} | ||
}, | ||
// The following entries duplicate the entries above but use babelify | ||
// to create versions safe for old browsers. | ||
adapterGlobalObjectES5: { | ||
src: ['./src/js/adapter_core.js'], | ||
dest: './out/adapter_es5.js', | ||
options: { | ||
browserifyOptions: { | ||
// Exposes shim methods in a global object to the browser. | ||
standalone: 'adapter', | ||
transform: [['babelify', {'presets': ['es2015']}]] | ||
} | ||
} | ||
}, | ||
// Use this if you do not want adapter to expose anything to the global | ||
// scope. | ||
adapterAndNoGlobalObjectES5: { | ||
src: ['./src/js/adapter_core.js'], | ||
dest: './out/adapter_no_global_es5.js', | ||
options: { | ||
browserifyOptions: { | ||
transform: [['babelify', {'presets': ['es2015']}]] | ||
} | ||
} | ||
}, | ||
// Use this if you do not want MS edge shim to be included. | ||
adapterNoEdgeES5: { | ||
src: ['./src/js/adapter_core.js'], | ||
dest: './out/adapter_no_edge_es5.js', | ||
options: { | ||
// These files will be skipped. | ||
ignore: [ | ||
'./src/js/edge/edge_shim.js', | ||
'./src/js/edge/edge_sdp.js' | ||
], | ||
browserifyOptions: { | ||
// Exposes the shim in a global object to the browser. | ||
standalone: 'adapter', | ||
transform: [['babelify', {'presets': ['es2015']}]] | ||
} | ||
} | ||
}, | ||
// Use this if you do not want MS edge shim to be included and do not | ||
// want adapter to expose anything to the global scope. | ||
adapterNoEdgeAndNoGlobalObjectES5: { | ||
src: ['./src/js/adapter_core.js'], | ||
dest: './out/adapter_no_edge_no_global_es5.js', | ||
options: { | ||
ignore: [ | ||
'./src/js/edge/edge_shim.js', | ||
'./src/js/edge/edge_sdp.js' | ||
], | ||
browserifyOptions: { | ||
transform: [['babelify', {'presets': ['es2015']}]] | ||
} | ||
} | ||
} | ||
@@ -109,0 +53,0 @@ }, |
@@ -287,19 +287,19 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
['createOffer', 'createAnswer'].forEach(function(method) { | ||
var nativeMethod = webkitRTCPeerConnection.prototype[method]; | ||
webkitRTCPeerConnection.prototype[method] = function() { | ||
var self = this; | ||
if (arguments.length < 1 || (arguments.length === 1 && | ||
typeof arguments[0] === 'object')) { | ||
var opts = arguments.length === 1 ? arguments[0] : undefined; | ||
return new Promise(function(resolve, reject) { | ||
nativeMethod.apply(self, [resolve, reject, opts]); | ||
}); | ||
} | ||
return nativeMethod.apply(this, arguments); | ||
}; | ||
}); | ||
// add promise support -- natively available in Chrome 51 | ||
if (browserDetails.version < 51) { | ||
['createOffer', 'createAnswer'].forEach(function(method) { | ||
var nativeMethod = webkitRTCPeerConnection.prototype[method]; | ||
webkitRTCPeerConnection.prototype[method] = function() { | ||
var self = this; | ||
if (arguments.length < 1 || (arguments.length === 1 && | ||
typeof arguments[0] === 'object')) { | ||
var opts = arguments.length === 1 ? arguments[0] : undefined; | ||
return new Promise(function(resolve, reject) { | ||
nativeMethod.apply(self, [resolve, reject, opts]); | ||
}); | ||
} | ||
return nativeMethod.apply(this, arguments); | ||
}; | ||
}); | ||
['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'] | ||
@@ -723,105 +723,2 @@ .forEach(function(method) { | ||
shimGetUserMedia: function() { | ||
// getUserMedia constraints shim. | ||
var getUserMedia_ = function(constraints, onSuccess, onError) { | ||
var constraintsToFF37_ = function(c) { | ||
if (typeof c !== 'object' || c.require) { | ||
return c; | ||
} | ||
var require = []; | ||
Object.keys(c).forEach(function(key) { | ||
if (key === 'require' || key === 'advanced' || | ||
key === 'mediaSource') { | ||
return; | ||
} | ||
var r = c[key] = (typeof c[key] === 'object') ? | ||
c[key] : {ideal: c[key]}; | ||
if (r.min !== undefined || | ||
r.max !== undefined || r.exact !== undefined) { | ||
require.push(key); | ||
} | ||
if (r.exact !== undefined) { | ||
if (typeof r.exact === 'number') { | ||
r. min = r.max = r.exact; | ||
} else { | ||
c[key] = r.exact; | ||
} | ||
delete r.exact; | ||
} | ||
if (r.ideal !== undefined) { | ||
c.advanced = c.advanced || []; | ||
var oc = {}; | ||
if (typeof r.ideal === 'number') { | ||
oc[key] = {min: r.ideal, max: r.ideal}; | ||
} else { | ||
oc[key] = r.ideal; | ||
} | ||
c.advanced.push(oc); | ||
delete r.ideal; | ||
if (!Object.keys(r).length) { | ||
delete c[key]; | ||
} | ||
} | ||
}); | ||
if (require.length) { | ||
c.require = require; | ||
} | ||
return c; | ||
}; | ||
constraints = JSON.parse(JSON.stringify(constraints)); | ||
if (browserDetails.version < 38) { | ||
logging('spec: ' + JSON.stringify(constraints)); | ||
if (constraints.audio) { | ||
constraints.audio = constraintsToFF37_(constraints.audio); | ||
} | ||
if (constraints.video) { | ||
constraints.video = constraintsToFF37_(constraints.video); | ||
} | ||
logging('ff37: ' + JSON.stringify(constraints)); | ||
} | ||
return navigator.mozGetUserMedia(constraints, onSuccess, onError); | ||
}; | ||
navigator.getUserMedia = getUserMedia_; | ||
// Returns the result of getUserMedia as a Promise. | ||
var getUserMediaPromise_ = function(constraints) { | ||
return new Promise(function(resolve, reject) { | ||
navigator.getUserMedia(constraints, resolve, reject); | ||
}); | ||
}; | ||
// Shim for mediaDevices on older versions. | ||
if (!navigator.mediaDevices) { | ||
navigator.mediaDevices = {getUserMedia: getUserMediaPromise_, | ||
addEventListener: function() { }, | ||
removeEventListener: function() { } | ||
}; | ||
} | ||
navigator.mediaDevices.enumerateDevices = | ||
navigator.mediaDevices.enumerateDevices || function() { | ||
return new Promise(function(resolve) { | ||
var infos = [ | ||
{kind: 'audioinput', deviceId: 'default', label: '', groupId: ''}, | ||
{kind: 'videoinput', deviceId: 'default', label: '', groupId: ''} | ||
]; | ||
resolve(infos); | ||
}); | ||
}; | ||
if (browserDetails.version < 41) { | ||
// Work around http://bugzil.la/1169665 | ||
var orgEnumerateDevices = | ||
navigator.mediaDevices.enumerateDevices.bind(navigator.mediaDevices); | ||
navigator.mediaDevices.enumerateDevices = function() { | ||
return orgEnumerateDevices().then(undefined, function(e) { | ||
if (e.name === 'NotFoundError') { | ||
return []; | ||
} | ||
throw e; | ||
}); | ||
}; | ||
} | ||
}, | ||
// Attach a media stream to an element. | ||
@@ -943,8 +840,6 @@ attachMediaStream: function(element, stream) { | ||
navigator.getUserMedia = getUserMedia_; | ||
// Returns the result of getUserMedia as a Promise. | ||
var getUserMediaPromise_ = function(constraints) { | ||
return new Promise(function(resolve, reject) { | ||
navigator.getUserMedia(constraints, resolve, reject); | ||
getUserMedia_(constraints, resolve, reject); | ||
}); | ||
@@ -993,2 +888,11 @@ }; | ||
} | ||
navigator.getUserMedia = function(constraints, onSuccess, onError) { | ||
if (browserDetails.version < 44) { | ||
return getUserMedia_(constraints, onSuccess, onError); | ||
} | ||
// Replace Firefox 44+'s deprecation warning with unprefixed version. | ||
console.warn('navigator.getUserMedia has been replaced by ' + | ||
'navigator.mediaDevices.getUserMedia'); | ||
navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError); | ||
}; | ||
}; | ||
@@ -995,0 +899,0 @@ |
@@ -287,19 +287,19 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.adapter = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
['createOffer', 'createAnswer'].forEach(function(method) { | ||
var nativeMethod = webkitRTCPeerConnection.prototype[method]; | ||
webkitRTCPeerConnection.prototype[method] = function() { | ||
var self = this; | ||
if (arguments.length < 1 || (arguments.length === 1 && | ||
typeof arguments[0] === 'object')) { | ||
var opts = arguments.length === 1 ? arguments[0] : undefined; | ||
return new Promise(function(resolve, reject) { | ||
nativeMethod.apply(self, [resolve, reject, opts]); | ||
}); | ||
} | ||
return nativeMethod.apply(this, arguments); | ||
}; | ||
}); | ||
// add promise support -- natively available in Chrome 51 | ||
if (browserDetails.version < 51) { | ||
['createOffer', 'createAnswer'].forEach(function(method) { | ||
var nativeMethod = webkitRTCPeerConnection.prototype[method]; | ||
webkitRTCPeerConnection.prototype[method] = function() { | ||
var self = this; | ||
if (arguments.length < 1 || (arguments.length === 1 && | ||
typeof arguments[0] === 'object')) { | ||
var opts = arguments.length === 1 ? arguments[0] : undefined; | ||
return new Promise(function(resolve, reject) { | ||
nativeMethod.apply(self, [resolve, reject, opts]); | ||
}); | ||
} | ||
return nativeMethod.apply(this, arguments); | ||
}; | ||
}); | ||
['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'] | ||
@@ -723,105 +723,2 @@ .forEach(function(method) { | ||
shimGetUserMedia: function() { | ||
// getUserMedia constraints shim. | ||
var getUserMedia_ = function(constraints, onSuccess, onError) { | ||
var constraintsToFF37_ = function(c) { | ||
if (typeof c !== 'object' || c.require) { | ||
return c; | ||
} | ||
var require = []; | ||
Object.keys(c).forEach(function(key) { | ||
if (key === 'require' || key === 'advanced' || | ||
key === 'mediaSource') { | ||
return; | ||
} | ||
var r = c[key] = (typeof c[key] === 'object') ? | ||
c[key] : {ideal: c[key]}; | ||
if (r.min !== undefined || | ||
r.max !== undefined || r.exact !== undefined) { | ||
require.push(key); | ||
} | ||
if (r.exact !== undefined) { | ||
if (typeof r.exact === 'number') { | ||
r. min = r.max = r.exact; | ||
} else { | ||
c[key] = r.exact; | ||
} | ||
delete r.exact; | ||
} | ||
if (r.ideal !== undefined) { | ||
c.advanced = c.advanced || []; | ||
var oc = {}; | ||
if (typeof r.ideal === 'number') { | ||
oc[key] = {min: r.ideal, max: r.ideal}; | ||
} else { | ||
oc[key] = r.ideal; | ||
} | ||
c.advanced.push(oc); | ||
delete r.ideal; | ||
if (!Object.keys(r).length) { | ||
delete c[key]; | ||
} | ||
} | ||
}); | ||
if (require.length) { | ||
c.require = require; | ||
} | ||
return c; | ||
}; | ||
constraints = JSON.parse(JSON.stringify(constraints)); | ||
if (browserDetails.version < 38) { | ||
logging('spec: ' + JSON.stringify(constraints)); | ||
if (constraints.audio) { | ||
constraints.audio = constraintsToFF37_(constraints.audio); | ||
} | ||
if (constraints.video) { | ||
constraints.video = constraintsToFF37_(constraints.video); | ||
} | ||
logging('ff37: ' + JSON.stringify(constraints)); | ||
} | ||
return navigator.mozGetUserMedia(constraints, onSuccess, onError); | ||
}; | ||
navigator.getUserMedia = getUserMedia_; | ||
// Returns the result of getUserMedia as a Promise. | ||
var getUserMediaPromise_ = function(constraints) { | ||
return new Promise(function(resolve, reject) { | ||
navigator.getUserMedia(constraints, resolve, reject); | ||
}); | ||
}; | ||
// Shim for mediaDevices on older versions. | ||
if (!navigator.mediaDevices) { | ||
navigator.mediaDevices = {getUserMedia: getUserMediaPromise_, | ||
addEventListener: function() { }, | ||
removeEventListener: function() { } | ||
}; | ||
} | ||
navigator.mediaDevices.enumerateDevices = | ||
navigator.mediaDevices.enumerateDevices || function() { | ||
return new Promise(function(resolve) { | ||
var infos = [ | ||
{kind: 'audioinput', deviceId: 'default', label: '', groupId: ''}, | ||
{kind: 'videoinput', deviceId: 'default', label: '', groupId: ''} | ||
]; | ||
resolve(infos); | ||
}); | ||
}; | ||
if (browserDetails.version < 41) { | ||
// Work around http://bugzil.la/1169665 | ||
var orgEnumerateDevices = | ||
navigator.mediaDevices.enumerateDevices.bind(navigator.mediaDevices); | ||
navigator.mediaDevices.enumerateDevices = function() { | ||
return orgEnumerateDevices().then(undefined, function(e) { | ||
if (e.name === 'NotFoundError') { | ||
return []; | ||
} | ||
throw e; | ||
}); | ||
}; | ||
} | ||
}, | ||
// Attach a media stream to an element. | ||
@@ -943,8 +840,6 @@ attachMediaStream: function(element, stream) { | ||
navigator.getUserMedia = getUserMedia_; | ||
// Returns the result of getUserMedia as a Promise. | ||
var getUserMediaPromise_ = function(constraints) { | ||
return new Promise(function(resolve, reject) { | ||
navigator.getUserMedia(constraints, resolve, reject); | ||
getUserMedia_(constraints, resolve, reject); | ||
}); | ||
@@ -993,2 +888,11 @@ }; | ||
} | ||
navigator.getUserMedia = function(constraints, onSuccess, onError) { | ||
if (browserDetails.version < 44) { | ||
return getUserMedia_(constraints, onSuccess, onError); | ||
} | ||
// Replace Firefox 44+'s deprecation warning with unprefixed version. | ||
console.warn('navigator.getUserMedia has been replaced by ' + | ||
'navigator.mediaDevices.getUserMedia'); | ||
navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError); | ||
}; | ||
}; | ||
@@ -995,0 +899,0 @@ |
{ | ||
"name": "webrtc-adapter", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "A shim to insulate apps from WebRTC spec changes and browser prefix differences", | ||
@@ -21,7 +21,2 @@ "license": "BSD-3-Clause", | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"es2015" | ||
] | ||
}, | ||
"dependencies": { | ||
@@ -34,4 +29,2 @@ "sdp": "^1.0.0" | ||
"devDependencies": { | ||
"babel-preset-es2015": "^6.6.0", | ||
"babelify": "^7.3.0", | ||
"chromedriver": "^2.16.0", | ||
@@ -38,0 +31,0 @@ "eslint-config-webrtc": "^1.0.0", |
@@ -190,19 +190,19 @@ | ||
['createOffer', 'createAnswer'].forEach(function(method) { | ||
var nativeMethod = webkitRTCPeerConnection.prototype[method]; | ||
webkitRTCPeerConnection.prototype[method] = function() { | ||
var self = this; | ||
if (arguments.length < 1 || (arguments.length === 1 && | ||
typeof arguments[0] === 'object')) { | ||
var opts = arguments.length === 1 ? arguments[0] : undefined; | ||
return new Promise(function(resolve, reject) { | ||
nativeMethod.apply(self, [resolve, reject, opts]); | ||
}); | ||
} | ||
return nativeMethod.apply(this, arguments); | ||
}; | ||
}); | ||
// add promise support -- natively available in Chrome 51 | ||
if (browserDetails.version < 51) { | ||
['createOffer', 'createAnswer'].forEach(function(method) { | ||
var nativeMethod = webkitRTCPeerConnection.prototype[method]; | ||
webkitRTCPeerConnection.prototype[method] = function() { | ||
var self = this; | ||
if (arguments.length < 1 || (arguments.length === 1 && | ||
typeof arguments[0] === 'object')) { | ||
var opts = arguments.length === 1 ? arguments[0] : undefined; | ||
return new Promise(function(resolve, reject) { | ||
nativeMethod.apply(self, [resolve, reject, opts]); | ||
}); | ||
} | ||
return nativeMethod.apply(this, arguments); | ||
}; | ||
}); | ||
['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'] | ||
@@ -209,0 +209,0 @@ .forEach(function(method) { |
@@ -91,2 +91,4 @@ /* | ||
} | ||
this.usingBundle = config && config.bundlePolicy === 'max-bundle'; | ||
if (config && config.iceServers) { | ||
@@ -96,9 +98,14 @@ // Edge does not like | ||
// 2) turn: that does not have all of turn:host:port?transport=udp | ||
this.iceOptions.iceServers = config.iceServers.filter(function(server) { | ||
var iceServers = JSON.parse(JSON.stringify(config.iceServers)); | ||
this.iceOptions.iceServers = iceServers.filter(function(server) { | ||
if (server && server.urls) { | ||
server.urls = server.urls.filter(function(url) { | ||
var urls = server.urls; | ||
if (typeof urls === 'string') { | ||
urls = [urls]; | ||
} | ||
urls = urls.filter(function(url) { | ||
return url.indexOf('turn:') === 0 && | ||
url.indexOf('transport=udp') !== -1; | ||
})[0]; | ||
return !!server.urls; | ||
return !!urls; | ||
} | ||
@@ -261,2 +268,14 @@ return false; | ||
// update local description. | ||
var sections = SDPUtils.splitSections(self.localDescription.sdp); | ||
if (event.candidate.candidate.indexOf('typ endOfCandidates') | ||
=== -1) { | ||
sections[event.candidate.sdpMLineIndex + 1] += | ||
'a=' + event.candidate.candidate + '\r\n'; | ||
} else { | ||
sections[event.candidate.sdpMLineIndex + 1] += | ||
'a=end-of-candidates\r\n'; | ||
} | ||
self.localDescription.sdp = sections.join(''); | ||
var complete = self.transceivers.every(function(transceiver) { | ||
@@ -396,7 +415,6 @@ return transceiver.iceGatherer && | ||
// RTCIceCandidateComplete) | ||
iceTransport.setRemoteCandidates(cands); | ||
if (cands.length) { | ||
iceTransport.setRemoteCandidates(cands); | ||
} | ||
} | ||
iceTransport.start(iceGatherer, remoteIceParameters, | ||
isIceLite ? 'controlling' : 'controlled'); | ||
var remoteDtlsParameters = SDPUtils.getDtlsParameters( | ||
@@ -407,4 +425,9 @@ mediaSection, sessionpart); | ||
} | ||
dtlsTransport.start(remoteDtlsParameters); | ||
if (!self.usingBundle || sdpMLineIndex === 0) { | ||
iceTransport.start(iceGatherer, remoteIceParameters, | ||
isIceLite ? 'controlling' : 'controlled'); | ||
dtlsTransport.start(remoteDtlsParameters); | ||
} | ||
// Calculate intersection of capabilities. | ||
@@ -476,2 +499,4 @@ var params = self._getCommonCapabilities(localCapabilities, | ||
'a=ice-lite').length > 0; | ||
this.usingBundle = SDPUtils.matchPrefix(sessionpart, | ||
'a=group:BUNDLE ').length > 0; | ||
sections.forEach(function(mediaSection, sdpMLineIndex) { | ||
@@ -540,4 +565,8 @@ var lines = SDPUtils.splitLines(mediaSection); | ||
if (description.type === 'offer' && !rejected) { | ||
var transports = self._createIceAndDtlsTransports(mid, | ||
sdpMLineIndex); | ||
var transports = self.usingBundle && sdpMLineIndex > 0 ? { | ||
iceGatherer: self.transceivers[0].iceGatherer, | ||
iceTransport: self.transceivers[0].iceTransport, | ||
dtlsTransport: self.transceivers[0].dtlsTransport | ||
} : self._createIceAndDtlsTransports(mid, sdpMLineIndex); | ||
if (isComplete) { | ||
@@ -605,8 +634,10 @@ transports.iceTransport.setRemoteCandidates(cands); | ||
if (isIceLite || isComplete) { | ||
if ((isIceLite || isComplete) && cands.length) { | ||
iceTransport.setRemoteCandidates(cands); | ||
} | ||
iceTransport.start(iceGatherer, remoteIceParameters, | ||
'controlling'); | ||
dtlsTransport.start(remoteDtlsParameters); | ||
if (!self.usingBundle || sdpMLineIndex === 0) { | ||
iceTransport.start(iceGatherer, remoteIceParameters, | ||
'controlling'); | ||
dtlsTransport.start(remoteDtlsParameters); | ||
} | ||
@@ -844,3 +875,7 @@ self._transceive(transceiver, | ||
var transports = self._createIceAndDtlsTransports(mid, sdpMLineIndex); | ||
var transports = self.usingBundle && sdpMLineIndex > 0 ? { | ||
iceGatherer: transceivers[0].iceGatherer, | ||
iceTransport: transceivers[0].iceTransport, | ||
dtlsTransport: transceivers[0].dtlsTransport | ||
} : self._createIceAndDtlsTransports(mid, sdpMLineIndex); | ||
@@ -876,2 +911,9 @@ var localCapabilities = RTCRtpSender.getCapabilities(kind); | ||
}; | ||
}); | ||
if (this.usingBundle) { | ||
sdp += 'a=group:BUNDLE ' + transceivers.map(function(t) { | ||
return t.mid; | ||
}).join(' ') + '\r\n'; | ||
} | ||
tracks.forEach(function(mline, sdpMLineIndex) { | ||
var transceiver = transceivers[sdpMLineIndex]; | ||
@@ -897,2 +939,7 @@ sdp += SDPUtils.writeMediaSection(transceiver, | ||
var sdp = SDPUtils.writeSessionBoilerplate(); | ||
if (this.usingBundle) { | ||
sdp += 'a=group:BUNDLE ' + this.transceivers.map(function(t) { | ||
return t.mid; | ||
}).join(' ') + '\r\n'; | ||
} | ||
this.transceivers.forEach(function(transceiver) { | ||
@@ -921,3 +968,3 @@ // Calculate intersection of capabilities. | ||
this.transceivers.forEach(function(transceiver) { | ||
transceiver.iceTransport.addIceCandidate({}); | ||
transceiver.iceTransport.addRemoteCandidate({}); | ||
}); | ||
@@ -924,0 +971,0 @@ } else { |
@@ -149,105 +149,2 @@ /* | ||
shimGetUserMedia: function() { | ||
// getUserMedia constraints shim. | ||
var getUserMedia_ = function(constraints, onSuccess, onError) { | ||
var constraintsToFF37_ = function(c) { | ||
if (typeof c !== 'object' || c.require) { | ||
return c; | ||
} | ||
var require = []; | ||
Object.keys(c).forEach(function(key) { | ||
if (key === 'require' || key === 'advanced' || | ||
key === 'mediaSource') { | ||
return; | ||
} | ||
var r = c[key] = (typeof c[key] === 'object') ? | ||
c[key] : {ideal: c[key]}; | ||
if (r.min !== undefined || | ||
r.max !== undefined || r.exact !== undefined) { | ||
require.push(key); | ||
} | ||
if (r.exact !== undefined) { | ||
if (typeof r.exact === 'number') { | ||
r. min = r.max = r.exact; | ||
} else { | ||
c[key] = r.exact; | ||
} | ||
delete r.exact; | ||
} | ||
if (r.ideal !== undefined) { | ||
c.advanced = c.advanced || []; | ||
var oc = {}; | ||
if (typeof r.ideal === 'number') { | ||
oc[key] = {min: r.ideal, max: r.ideal}; | ||
} else { | ||
oc[key] = r.ideal; | ||
} | ||
c.advanced.push(oc); | ||
delete r.ideal; | ||
if (!Object.keys(r).length) { | ||
delete c[key]; | ||
} | ||
} | ||
}); | ||
if (require.length) { | ||
c.require = require; | ||
} | ||
return c; | ||
}; | ||
constraints = JSON.parse(JSON.stringify(constraints)); | ||
if (browserDetails.version < 38) { | ||
logging('spec: ' + JSON.stringify(constraints)); | ||
if (constraints.audio) { | ||
constraints.audio = constraintsToFF37_(constraints.audio); | ||
} | ||
if (constraints.video) { | ||
constraints.video = constraintsToFF37_(constraints.video); | ||
} | ||
logging('ff37: ' + JSON.stringify(constraints)); | ||
} | ||
return navigator.mozGetUserMedia(constraints, onSuccess, onError); | ||
}; | ||
navigator.getUserMedia = getUserMedia_; | ||
// Returns the result of getUserMedia as a Promise. | ||
var getUserMediaPromise_ = function(constraints) { | ||
return new Promise(function(resolve, reject) { | ||
navigator.getUserMedia(constraints, resolve, reject); | ||
}); | ||
}; | ||
// Shim for mediaDevices on older versions. | ||
if (!navigator.mediaDevices) { | ||
navigator.mediaDevices = {getUserMedia: getUserMediaPromise_, | ||
addEventListener: function() { }, | ||
removeEventListener: function() { } | ||
}; | ||
} | ||
navigator.mediaDevices.enumerateDevices = | ||
navigator.mediaDevices.enumerateDevices || function() { | ||
return new Promise(function(resolve) { | ||
var infos = [ | ||
{kind: 'audioinput', deviceId: 'default', label: '', groupId: ''}, | ||
{kind: 'videoinput', deviceId: 'default', label: '', groupId: ''} | ||
]; | ||
resolve(infos); | ||
}); | ||
}; | ||
if (browserDetails.version < 41) { | ||
// Work around http://bugzil.la/1169665 | ||
var orgEnumerateDevices = | ||
navigator.mediaDevices.enumerateDevices.bind(navigator.mediaDevices); | ||
navigator.mediaDevices.enumerateDevices = function() { | ||
return orgEnumerateDevices().then(undefined, function(e) { | ||
if (e.name === 'NotFoundError') { | ||
return []; | ||
} | ||
throw e; | ||
}); | ||
}; | ||
} | ||
}, | ||
// Attach a media stream to an element. | ||
@@ -254,0 +151,0 @@ attachMediaStream: function(element, stream) { |
@@ -94,8 +94,6 @@ /* | ||
navigator.getUserMedia = getUserMedia_; | ||
// Returns the result of getUserMedia as a Promise. | ||
var getUserMediaPromise_ = function(constraints) { | ||
return new Promise(function(resolve, reject) { | ||
navigator.getUserMedia(constraints, resolve, reject); | ||
getUserMedia_(constraints, resolve, reject); | ||
}); | ||
@@ -144,2 +142,11 @@ }; | ||
} | ||
navigator.getUserMedia = function(constraints, onSuccess, onError) { | ||
if (browserDetails.version < 44) { | ||
return getUserMedia_(constraints, onSuccess, onError); | ||
} | ||
// Replace Firefox 44+'s deprecation warning with unprefixed version. | ||
console.warn('navigator.getUserMedia has been replaced by ' + | ||
'navigator.mediaDevices.getUserMedia'); | ||
navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError); | ||
}; | ||
}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11
43
438843
32
11267