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 1.0.0 to 1.0.1

27

dist/react-webcam.js

@@ -337,25 +337,20 @@ (function webpackUniversalModuleDefinition(root, factory) {

key: 'handleUserMedia',
value: function handleUserMedia(error, stream) {
if (error) {
this.setState({
hasUserMedia: false
});
this.props.onUserMediaError(error);
value: function handleUserMedia(err, stream) {
if (err) {
this.setState({ hasUserMedia: false });
this.props.onUserMediaError(err);
return;
}
this.stream = stream;
try {
var src = window.URL.createObjectURL(stream);
this.stream = stream;
this.video.srcObject = stream;
this.setState({ hasUserMedia: true });
} catch (error) {
this.setState({
hasUserMedia: true,
src: src
src: window.URL.createObjectURL(stream)
});
} catch (err) {
this.stream = stream;
this.video.srcObject = stream;
this.setState({
hasUserMedia: true
});
}

@@ -362,0 +357,0 @@

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("prop-types"),require("react")):"function"==typeof define&&define.amd?define(["prop-types","react"],t):"object"==typeof exports?exports.Webcam=t(require("prop-types"),require("react")):e.Webcam=t(e.PropTypes,e.React)}(this,function(e,t){return function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(t,r){t.exports=e},function(e,r){e.exports=t},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(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 s(){return!!(navigator.mediaDevices.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia)}Object.defineProperty(t,"__esModule",{value:!0});var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},d=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}}(),c=r(1),f=n(c),l=r(0),p=n(l),h=p.default.oneOfType([p.default.string,p.default.arrayOf(p.default.string),p.default.shape({exact:p.default.oneOfType([p.default.string,p.default.arrayOf(p.default.string)])}),p.default.shape({ideal:p.default.oneOfType([p.default.string,p.default.arrayOf(p.default.string)])})]),m=p.default.oneOfType([p.default.shape({exact:p.default.bool}),p.default.shape({ideal:p.default.bool})]),v=p.default.oneOfType([p.default.number,p.default.shape({exact:p.default.number,ideal:p.default.number,min:p.default.number,max:p.default.number})]),y=v,g=p.default.shape({deviceId:h,groupId:h,autoGainControl:m,channelCount:v,latency:y,noiseSuppression:m,sampleRate:v,sampleSize:v,volume:y}),b=p.default.shape({deviceId:h,groupId:h,aspectRatio:y,facingMode:h,frameRate:y,height:v,width:v}),M=function(e){function t(){a(this,t);var e=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.state={hasUserMedia:!1},e}return o(t,e),d(t,[{key:"componentDidMount",value:function(){s()&&(t.mountedInstances.push(this),this.state.hasUserMedia||t.userMediaRequested||this.requestUserMedia())}},{key:"componentWillUpdate",value:function(e){JSON.stringify(e.audioConstraints)===JSON.stringify(this.props.audioConstraints)&&JSON.stringify(e.videoConstraints)===JSON.stringify(this.props.videoConstraints)||this.requestUserMedia()}},{key:"componentWillUnmount",value:function(){var e=t.mountedInstances.indexOf(this);t.mountedInstances.splice(e,1),0===t.mountedInstances.length&&this.state.hasUserMedia&&(this.stream.stop?this.stream.stop():(this.stream.getVideoTracks&&this.stream.getVideoTracks().map(function(e){return e.stop()}),this.stream.getAudioTracks&&this.stream.getAudioTracks().map(function(e){return e.stop()})),t.userMediaRequested=!1,window.URL.revokeObjectURL(this.state.src))}},{key:"getScreenshot",value:function(){if(!this.state.hasUserMedia)return null;var e=this.getCanvas();return e&&e.toDataURL(this.props.screenshotFormat,this.props.screenshotQuality)}},{key:"getCanvas",value:function(){if(!this.state.hasUserMedia||!this.video.videoHeight)return null;if(!this.ctx){var e=document.createElement("canvas"),t=this.video.videoWidth/this.video.videoHeight,r=this.props.screenshotWidth||this.video.clientWidth;e.width=r,e.height=r/t,this.canvas=e,this.ctx=e.getContext("2d")}var n=this.ctx,a=this.canvas;return n.drawImage(this.video,0,0,a.width,a.height),a}},{key:"requestUserMedia",value:function(){var e=this;navigator.getUserMedia=navigator.mediaDevices.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;var r=function(r,n){var a={video:n||!0};e.props.audio&&(a.audio=r||!0),navigator.mediaDevices.getUserMedia(a).then(function(e){t.mountedInstances.forEach(function(t){return t.handleUserMedia(null,e)})}).catch(function(e){t.mountedInstances.forEach(function(t){return t.handleUserMedia(e)})})};if("mediaDevices"in navigator)r(this.props.audioConstraints,this.props.videoConstraints);else{var n=function(e){return{optional:[{sourceId:e}]}},a=function(e){var t=(e||{}).deviceId;return"string"==typeof t?t:Array.isArray(t)&&t.length>0?t[0]:"object"===(void 0===t?"undefined":u(t))&&t.ideal?t.ideal:null};MediaStreamTrack.getSources(function(t){var i=null,o=null;t.forEach(function(e){"audio"===e.kind?i=e.id:"video"===e.kind&&(o=e.id)});var s=a(e.props.audioConstraints);s&&(i=s);var u=a(e.props.videoConstraints);u&&(o=u),r(n(i),n(o))})}t.userMediaRequested=!0}},{key:"handleUserMedia",value:function(e,t){if(e)return this.setState({hasUserMedia:!1}),void this.props.onUserMediaError(e);try{var r=window.URL.createObjectURL(t);this.stream=t,this.setState({hasUserMedia:!0,src:r})}catch(e){this.stream=t,this.video.srcObject=t,this.setState({hasUserMedia:!0})}this.props.onUserMedia()}},{key:"render",value:function(){var e=this;return f.default.createElement("video",{autoPlay:!0,width:this.props.width,height:this.props.height,src:this.state.src,muted:this.props.audio,className:this.props.className,playsInline:!0,style:this.props.style,ref:function(t){e.video=t}})}}]),t}(c.Component);M.defaultProps={audio:!0,className:"",height:480,onUserMedia:function(){},onUserMediaError:function(){},screenshotFormat:"image/webp",width:640,screenshotQuality:.92},M.propTypes={audio:p.default.bool,onUserMedia:p.default.func,onUserMediaError:p.default.func,height:p.default.oneOfType([p.default.number,p.default.string]),width:p.default.oneOfType([p.default.number,p.default.string]),screenshotFormat:p.default.oneOf(["image/webp","image/png","image/jpeg"]),style:p.default.object,className:p.default.string,screenshotQuality:p.default.number,screenshotWidth:p.default.number,audioConstraints:g,videoConstraints:b},M.mountedInstances=[],M.userMediaRequested=!1,t.default=M,e.exports=t.default}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("prop-types"),require("react")):"function"==typeof define&&define.amd?define(["prop-types","react"],t):"object"==typeof exports?exports.Webcam=t(require("prop-types"),require("react")):e.Webcam=t(e.PropTypes,e.React)}(this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(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 s(){return!!(navigator.mediaDevices.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia)}Object.defineProperty(t,"__esModule",{value:!0});var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},d=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),c=n(1),f=r(c),l=n(0),p=r(l),h=p.default.oneOfType([p.default.string,p.default.arrayOf(p.default.string),p.default.shape({exact:p.default.oneOfType([p.default.string,p.default.arrayOf(p.default.string)])}),p.default.shape({ideal:p.default.oneOfType([p.default.string,p.default.arrayOf(p.default.string)])})]),m=p.default.oneOfType([p.default.shape({exact:p.default.bool}),p.default.shape({ideal:p.default.bool})]),v=p.default.oneOfType([p.default.number,p.default.shape({exact:p.default.number,ideal:p.default.number,min:p.default.number,max:p.default.number})]),y=v,g=p.default.shape({deviceId:h,groupId:h,autoGainControl:m,channelCount:v,latency:y,noiseSuppression:m,sampleRate:v,sampleSize:v,volume:y}),b=p.default.shape({deviceId:h,groupId:h,aspectRatio:y,facingMode:h,frameRate:y,height:v,width:v}),M=function(e){function t(){i(this,t);var e=a(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.state={hasUserMedia:!1},e}return o(t,e),d(t,[{key:"componentDidMount",value:function(){s()&&(t.mountedInstances.push(this),this.state.hasUserMedia||t.userMediaRequested||this.requestUserMedia())}},{key:"componentWillUpdate",value:function(e){JSON.stringify(e.audioConstraints)===JSON.stringify(this.props.audioConstraints)&&JSON.stringify(e.videoConstraints)===JSON.stringify(this.props.videoConstraints)||this.requestUserMedia()}},{key:"componentWillUnmount",value:function(){var e=t.mountedInstances.indexOf(this);t.mountedInstances.splice(e,1),0===t.mountedInstances.length&&this.state.hasUserMedia&&(this.stream.stop?this.stream.stop():(this.stream.getVideoTracks&&this.stream.getVideoTracks().map(function(e){return e.stop()}),this.stream.getAudioTracks&&this.stream.getAudioTracks().map(function(e){return e.stop()})),t.userMediaRequested=!1,window.URL.revokeObjectURL(this.state.src))}},{key:"getScreenshot",value:function(){if(!this.state.hasUserMedia)return null;var e=this.getCanvas();return e&&e.toDataURL(this.props.screenshotFormat,this.props.screenshotQuality)}},{key:"getCanvas",value:function(){if(!this.state.hasUserMedia||!this.video.videoHeight)return null;if(!this.ctx){var e=document.createElement("canvas"),t=this.video.videoWidth/this.video.videoHeight,n=this.props.screenshotWidth||this.video.clientWidth;e.width=n,e.height=n/t,this.canvas=e,this.ctx=e.getContext("2d")}var r=this.ctx,i=this.canvas;return r.drawImage(this.video,0,0,i.width,i.height),i}},{key:"requestUserMedia",value:function(){var e=this;navigator.getUserMedia=navigator.mediaDevices.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;var n=function(n,r){var i={video:r||!0};e.props.audio&&(i.audio=n||!0),navigator.mediaDevices.getUserMedia(i).then(function(e){t.mountedInstances.forEach(function(t){return t.handleUserMedia(null,e)})}).catch(function(e){t.mountedInstances.forEach(function(t){return t.handleUserMedia(e)})})};if("mediaDevices"in navigator)n(this.props.audioConstraints,this.props.videoConstraints);else{var r=function(e){return{optional:[{sourceId:e}]}},i=function(e){var t=(e||{}).deviceId;return"string"==typeof t?t:Array.isArray(t)&&t.length>0?t[0]:"object"===(void 0===t?"undefined":u(t))&&t.ideal?t.ideal:null};MediaStreamTrack.getSources(function(t){var a=null,o=null;t.forEach(function(e){"audio"===e.kind?a=e.id:"video"===e.kind&&(o=e.id)});var s=i(e.props.audioConstraints);s&&(a=s);var u=i(e.props.videoConstraints);u&&(o=u),n(r(a),r(o))})}t.userMediaRequested=!0}},{key:"handleUserMedia",value:function(e,t){if(e)return this.setState({hasUserMedia:!1}),void this.props.onUserMediaError(e);this.stream=t;try{this.video.srcObject=t,this.setState({hasUserMedia:!0})}catch(e){this.setState({hasUserMedia:!0,src:window.URL.createObjectURL(t)})}this.props.onUserMedia()}},{key:"render",value:function(){var e=this;return f.default.createElement("video",{autoPlay:!0,width:this.props.width,height:this.props.height,src:this.state.src,muted:this.props.audio,className:this.props.className,playsInline:!0,style:this.props.style,ref:function(t){e.video=t}})}}]),t}(c.Component);M.defaultProps={audio:!0,className:"",height:480,onUserMedia:function(){},onUserMediaError:function(){},screenshotFormat:"image/webp",width:640,screenshotQuality:.92},M.propTypes={audio:p.default.bool,onUserMedia:p.default.func,onUserMediaError:p.default.func,height:p.default.oneOfType([p.default.number,p.default.string]),width:p.default.oneOfType([p.default.number,p.default.string]),screenshotFormat:p.default.oneOf(["image/webp","image/png","image/jpeg"]),style:p.default.object,className:p.default.string,screenshotQuality:p.default.number,screenshotWidth:p.default.number,audioConstraints:g,videoConstraints:b},M.mountedInstances=[],M.userMediaRequested=!1,t.default=M,e.exports=t.default}])});
{
"name": "react-webcam",
"version": "1.0.0",
"version": "1.0.1",
"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