Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-webcam

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-webcam - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

51

dist/react-webcam.js

@@ -80,8 +80,2 @@ (function webpackUniversalModuleDefinition(root, factory) {

Webcam.prototype.getDefaultProps = function getDefaultProps() {
return {
screenshotFormat: 'image/webp'
};
};
_createClass(Webcam, null, [{

@@ -92,3 +86,4 @@ key: 'defaultProps',

height: 480,
width: 640
width: 640,
screenshotFormat: 'image/webp'
},

@@ -167,17 +162,35 @@ enumerable: true

} else {
navigator.mediaDevices.enumerateDevices().then(function (devices) {
var audioSource = null;
var videoSource = null;
if ('mediaDevices' in navigator) {
navigator.mediaDevices.enumerateDevices().then(function (devices) {
var audioSource = null;
var videoSource = null;
devices.forEach(function (device) {
if (device.kind === 'audio') {
audioSource = device.id;
} else if (device.kind === 'video') {
videoSource = device.id;
}
devices.forEach(function (device) {
if (device.kind === 'audio') {
audioSource = device.id;
} else if (device.kind === 'video') {
videoSource = device.id;
}
});
sourceSelected(audioSource, videoSource);
})['catch'](function (error) {
return console.log(error.name + ": " + error.message);
});
} else {
MediaStreamTrack.getSources(function (sources) {
var audioSource = null;
var videoSource = null;
sourceSelected(audioSource, videoSource);
});
// .catch((error) => console.log(error.name + ": " + error.message));
sources.forEach(function (source) {
if (source.kind === 'audio') {
audioSource = source.id;
} else if (source.kind === 'video') {
videoSource = source.id;
}
});
sourceSelected(audioSource, videoSource);
});
}
}

@@ -184,0 +197,0 @@

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.Webcam=t(require("react")):e.Webcam=t(e.React)}(this,function(e){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(){return!!(navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia)}t.__esModule=!0;var s=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}(),u=r(1),p=o(u),c=function(e){function t(){n(this,t),e.call(this),this.state={hasUserMedia:!1}}return i(t,e),t.prototype.getDefaultProps=function(){return{screenshotFormat:"image/webp"}},s(t,null,[{key:"defaultProps",value:{audio:!0,height:480,width:640},enumerable:!0},{key:"propTypes",value:{audio:u.PropTypes.bool,onUserMedia:u.PropTypes.func,height:u.PropTypes.oneOfType([u.PropTypes.number,u.PropTypes.string]),width:u.PropTypes.oneOfType([u.PropTypes.number,u.PropTypes.string]),screenshotFormat:u.PropTypes.oneOf(["image/webp","image/png","image/jpeg"])},enumerable:!0},{key:"mountedInstances",value:[],enumerable:!0},{key:"userMediaRequested",value:!1,enumerable:!0}]),t.prototype.componentDidMount=function(){a()&&(t.mountedInstances.push(this),this.state.hasUserMedia||t.userMediaRequested||this.requestUserMedia())},t.prototype.requestUserMedia=function(){var e=this;navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;var r=function(r,o){var n={video:{optional:[{sourceId:o}]}};e.props.audio&&(n.audio={optional:[{sourceId:r}]}),navigator.getUserMedia(n,function(e){t.mountedInstances.forEach(function(t){return t.handleUserMedia(null,e)})},function(e){t.mountedInstances.forEach(function(t){return t.handleUserMedia(e)})})};this.props.audioSource&&this.props.videoSource?r(this.props.audioSource,this.props.videoSource):navigator.mediaDevices.enumerateDevices().then(function(e){var t=null,o=null;e.forEach(function(e){"audio"===e.kind?t=e.id:"video"===e.kind&&(o=e.id)}),r(t,o)}),t.userMediaRequested=!0},t.prototype.handleUserMedia=function(e,t){if(e)return void this.setState({hasUserMedia:!1});var r=window.URL.createObjectURL(t);this.stream=t,this.setState({hasUserMedia:!0,src:r}),this.props.onUserMedia&&this.props.onUserMedia()},t.prototype.componentWillUnmount=function(){var e=t.mountedInstances.indexOf(this);t.mountedInstances.splice(e,1),0===t.mountedInstances.length&&this.state.hasUserMedia&&(this.stream.stop(),t.userMediaRequested=!1,window.URL.revokeObjectURL(this.state.src))},t.prototype.getScreenshot=function(){if(!this.state.hasUserMedia)return null;var e=this.getCanvas();return e.toDataURL(this.props.screenshotFormat)},t.prototype.getCanvas=function(){if(!this.state.hasUserMedia)return null;var e=p.default.findDOMNode(this);if(!this.ctx){var t=document.createElement("canvas");t.height=e.clientHeight,t.width=e.clientWidth,this.canvas=t,this.ctx=t.getContext("2d")}var r=this.ctx,o=this.canvas;return r.drawImage(e,0,0,o.width,o.height),o},t.prototype.render=function(){return p.default.createElement("video",{autoPlay:!0,width:this.props.width,height:this.props.height,src:this.state.src})},t}(u.Component);t.default=c,e.exports=t.default},function(t,r){t.exports=e}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.Webcam=t(require("react")):e.Webcam=t(e.React)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(){return!!(navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia)}t.__esModule=!0;var s=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),u=r(1),c=n(u),d=function(e){function t(){o(this,t),e.call(this),this.state={hasUserMedia:!1}}return i(t,e),s(t,null,[{key:"defaultProps",value:{audio:!0,height:480,width:640,screenshotFormat:"image/webp"},enumerable:!0},{key:"propTypes",value:{audio:u.PropTypes.bool,onUserMedia:u.PropTypes.func,height:u.PropTypes.oneOfType([u.PropTypes.number,u.PropTypes.string]),width:u.PropTypes.oneOfType([u.PropTypes.number,u.PropTypes.string]),screenshotFormat:u.PropTypes.oneOf(["image/webp","image/png","image/jpeg"])},enumerable:!0},{key:"mountedInstances",value:[],enumerable:!0},{key:"userMediaRequested",value:!1,enumerable:!0}]),t.prototype.componentDidMount=function(){a()&&(t.mountedInstances.push(this),this.state.hasUserMedia||t.userMediaRequested||this.requestUserMedia())},t.prototype.requestUserMedia=function(){var e=this;navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;var r=function(r,n){var o={video:{optional:[{sourceId:n}]}};e.props.audio&&(o.audio={optional:[{sourceId:r}]}),navigator.getUserMedia(o,function(e){t.mountedInstances.forEach(function(t){return t.handleUserMedia(null,e)})},function(e){t.mountedInstances.forEach(function(t){return t.handleUserMedia(e)})})};this.props.audioSource&&this.props.videoSource?r(this.props.audioSource,this.props.videoSource):"mediaDevices"in navigator?navigator.mediaDevices.enumerateDevices().then(function(e){var t=null,n=null;e.forEach(function(e){"audio"===e.kind?t=e.id:"video"===e.kind&&(n=e.id)}),r(t,n)}).catch(function(e){return console.log(e.name+": "+e.message)}):MediaStreamTrack.getSources(function(e){var t=null,n=null;e.forEach(function(e){"audio"===e.kind?t=e.id:"video"===e.kind&&(n=e.id)}),r(t,n)}),t.userMediaRequested=!0},t.prototype.handleUserMedia=function(e,t){if(e)return void this.setState({hasUserMedia:!1});var r=window.URL.createObjectURL(t);this.stream=t,this.setState({hasUserMedia:!0,src:r}),this.props.onUserMedia&&this.props.onUserMedia()},t.prototype.componentWillUnmount=function(){var e=t.mountedInstances.indexOf(this);t.mountedInstances.splice(e,1),0===t.mountedInstances.length&&this.state.hasUserMedia&&(this.stream.stop(),t.userMediaRequested=!1,window.URL.revokeObjectURL(this.state.src))},t.prototype.getScreenshot=function(){if(!this.state.hasUserMedia)return null;var e=this.getCanvas();return e.toDataURL(this.props.screenshotFormat)},t.prototype.getCanvas=function(){if(!this.state.hasUserMedia)return null;var e=c.default.findDOMNode(this);if(!this.ctx){var t=document.createElement("canvas");t.height=e.clientHeight,t.width=e.clientWidth,this.canvas=t,this.ctx=t.getContext("2d")}var r=this.ctx,n=this.canvas;return r.drawImage(e,0,0,n.width,n.height),n},t.prototype.render=function(){return c.default.createElement("video",{autoPlay:!0,width:this.props.width,height:this.props.height,src:this.state.src})},t}(u.Component);t.default=d,e.exports=t.default},function(t,r){t.exports=e}])});
{
"name": "react-webcam",
"version": "0.0.5",
"version": "0.0.6",
"description": "React webcam component",

@@ -5,0 +5,0 @@ "main": "dist/react-webcam.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc