react-webcam
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -313,4 +313,2 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
}); | ||
this.props.onUserMedia(); | ||
} catch (err) { | ||
@@ -323,2 +321,4 @@ this.stream = stream; | ||
} | ||
this.props.onUserMedia(); | ||
} | ||
@@ -325,0 +325,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(r){if(i[r])return i[r].exports;var o=i[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var i={};return t.m=e,t.c=i,t.i=function(e){return e},t.d=function(e,i,r){t.o(e,i)||Object.defineProperty(e,i,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(t,i){t.exports=e},function(e,i){e.exports=t},function(e,t,i){"use strict";function r(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 n(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 a(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(){function e(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),c=i(1),d=r(c),p=i(0),h=r(p),f=function(e){function t(){o(this,t);var e=n(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.state={hasUserMedia:!1},e}return a(t,e),u(t,[{key:"componentDidMount",value:function(){s()&&(t.mountedInstances.push(this),this.state.hasUserMedia||t.userMediaRequested||this.requestUserMedia())}},{key:"componentWillUpdate",value:function(e){e.videoSource===this.props.videoSource&&e.audioSource===this.props.audioSource||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)}},{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;e.width=this.video.clientWidth,e.height=this.video.clientWidth/t,this.canvas=e,this.ctx=e.getContext("2d")}var i=this.ctx,r=this.canvas;return i.drawImage(this.video,0,0,r.width,r.height),r}},{key:"requestUserMedia",value:function(){var e=this;navigator.getUserMedia=navigator.mediaDevices.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;var i=function(i,r){var o={video:{optional:[{sourceId:r}]}};e.props.audio&&(o.audio={optional:[{sourceId:i}]}),navigator.mediaDevices.getUserMedia(o).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)})})};this.props.audioSource&&this.props.videoSource?i(this.props.audioSource,this.props.videoSource):"mediaDevices"in navigator?navigator.mediaDevices.enumerateDevices().then(function(t){var r=null,o=null;t.forEach(function(e){"audioinput"===e.kind?r=e.id:"videoinput"===e.kind&&(o=e.id)}),e.props.audioSource&&(r=e.props.audioSource),e.props.videoSource&&(o=e.props.videoSource),i(r,o)}).catch(function(e){console.log(e.name+": "+e.message)}):MediaStreamTrack.getSources(function(t){var r=null,o=null;t.forEach(function(e){"audio"===e.kind?r=e.id:"video"===e.kind&&(o=e.id)}),e.props.audioSource&&(r=e.props.audioSource),e.props.videoSource&&(o=e.props.videoSource),i(r,o)}),t.userMediaRequested=!0}},{key:"handleUserMedia",value:function(e,t){if(e)return void this.setState({hasUserMedia:!1});try{var i=window.URL.createObjectURL(t);this.stream=t,this.setState({hasUserMedia:!0,src:i}),this.props.onUserMedia()}catch(e){this.stream=t,this.video.srcObject=t,this.setState({hasUserMedia:!0})}}},{key:"render",value:function(){var e=this;return d.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);f.defaultProps={audio:!0,className:"",height:480,onUserMedia:function(){},screenshotFormat:"image/webp",width:640},f.propTypes={audio:h.default.bool,onUserMedia:h.default.func,height:h.default.oneOfType([h.default.number,h.default.string]),width:h.default.oneOfType([h.default.number,h.default.string]),screenshotFormat:h.default.oneOf(["image/webp","image/png","image/jpeg"]),style:h.default.object,className:h.default.string,audioSource:h.default.string,videoSource:h.default.string},f.mountedInstances=[],f.userMediaRequested=!1,t.default=f,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(i[r])return i[r].exports;var o=i[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var i={};return t.m=e,t.c=i,t.i=function(e){return e},t.d=function(e,i,r){t.o(e,i)||Object.defineProperty(e,i,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(t,i){t.exports=e},function(e,i){e.exports=t},function(e,t,i){"use strict";function r(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 n(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 a(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(){function e(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),c=i(1),d=r(c),p=i(0),h=r(p),f=function(e){function t(){o(this,t);var e=n(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.state={hasUserMedia:!1},e}return a(t,e),u(t,[{key:"componentDidMount",value:function(){s()&&(t.mountedInstances.push(this),this.state.hasUserMedia||t.userMediaRequested||this.requestUserMedia())}},{key:"componentWillUpdate",value:function(e){e.videoSource===this.props.videoSource&&e.audioSource===this.props.audioSource||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)}},{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;e.width=this.video.clientWidth,e.height=this.video.clientWidth/t,this.canvas=e,this.ctx=e.getContext("2d")}var i=this.ctx,r=this.canvas;return i.drawImage(this.video,0,0,r.width,r.height),r}},{key:"requestUserMedia",value:function(){var e=this;navigator.getUserMedia=navigator.mediaDevices.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;var i=function(i,r){var o={video:{optional:[{sourceId:r}]}};e.props.audio&&(o.audio={optional:[{sourceId:i}]}),navigator.mediaDevices.getUserMedia(o).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)})})};this.props.audioSource&&this.props.videoSource?i(this.props.audioSource,this.props.videoSource):"mediaDevices"in navigator?navigator.mediaDevices.enumerateDevices().then(function(t){var r=null,o=null;t.forEach(function(e){"audioinput"===e.kind?r=e.id:"videoinput"===e.kind&&(o=e.id)}),e.props.audioSource&&(r=e.props.audioSource),e.props.videoSource&&(o=e.props.videoSource),i(r,o)}).catch(function(e){console.log(e.name+": "+e.message)}):MediaStreamTrack.getSources(function(t){var r=null,o=null;t.forEach(function(e){"audio"===e.kind?r=e.id:"video"===e.kind&&(o=e.id)}),e.props.audioSource&&(r=e.props.audioSource),e.props.videoSource&&(o=e.props.videoSource),i(r,o)}),t.userMediaRequested=!0}},{key:"handleUserMedia",value:function(e,t){if(e)return void this.setState({hasUserMedia:!1});try{var i=window.URL.createObjectURL(t);this.stream=t,this.setState({hasUserMedia:!0,src:i})}catch(e){this.stream=t,this.video.srcObject=t,this.setState({hasUserMedia:!0})}this.props.onUserMedia()}},{key:"render",value:function(){var e=this;return d.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);f.defaultProps={audio:!0,className:"",height:480,onUserMedia:function(){},screenshotFormat:"image/webp",width:640},f.propTypes={audio:h.default.bool,onUserMedia:h.default.func,height:h.default.oneOfType([h.default.number,h.default.string]),width:h.default.oneOfType([h.default.number,h.default.string]),screenshotFormat:h.default.oneOf(["image/webp","image/png","image/jpeg"]),style:h.default.object,className:h.default.string,audioSource:h.default.string,videoSource:h.default.string},f.mountedInstances=[],f.userMediaRequested=!1,t.default=f,e.exports=t.default}])}); |
{ | ||
"name": "react-webcam", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "React webcam component", | ||
@@ -5,0 +5,0 @@ "main": "dist/react-webcam.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
145659