webrtc-browser-test
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -5,3 +5,5 @@ const gulp = require('gulp'); | ||
const rename = require('gulp-rename'); | ||
const uglify = require('gulp-uglify'); | ||
const terser = require('terser'); | ||
const composer = require('gulp-uglify/composer'); | ||
const uglify = composer(terser, console); | ||
@@ -12,5 +14,3 @@ gulp.task('transpile', () => { | ||
.pipe(eslint.format()) | ||
.pipe(babel({ | ||
presets: ['es2015'] | ||
})) | ||
.pipe(babel()) | ||
.pipe(gulp.dest('./lib')); | ||
@@ -17,0 +17,0 @@ }); |
@@ -1,5 +0,4 @@ | ||
'use strict'; | ||
"use strict"; | ||
(function () { | ||
var ParameterError = function ParameterError(message) { | ||
@@ -9,2 +8,3 @@ this.name = 'ParameterError'; | ||
}; | ||
ParameterError.prototype = Error.prototype; | ||
@@ -16,2 +16,3 @@ | ||
}; | ||
BrowserNotSupportedError.prototype = Error.prototype; | ||
@@ -23,2 +24,3 @@ | ||
}; | ||
VideoNotFoundError.prototype = Error.prototype; | ||
@@ -30,2 +32,3 @@ | ||
}; | ||
VideoDeniedError.prototype = Error.prototype; | ||
@@ -37,2 +40,3 @@ | ||
}; | ||
AudioNotFoundError.prototype = Error.prototype; | ||
@@ -44,9 +48,10 @@ | ||
}; | ||
AudioDeniedError.prototype = Error.prototype; | ||
var WebRtcBrowserTest = function WebRtcBrowserTest(opts) { | ||
if (typeof opts.mediaElementContainer === 'string') { | ||
opts.mediaElementContainer = document.querySelector(opts.mediaElementContainer); | ||
} | ||
if (!opts.mediaElementContainer || !(opts.mediaElementContainer instanceof Element)) { | ||
@@ -65,2 +70,3 @@ throw new ParameterError('Missing required element parameter. Tests can\'t continue.'); | ||
var videoElement = document.querySelector('#videoContainer > video'); | ||
if (!videoElement) { | ||
@@ -73,2 +79,3 @@ videoElement = document.createElement('video'); | ||
var audioElement = document.querySelector('#videoContainer > audio'); | ||
if (!audioElement) { | ||
@@ -103,5 +110,10 @@ audioElement = document.createElement('audio'); | ||
var cameraStream; | ||
var startVideo = function startVideo() { | ||
return checkBrowser().then(function () { | ||
return getUserMedia({ video: true }).then(function (stream) { | ||
return getUserMedia({ | ||
video: true | ||
}).then(function (stream) { | ||
cameraStream = stream; | ||
videoElement.srcObject = stream; | ||
@@ -125,4 +137,7 @@ return Promise.resolve(); | ||
return checkBrowser().then(function () { | ||
return getUserMedia({ audio: true }).then(function (stream) { | ||
return getUserMedia({ | ||
audio: true | ||
}).then(function (stream) { | ||
audioElement.srcObject = stream; | ||
audioElement.volume = 0; | ||
return startVolume(stream); | ||
@@ -147,2 +162,3 @@ }).catch(function (err) { | ||
var movingAvg = null; | ||
processor.onaudioprocess = function (event) { | ||
@@ -152,5 +168,7 @@ var data = event.inputBuffer.getChannelData(0); | ||
var total = 0; | ||
while (i < data.length) { | ||
total += Math.abs(data[i++]); | ||
} | ||
var rms = Math.sqrt(total / data.length); | ||
@@ -171,2 +189,3 @@ | ||
}; | ||
return processor; | ||
@@ -176,3 +195,4 @@ }; | ||
var startVolume = function startVolume(stream) { | ||
var audioContext = void 0; | ||
var audioContext; | ||
try { | ||
@@ -184,3 +204,5 @@ window.AudioContext = window.AudioContext || window.webkitAudioContext; | ||
} | ||
var listener = createVolumeListener(audioContext, opts.onVolumeChange); | ||
try { | ||
@@ -203,2 +225,37 @@ var mic = audioContext.createMediaStreamSource(stream); | ||
var toggleVolume = function toggleVolume() { | ||
audioElement.volume = audioElement.volume ? 0 : 1; | ||
}; | ||
var checkScreenSharing = function checkScreenSharing() { | ||
return !!(navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia); | ||
}; | ||
var screenStream; | ||
var startScreenSharing = function startScreenSharing() { | ||
if (!checkScreenSharing()) { | ||
return Promise.reject(new BrowserNotSupportedError('Your browser doesn\'t support screen sharing.')); | ||
} | ||
return navigator.mediaDevices.getDisplayMedia({ | ||
video: true | ||
}).then(function (stream) { | ||
screenStream = stream; | ||
videoElement.srcObject = screenStream; | ||
}).catch(console.log); | ||
}; | ||
var endScreenSharing = function endScreenSharing() { | ||
if (!screenStream) { | ||
throw new Error('Screen sharing hasn\'t been started yet.'); | ||
} | ||
videoElement.srcObject = cameraStream; | ||
screenStream.getTracks().forEach(function (track) { | ||
return track.stop(); | ||
}); | ||
screenStream = null; | ||
}; | ||
return { | ||
@@ -208,3 +265,7 @@ checkBrowser: checkBrowser, | ||
startAudio: startAudio, | ||
startAll: startAll | ||
startAll: startAll, | ||
toggleVolume: toggleVolume, | ||
checkScreenSharing: checkScreenSharing, | ||
startScreenSharing: startScreenSharing, | ||
endScreenSharing: endScreenSharing | ||
}; | ||
@@ -211,0 +272,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
"use strict";!function(){var e=function(e){this.name="ParameterError",this.message=e||""};e.prototype=Error.prototype;var t=function(e){this.name="BrowserNotSupportedError",this.message=e||""};t.prototype=Error.prototype;var r=function(e){this.name="VideoNotFoundError",this.message=e||"Unable to detect a video camera. Please ensure you've installed and tested your webcam."};r.prototype=Error.prototype;var o=function(e){this.name="VideoDeniedError",this.message=e||"Your browser is preventing access to your camera and microphone. Please check your browser settings (usually an icon in the address bar) to enable access."};o.prototype=Error.prototype;var n=function(e){this.name="AudioNotFoundError",this.message=e||"Unable to detect a microphone. Usually your video camera will have an integrated microphone, but if not please attach and enable one."};n.prototype=Error.prototype;var a=function(e){this.name="AudioDeniedError",this.message=e||"Your browser is preventing access to your microphone. Please check your browser settings (usually an icon in the address bar) to enable access."};a.prototype=Error.prototype;var i=function(i){if("string"==typeof i.mediaElementContainer&&(i.mediaElementContainer=document.querySelector(i.mediaElementContainer)),!(i.mediaElementContainer&&i.mediaElementContainer instanceof Element))throw new e("Missing required element parameter. Tests can't continue.");if(i.onVolumeChange&&"function"!=typeof i.onVolumeChange)throw new e("Volume callback parameter must be a function. Tests can't continue.");if(!window.Promise)throw new t("Your browser doesn't support Promises. Tests can't continue.");var s=document.querySelector("#videoContainer > video");s||(s=document.createElement("video"),s.setAttribute("autoplay",!0),i.mediaElementContainer.appendChild(s));var u=document.querySelector("#videoContainer > audio");u||(u=document.createElement("audio"),u.setAttribute("autoplay",!0),i.mediaElementContainer.appendChild(u));var c=function(e){return navigator.mediaDevices&&navigator.mediaDevices.getUserMedia?navigator.mediaDevices.getUserMedia(e):navigator.getUserMedia?new Promise(function(t,r){navigator.getUserMedia(e,t,r)}):navigator.mozGetUserMedia?new Promise(function(t,r){navigator.mozGetUserMedia(e,t,r)}):navigator.webkitGetUserMedia?new Promise(function(t,r){navigator.webkitGetUserMedia(e,t,r)}):void 0},d=function(){return navigator.mediaDevices&&navigator.mediaDevices.getUserMedia||navigator.getUserMedia||navigator.mozGetUserMedia||navigator.webkitGetUserMedia?Promise.resolve():Promise.reject(new t("Your browser doesn't support WebRTC."))},m=function(){return d().then(function(){return c({video:!0}).then(function(e){return s.srcObject=e,Promise.resolve()}).catch(function(e){throw"NotFoundError"===e.name?new r:"NotAllowedError"===e.name?new o:"PermissionDeniedError"===e.name?new o:e})})},l=function(){return d().then(function(){return c({audio:!0}).then(function(e){return u.srcObject=e,v(e)}).catch(function(e){throw"NotFoundError"===e.name?new n:"NotAllowedError"===e.name?new a:"PermissionDeniedError"===e.name?new a:e})})},p=function(e,t){var r=e.createScriptProcessor(2048,1,1);r.connect(e.destination);var o=null;return r.onaudioprocess=function(e){for(var r=e.inputBuffer.getChannelData(0),n=0,a=0;n<r.length;)a+=Math.abs(r[n++]);var i=Math.sqrt(a/r.length);o=null===o||o<i?i:.7*o+.3*i;var s=Math.log(o)/Math.LN10/1.5+1;s=Math.min(Math.max(s,0),1),t&&t(s)},r},v=function(e){var r=void 0;try{window.AudioContext=window.AudioContext||window.webkitAudioContext,r=new AudioContext}catch(e){return Promise.reject(new t("Your browser doesn't support web audio."))}var o=p(r,i.onVolumeChange);try{return r.createMediaStreamSource(e).connect(o),Promise.resolve()}catch(e){return Promise.reject(e)}};return{checkBrowser:d,startVideo:m,startAudio:l,startAll:function(){return d().then(function(){return m()}).then(function(){return l()})}}};"undefined"==typeof module||void 0===module.exports?window.WebRtcBrowserTest=i:module.exports=i}(); | ||
"use strict";!function(){var e=function(e){this.name="ParameterError",this.message=e||""};e.prototype=Error.prototype;var t=function(e){this.name="BrowserNotSupportedError",this.message=e||""};t.prototype=Error.prototype;var r=function(e){this.name="VideoNotFoundError",this.message=e||"Unable to detect a video camera. Please ensure you've installed and tested your webcam."};r.prototype=Error.prototype;var n=function(e){this.name="VideoDeniedError",this.message=e||"Your browser is preventing access to your camera and microphone. Please check your browser settings (usually an icon in the address bar) to enable access."};n.prototype=Error.prototype;var o=function(e){this.name="AudioNotFoundError",this.message=e||"Unable to detect a microphone. Usually your video camera will have an integrated microphone, but if not please attach and enable one."};o.prototype=Error.prototype;var i=function(e){this.name="AudioDeniedError",this.message=e||"Your browser is preventing access to your microphone. Please check your browser settings (usually an icon in the address bar) to enable access."};i.prototype=Error.prototype;var a=function(a){if("string"==typeof a.mediaElementContainer&&(a.mediaElementContainer=document.querySelector(a.mediaElementContainer)),!(a.mediaElementContainer&&a.mediaElementContainer instanceof Element))throw new e("Missing required element parameter. Tests can't continue.");if(a.onVolumeChange&&"function"!=typeof a.onVolumeChange)throw new e("Volume callback parameter must be a function. Tests can't continue.");if(!window.Promise)throw new t("Your browser doesn't support Promises. Tests can't continue.");var s=document.querySelector("#videoContainer > video");s||((s=document.createElement("video")).setAttribute("autoplay",!0),a.mediaElementContainer.appendChild(s));var c=document.querySelector("#videoContainer > audio");c||((c=document.createElement("audio")).setAttribute("autoplay",!0),a.mediaElementContainer.appendChild(c));var u,d,m=function(e){return navigator.mediaDevices&&navigator.mediaDevices.getUserMedia?navigator.mediaDevices.getUserMedia(e):navigator.getUserMedia?new Promise(function(t,r){navigator.getUserMedia(e,t,r)}):navigator.mozGetUserMedia?new Promise(function(t,r){navigator.mozGetUserMedia(e,t,r)}):navigator.webkitGetUserMedia?new Promise(function(t,r){navigator.webkitGetUserMedia(e,t,r)}):void 0},l=function(){return navigator.mediaDevices&&navigator.mediaDevices.getUserMedia||navigator.getUserMedia||navigator.mozGetUserMedia||navigator.webkitGetUserMedia?Promise.resolve():Promise.reject(new t("Your browser doesn't support WebRTC."))},h=function(){return l().then(function(){return m({video:!0}).then(function(e){return u=e,s.srcObject=e,Promise.resolve()}).catch(function(e){throw"NotFoundError"===e.name?new r:"NotAllowedError"===e.name?new n:"PermissionDeniedError"===e.name?new n:e})})},v=function(){return l().then(function(){return m({audio:!0}).then(function(e){return c.srcObject=e,c.volume=0,p(e)}).catch(function(e){throw"NotFoundError"===e.name?new o:"NotAllowedError"===e.name?new i:"PermissionDeniedError"===e.name?new i:e})})},p=function(e){var r;try{window.AudioContext=window.AudioContext||window.webkitAudioContext,r=new AudioContext}catch(e){return Promise.reject(new t("Your browser doesn't support web audio."))}var n=function(e,t){var r=e.createScriptProcessor(2048,1,1);r.connect(e.destination);var n=null;return r.onaudioprocess=function(e){for(var r=e.inputBuffer.getChannelData(0),o=0,i=0;o<r.length;)i+=Math.abs(r[o++]);var a=Math.sqrt(i/r.length);n=null===n||n<a?a:.7*n+.3*a;var s=Math.log(n)/Math.LN10/1.5+1;s=Math.min(Math.max(s,0),1),t&&t(s)},r}(r,a.onVolumeChange);try{return r.createMediaStreamSource(e).connect(n),Promise.resolve()}catch(e){return Promise.reject(e)}},g=function(){return!(!navigator.mediaDevices||!navigator.mediaDevices.getDisplayMedia)};return{checkBrowser:l,startVideo:h,startAudio:v,startAll:function(){return l().then(function(){return h()}).then(function(){return v()})},toggleVolume:function(){c.volume=c.volume?0:1},checkScreenSharing:g,startScreenSharing:function(){return g()?navigator.mediaDevices.getDisplayMedia({video:!0}).then(function(e){d=e,s.srcObject=d}).catch(console.log):Promise.reject(new t("Your browser doesn't support screen sharing."))},endScreenSharing:function(){if(!d)throw new Error("Screen sharing hasn't been started yet.");s.srcObject=u,d.getTracks().forEach(function(e){return e.stop()}),d=null}}};"undefined"==typeof module||void 0===module.exports?window.WebRtcBrowserTest=a:module.exports=a}(); |
{ | ||
"name": "webrtc-browser-test", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Test video and audio capabilities of the browser, verifying hardware works properly.", | ||
@@ -17,11 +17,13 @@ "main": "lib/webrtc-browser-test.js", | ||
"devDependencies": { | ||
"babel-eslint": "^7.2.1", | ||
"babel-preset-es2015": "^6.24.1", | ||
"eslint": "^3.19.0", | ||
"gulp": "github:gulpjs/gulp#4.0", | ||
"gulp-babel": "^6.1.2", | ||
"gulp-eslint": "^3.0.1", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-uglify": "^2.1.2", | ||
"http-server": "^0.9.0" | ||
"babel-eslint": "^10.0.1", | ||
"@babel/core": "^7.2.2", | ||
"@babel/preset-env": "^7.3.1", | ||
"eslint": "^5.12.1", | ||
"gulp": "^4.0.0", | ||
"gulp-babel": "^8.0.0", | ||
"gulp-eslint": "^5.0.0", | ||
"gulp-rename": "^1.4.0", | ||
"gulp-uglify": "^3.0.1", | ||
"http-server": "^0.11.1", | ||
"terser": "^3.16.1" | ||
}, | ||
@@ -28,0 +30,0 @@ "scripts": { |
@@ -41,2 +41,5 @@ webrtc-browser-test | ||
* `startAll()` - Run all the above tests. | ||
* `checkScreenSharing()` - Check whether the browser supports the `getDisplayMedia` method. | ||
* `startScreenSharing()` - Initiates screen sharing. | ||
* `endScreenSharing()` - Stops screen sharing and resumes using the camera. | ||
@@ -61,2 +64,4 @@ Example | ||
See `index.html` for full working example. | ||
Demo | ||
@@ -63,0 +68,0 @@ ---- |
@@ -98,5 +98,7 @@ (function() { | ||
let cameraStream; | ||
const startVideo = function() { | ||
return checkBrowser().then(() => { | ||
return getUserMedia({ video: true }).then((stream) => { | ||
cameraStream = stream; | ||
videoElement.srcObject = stream; | ||
@@ -122,2 +124,3 @@ return Promise.resolve(); | ||
audioElement.srcObject = stream; | ||
audioElement.volume = 0; | ||
return startVolume(stream); | ||
@@ -192,2 +195,30 @@ }).catch((err) => { | ||
const toggleVolume = function() { | ||
audioElement.volume = audioElement.volume ? 0 : 1; | ||
}; | ||
const checkScreenSharing = function() { | ||
return !!(navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia); | ||
}; | ||
let screenStream; | ||
const startScreenSharing = function() { | ||
if (!checkScreenSharing()) { | ||
return Promise.reject(new BrowserNotSupportedError('Your browser doesn\'t support screen sharing.')); | ||
} | ||
return navigator.mediaDevices.getDisplayMedia({ video: true }).then((stream) => { | ||
screenStream = stream; | ||
videoElement.srcObject = screenStream; | ||
}).catch(console.log); | ||
}; | ||
const endScreenSharing = function() { | ||
if (!screenStream) { | ||
throw new Error('Screen sharing hasn\'t been started yet.'); | ||
} | ||
videoElement.srcObject = cameraStream; | ||
screenStream.getTracks().forEach(track => track.stop()); | ||
screenStream = null; | ||
}; | ||
return { | ||
@@ -197,3 +228,7 @@ checkBrowser, | ||
startAudio, | ||
startAll | ||
startAll, | ||
toggleVolume, | ||
checkScreenSharing, | ||
startScreenSharing, | ||
endScreenSharing | ||
}; | ||
@@ -200,0 +235,0 @@ }; |
Sorry, the diff of this file is not supported yet
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
30082
9
455
74
11