traceablepeerconnection
Advanced tools
Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "traceablepeerconnection", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Lowlevel RTCPeerConnection wrapper which allows tracing the API calls", | ||
@@ -16,3 +16,3 @@ "main": "index.js", | ||
"wildemitter": "1.x", | ||
"webrtc-adapter-test": "^0.1.6" | ||
"webrtc-adapter-test": "^0.2.1" | ||
}, | ||
@@ -19,0 +19,0 @@ "devDependencies": { |
@@ -1002,2 +1002,12 @@ !function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.PeerConnection=e():"undefined"!=typeof global?global.PeerConnection=e():"undefined"!=typeof self&&(self.PeerConnection=e())}(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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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){ | ||
var webrtcMinimumVersion = null; | ||
var webrtcUtils = { | ||
log: function() { | ||
// suppress console.log output when being included as a module. | ||
if (typeof module !== 'undefined' || | ||
typeof require === 'function' && typeof define === 'function') { | ||
return; | ||
} | ||
console.log.apply(console, arguments); | ||
} | ||
}; | ||
@@ -1011,5 +1021,5 @@ function trace(text) { | ||
var now = (window.performance.now() / 1000).toFixed(3); | ||
console.log(now + ': ' + text); | ||
webrtcUtils.log(now + ': ' + text); | ||
} else { | ||
console.log(text); | ||
webrtcUtils.log(text); | ||
} | ||
@@ -1019,6 +1029,6 @@ } | ||
if (typeof window === 'undefined' || !window.navigator) { | ||
console.log('This does not appear to be a browser'); | ||
webrtcUtils.log('This does not appear to be a browser'); | ||
webrtcDetectedBrowser = 'not a browser'; | ||
} else if (navigator.mozGetUserMedia) { | ||
console.log('This appears to be Firefox'); | ||
} else if (navigator.mozGetUserMedia && window.mozRTCPeerConnection) { | ||
webrtcUtils.log('This appears to be Firefox'); | ||
@@ -1061,3 +1071,3 @@ webrtcDetectedBrowser = 'firefox'; | ||
} | ||
return new mozRTCPeerConnection(pcConfig, pcConstraints); | ||
return new mozRTCPeerConnection(pcConfig, pcConstraints); // jscs:ignore requireCapitalizedConstructors | ||
}; | ||
@@ -1072,4 +1082,3 @@ | ||
// getUserMedia constraints shim. | ||
getUserMedia = (webrtcDetectedVersion < 38) ? | ||
function(c, onSuccess, onError) { | ||
getUserMedia = function(constraints, onSuccess, onError) { | ||
var constraintsToFF37 = function(c) { | ||
@@ -1081,15 +1090,27 @@ if (typeof c !== 'object' || c.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) { | ||
r.min = r.max = r.exact; | ||
if (typeof r.exact === 'number') { | ||
r.min = r.max = r.exact; | ||
} else { | ||
c[key] = r.exact; | ||
} | ||
delete r.exact; | ||
} | ||
if (r.min !== undefined || r.max !== undefined) { | ||
require.push(key); | ||
} | ||
if (r.ideal !== undefined) { | ||
c.advanced = c.advanced || []; | ||
var oc = {}; | ||
oc[key] = {min: r.ideal, max: r.ideal}; | ||
if (typeof r.ideal === 'number') { | ||
oc[key] = {min: r.ideal, max: r.ideal}; | ||
} else { | ||
oc[key] = r.ideal; | ||
} | ||
c.advanced.push(oc); | ||
@@ -1107,8 +1128,14 @@ delete r.ideal; | ||
}; | ||
console.log('spec: ' + JSON.stringify(c)); | ||
c.audio = constraintsToFF37(c.audio); | ||
c.video = constraintsToFF37(c.video); | ||
console.log('ff37: ' + JSON.stringify(c)); | ||
return navigator.mozGetUserMedia(c, onSuccess, onError); | ||
} : navigator.mozGetUserMedia.bind(navigator); | ||
if (webrtcDetectedVersion < 38) { | ||
webrtcUtils.log('spec: ' + JSON.stringify(constraints)); | ||
if (constraints.audio) { | ||
constraints.audio = constraintsToFF37(constraints.audio); | ||
} | ||
if (constraints.video) { | ||
constraints.video = constraintsToFF37(constraints.video); | ||
} | ||
webrtcUtils.log('ff37: ' + JSON.stringify(constraints)); | ||
} | ||
return navigator.mozGetUserMedia(constraints, onSuccess, onError); | ||
}; | ||
@@ -1128,4 +1155,4 @@ navigator.getUserMedia = getUserMedia; | ||
var infos = [ | ||
{kind: 'audioinput', deviceId: 'default', label:'', groupId:''}, | ||
{kind: 'videoinput', deviceId: 'default', label:'', groupId:''} | ||
{kind: 'audioinput', deviceId: 'default', label: '', groupId: ''}, | ||
{kind: 'videoinput', deviceId: 'default', label: '', groupId: ''} | ||
]; | ||
@@ -1149,15 +1176,22 @@ resolve(infos); | ||
} | ||
Object.defineProperty(HTMLVideoElement.prototype, 'srcObject', { | ||
get: function() { | ||
return this.mozSrcObject; | ||
}, | ||
set: function(stream) { | ||
this.mozSrcObject = stream; | ||
} | ||
}); | ||
// Attach a media stream to an element. | ||
attachMediaStream = function(element, stream) { | ||
console.log('Attaching media stream'); | ||
element.mozSrcObject = stream; | ||
element.srcObject = stream; | ||
}; | ||
reattachMediaStream = function(to, from) { | ||
console.log('Reattaching media stream'); | ||
to.mozSrcObject = from.mozSrcObject; | ||
to.srcObject = from.srcObject; | ||
}; | ||
} else if (navigator.webkitGetUserMedia) { | ||
console.log('This appears to be Chrome'); | ||
webrtcUtils.log('This appears to be Chrome'); | ||
@@ -1175,8 +1209,17 @@ webrtcDetectedBrowser = 'chrome'; | ||
window.RTCPeerConnection = function(pcConfig, pcConstraints) { | ||
var pc = new webkitRTCPeerConnection(pcConfig, pcConstraints); | ||
// Translate iceTransportPolicy to iceTransports, | ||
// see https://code.google.com/p/webrtc/issues/detail?id=4869 | ||
if (pcConfig && pcConfig.iceTransportPolicy) { | ||
pcConfig.iceTransports = pcConfig.iceTransportPolicy; | ||
} | ||
var pc = new webkitRTCPeerConnection(pcConfig, pcConstraints); // jscs:ignore requireCapitalizedConstructors | ||
var origGetStats = pc.getStats.bind(pc); | ||
pc.getStats = function(selector, successCallback, errorCallback) { // jshint ignore: line | ||
var self = this; | ||
var args = arguments; | ||
// If selector is a function then we are in the old style stats so just | ||
// pass back the original getStats format to avoid breaking old users. | ||
if (typeof selector === 'function') { | ||
if (arguments.length > 0 && typeof selector === 'function') { | ||
return origGetStats(selector, successCallback); | ||
@@ -1202,6 +1245,22 @@ } | ||
}; | ||
var successCallbackWrapper = function(response) { | ||
successCallback(fixChromeStats(response)); | ||
}; | ||
return origGetStats(successCallbackWrapper, selector); | ||
if (arguments.length >= 2) { | ||
var successCallbackWrapper = function(response) { | ||
args[1](fixChromeStats(response)); | ||
}; | ||
return origGetStats.apply(this, [successCallbackWrapper, arguments[0]]); | ||
} | ||
// promise-support | ||
return new Promise(function(resolve, reject) { | ||
if (args.length === 1 && selector === null) { | ||
origGetStats.apply(self, [ | ||
function(response) { | ||
resolve.apply(null, [fixChromeStats(response)]); | ||
}, reject]); | ||
} else { | ||
origGetStats.apply(self, [resolve, reject]); | ||
} | ||
}); | ||
}; | ||
@@ -1255,76 +1314,65 @@ | ||
// getUserMedia constraints shim. | ||
getUserMedia = function(c, onSuccess, onError) { | ||
var constraintsToChrome = function(c) { | ||
if (typeof c !== 'object' || c.mandatory || c.optional) { | ||
return c; | ||
var constraintsToChrome = function(c) { | ||
if (typeof c !== 'object' || c.mandatory || c.optional) { | ||
return c; | ||
} | ||
var cc = {}; | ||
Object.keys(c).forEach(function(key) { | ||
if (key === 'require' || key === 'advanced' || key === 'mediaSource') { | ||
return; | ||
} | ||
var cc = {}; | ||
Object.keys(c).forEach(function(key) { | ||
if (key === 'require' || key === 'advanced') { | ||
return; | ||
var r = (typeof c[key] === 'object') ? c[key] : {ideal: c[key]}; | ||
if (r.exact !== undefined && typeof r.exact === 'number') { | ||
r.min = r.max = r.exact; | ||
} | ||
var oldname = function(prefix, name) { | ||
if (prefix) { | ||
return prefix + name.charAt(0).toUpperCase() + name.slice(1); | ||
} | ||
var r = (typeof c[key] === 'object') ? c[key] : {ideal: c[key]}; | ||
if (r.exact !== undefined && typeof r.exact === 'number') { | ||
r.min = r.max = r.exact; | ||
} | ||
var oldname = function(prefix, name) { | ||
if (prefix) { | ||
return prefix + name.charAt(0).toUpperCase() + name.slice(1); | ||
} | ||
return (name === 'deviceId') ? 'sourceId' : name; | ||
}; | ||
if (r.ideal !== undefined) { | ||
cc.optional = cc.optional || []; | ||
var oc = {}; | ||
if (typeof r.ideal === 'number') { | ||
oc[oldname('min', key)] = r.ideal; | ||
cc.optional.push(oc); | ||
oc = {}; | ||
oc[oldname('max', key)] = r.ideal; | ||
cc.optional.push(oc); | ||
} else { | ||
oc[oldname('', key)] = r.ideal; | ||
cc.optional.push(oc); | ||
} | ||
} | ||
if (r.exact !== undefined && typeof r.exact !== 'number') { | ||
cc.mandatory = cc.mandatory || {}; | ||
cc.mandatory[oldname('', key)] = r.exact; | ||
return (name === 'deviceId') ? 'sourceId' : name; | ||
}; | ||
if (r.ideal !== undefined) { | ||
cc.optional = cc.optional || []; | ||
var oc = {}; | ||
if (typeof r.ideal === 'number') { | ||
oc[oldname('min', key)] = r.ideal; | ||
cc.optional.push(oc); | ||
oc = {}; | ||
oc[oldname('max', key)] = r.ideal; | ||
cc.optional.push(oc); | ||
} else { | ||
['min', 'max'].forEach(function(mix) { | ||
if (r[mix] !== undefined) { | ||
cc.mandatory = cc.mandatory || {}; | ||
cc.mandatory[oldname(mix, key)] = r[mix]; | ||
} | ||
}); | ||
oc[oldname('', key)] = r.ideal; | ||
cc.optional.push(oc); | ||
} | ||
}); | ||
if (c.advanced) { | ||
cc.optional = (cc.optional || []).concat(c.advanced); | ||
} | ||
return cc; | ||
}; | ||
console.log('spec: ' + JSON.stringify(c)); // whitespace for alignment | ||
c.audio = constraintsToChrome(c.audio); | ||
c.video = constraintsToChrome(c.video); | ||
console.log('chrome: ' + JSON.stringify(c)); | ||
return navigator.webkitGetUserMedia(c, onSuccess, onError); | ||
if (r.exact !== undefined && typeof r.exact !== 'number') { | ||
cc.mandatory = cc.mandatory || {}; | ||
cc.mandatory[oldname('', key)] = r.exact; | ||
} else { | ||
['min', 'max'].forEach(function(mix) { | ||
if (r[mix] !== undefined) { | ||
cc.mandatory = cc.mandatory || {}; | ||
cc.mandatory[oldname(mix, key)] = r[mix]; | ||
} | ||
}); | ||
} | ||
}); | ||
if (c.advanced) { | ||
cc.optional = (cc.optional || []).concat(c.advanced); | ||
} | ||
return cc; | ||
}; | ||
navigator.getUserMedia = getUserMedia; | ||
// Attach a media stream to an element. | ||
attachMediaStream = function(element, stream) { | ||
if (typeof element.srcObject !== 'undefined') { | ||
element.srcObject = stream; | ||
} else if (typeof element.src !== 'undefined') { | ||
element.src = URL.createObjectURL(stream); | ||
} else { | ||
console.log('Error attaching stream to element.'); | ||
getUserMedia = function(constraints, onSuccess, onError) { | ||
if (constraints.audio) { | ||
constraints.audio = constraintsToChrome(constraints.audio); | ||
} | ||
if (constraints.video) { | ||
constraints.video = constraintsToChrome(constraints.video); | ||
} | ||
webrtcUtils.log('chrome: ' + JSON.stringify(constraints)); | ||
return navigator.webkitGetUserMedia(constraints, onSuccess, onError); | ||
}; | ||
navigator.getUserMedia = getUserMedia; | ||
reattachMediaStream = function(to, from) { | ||
to.src = from.src; | ||
}; | ||
if (!navigator.mediaDevices) { | ||
@@ -1345,9 +1393,69 @@ navigator.mediaDevices = {getUserMedia: requestUserMedia, | ||
}}; | ||
// in case someone wants to listen for the devicechange event. | ||
navigator.mediaDevices.addEventListener = function() { }; | ||
navigator.mediaDevices.removeEventListener = function() { }; | ||
} | ||
// A shim for getUserMedia method on the mediaDevices object. | ||
// TODO(KaptenJansson) remove once implemented in Chrome stable. | ||
if (!navigator.mediaDevices.getUserMedia) { | ||
navigator.mediaDevices.getUserMedia = function(constraints) { | ||
return requestUserMedia(constraints); | ||
}; | ||
} else { | ||
// Even though Chrome 45 has navigator.mediaDevices and a getUserMedia | ||
// function which returns a Promise, it does not accept spec-style | ||
// constraints. | ||
var origGetUserMedia = navigator.mediaDevices.getUserMedia. | ||
bind(navigator.mediaDevices); | ||
navigator.mediaDevices.getUserMedia = function(c) { | ||
webrtcUtils.log('spec: ' + JSON.stringify(c)); // whitespace for alignment | ||
c.audio = constraintsToChrome(c.audio); | ||
c.video = constraintsToChrome(c.video); | ||
webrtcUtils.log('chrome: ' + JSON.stringify(c)); | ||
return origGetUserMedia(c); | ||
}; | ||
} | ||
// Dummy devicechange event methods. | ||
// TODO(KaptenJansson) remove once implemented in Chrome stable. | ||
if (typeof navigator.mediaDevices.addEventListener === 'undefined') { | ||
navigator.mediaDevices.addEventListener = function() { | ||
webrtcUtils.log('Dummy mediaDevices.addEventListener called.'); | ||
}; | ||
} | ||
if (typeof navigator.mediaDevices.removeEventListener === 'undefined') { | ||
navigator.mediaDevices.removeEventListener = function() { | ||
webrtcUtils.log('Dummy mediaDevices.removeEventListener called.'); | ||
}; | ||
} | ||
Object.defineProperty(HTMLVideoElement.prototype, 'srcObject', { | ||
get: function() { | ||
return this._srcObject; | ||
}, | ||
set: function(stream) { | ||
this._srcObject = stream; | ||
this.src = URL.createObjectURL(stream); | ||
} | ||
}); | ||
// Attach a media stream to an element. | ||
attachMediaStream = function(element, stream) { | ||
if (webrtcDetectedVersion >= 43) { | ||
element.srcObject = stream; | ||
} else if (typeof element.src !== 'undefined') { | ||
element.src = URL.createObjectURL(stream); | ||
} else { | ||
webrtcUtils.log('Error attaching stream to element.'); | ||
} | ||
}; | ||
reattachMediaStream = function(to, from) { | ||
if (webrtcDetectedVersion >= 43) { | ||
to.srcObject = from.srcObject; | ||
} else { | ||
to.src = from.src; | ||
} | ||
}; | ||
} else if (navigator.mediaDevices && navigator.userAgent.match( | ||
/Edge\/(\d+).(\d+)$/)) { | ||
console.log('This appears to be Edge'); | ||
webrtcUtils.log('This appears to be Edge'); | ||
webrtcDetectedBrowser = 'edge'; | ||
@@ -1361,2 +1469,4 @@ | ||
getUserMedia = navigator.getUserMedia; | ||
attachMediaStream = function(element, stream) { | ||
@@ -1369,3 +1479,3 @@ element.srcObject = stream; | ||
} else { | ||
console.log('Browser does not appear to be WebRTC-capable'); | ||
webrtcUtils.log('Browser does not appear to be WebRTC-capable'); | ||
} | ||
@@ -1380,4 +1490,11 @@ | ||
var webrtcTesting = {}; | ||
Object.defineProperty(webrtcTesting, 'version', { | ||
set: function(version) { | ||
webrtcDetectedVersion = version; | ||
} | ||
}); | ||
if (typeof module !== 'undefined') { | ||
var RTCPeerConnection = 'undefined'; | ||
var RTCPeerConnection; | ||
if (typeof window !== 'undefined') { | ||
@@ -1393,3 +1510,4 @@ RTCPeerConnection = window.RTCPeerConnection; | ||
webrtcDetectedVersion: webrtcDetectedVersion, | ||
webrtcMinimumVersion: webrtcMinimumVersion | ||
webrtcMinimumVersion: webrtcMinimumVersion, | ||
webrtcTesting: webrtcTesting | ||
//requestUserMedia: not exposed on purpose. | ||
@@ -1408,3 +1526,4 @@ //trace: not exposed on purpose. | ||
webrtcDetectedVersion: webrtcDetectedVersion, | ||
webrtcMinimumVersion: webrtcMinimumVersion | ||
webrtcMinimumVersion: webrtcMinimumVersion, | ||
webrtcTesting: webrtcTesting | ||
//requestUserMedia: not exposed on purpose. | ||
@@ -1411,0 +1530,0 @@ //trace: not exposed on purpose. |
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
58712
1666
+ Addedwebrtc-adapter-test@0.2.10(transitive)
- Removedwebrtc-adapter-test@0.1.9(transitive)
Updatedwebrtc-adapter-test@^0.2.1