react-user-media
Version:
React components for webcam and audio
14 lines • 11.9 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["react-user-media"]=t():e["react-user-media"]=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,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=1)}([function(e,t,r){"use strict";function n(e){return function(){return e}}var o=function(){};o.thatReturns=n,o.thatReturnsFalse=n(!1),o.thatReturnsTrue=n(!0),o.thatReturnsNull=n(null),o.thatReturnsThis=function(){return this},o.thatReturnsArgument=function(e){return e},e.exports=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(2),o=function(e){return e&&e.__esModule?e:{default:e}}(n);t.default=o.default},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 u(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 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)}Object.defineProperty(t,"__esModule",{value:!0});var a=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(3),s=n(c),f=r(7),l=n(f),p=function(e){function t(e){o(this,t);var r=u(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.state={hasUserMedia:!1,userMediaRequested:!1},r}return i(t,e),a(t,[{key:"componentDidMount",value:function(){if(!this._hasGetUserMedia())return!1;var e=this.state,t=e.hasUserMedia,r=e.userMediaRequested;t||r||this._requestUserMedia()}},{key:"componentWillUnmount",value:function(){this._mediaStream&&this._mediaStream.getTracks().forEach(function(e){return e.stop()})}},{key:"_hasGetUserMedia",value:function(){return!(!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia)}},{key:"_requestUserMedia",value:function(){var e=this,t={video:this.props.video,audio:this.props.audio};navigator.mediaDevices.getUserMedia(t).then(function(t){e._video.srcObject=t,e._mediaStream=t,e.setState({hasUserMedia:!0,userMediaRequested:!0}),e.props.onSuccess()}).catch(function(t){e.props.onFailure(t)})}},{key:"_getCanvas",value:function(){return this._captureCanvas?this._captureCanvas:(this._captureCanvas=document.createElement("canvas"),this._captureCanvas.width=this.props.width,this._captureCanvas.height=this.props.height,this._captureCanvas)}},{key:"captureCanvas",value:function(){var e=this.state,t=e.hasUserMedia,r=e.userMediaRequested,n=this.props,o=n.width,u=n.height;if(t&&r){var i=this._getCanvas();return i.getContext("2d").drawImage(this._video,0,0,o,u),i}}},{key:"captureScreenshot",value:function(){var e=this.props.captureFormat,t=this.captureCanvas();if(t)return t.toDataURL(e)}},{key:"captureBlob",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){},t=this.props.captureFormat,r=this.captureCanvas();if(r)return r.toBlob(e,t)}},{key:"render",value:function(){var e=this,t=this.props,r=t.width,n=t.height;return s.default.createElement("video",{width:r,height:n,ref:function(t){return e._video=t},autoPlay:!0})}}]),t}(c.Component);p.propTypes={audio:l.default.bool,width:l.default.number,height:l.default.number,captureFormat:l.default.oneOf(["image/png","image/jpeg","image/webp"]),onSuccess:l.default.func,onFailure:l.default.func},p.defaultProps={audio:!0,video:!0,width:640,height:480,captureFormat:"image/png",onSuccess:function(){},onFailure:function(e){throw console.error("An error occured while requesting user media"),e}},p._mediaStream=null,p._captureCanvas=null,t.default=p},function(e,t,r){"use strict";e.exports=r(4)},function(e,t,r){"use strict";function n(e){for(var t=arguments.length-1,r="Minified React error #"+e+"; visit http://facebook.github.io/react/docs/error-decoder.html?invariant="+e,n=0;n<t;n++)r+="&args[]="+encodeURIComponent(arguments[n+1]);throw t=Error(r+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."),t.name="Invariant Violation",t.framesToPop=1,t}function o(e,t,r){this.props=e,this.context=t,this.refs=g,this.updater=r||R}function u(e,t,r){this.props=e,this.context=t,this.refs=g,this.updater=r||R}function i(){}function a(e,t,r){this.props=e,this.context=t,this.refs=g,this.updater=r||R}function c(e,t,r){var n,o={},u=null,i=null;if(null!=t)for(n in void 0!==t.ref&&(i=t.ref),void 0!==t.key&&(u=""+t.key),t)T.call(t,n)&&!U.hasOwnProperty(n)&&(o[n]=t[n]);var a=arguments.length-2;if(1===a)o.children=r;else if(1<a){for(var c=Array(a),s=0;s<a;s++)c[s]=arguments[s+2];o.children=c}if(e&&e.defaultProps)for(n in a=e.defaultProps)void 0===o[n]&&(o[n]=a[n]);return{$$typeof:w,type:e,key:u,ref:i,props:o,_owner:M.current}}function s(e){return"object"==typeof e&&null!==e&&e.$$typeof===w}function f(e){var t={"=":"=0",":":"=2"};return"$"+(""+e).replace(/[=:]/g,function(e){return t[e]})}function l(e,t,r,n){if(A.length){var o=A.pop();return o.result=e,o.keyPrefix=t,o.func=r,o.context=n,o.count=0,o}return{result:e,keyPrefix:t,func:r,context:n,count:0}}function p(e){e.result=null,e.keyPrefix=null,e.func=null,e.context=null,e.count=0,10>A.length&&A.push(e)}function d(e,t,r,o){var u=typeof e;"undefined"!==u&&"boolean"!==u||(e=null);var i=!1;if(null===e)i=!0;else switch(u){case"string":case"number":i=!0;break;case"object":switch(e.$$typeof){case w:case j:case k:case S:i=!0}}if(i)return r(o,e,""===t?"."+h(e,0):t),1;if(i=0,t=""===t?".":t+":",Array.isArray(e))for(var a=0;a<e.length;a++){u=e[a];var c=t+h(u,a);i+=d(u,c,r,o)}else if(null===e||void 0===e?c=null:(c=P&&e[P]||e["@@iterator"],c="function"==typeof c?c:null),"function"==typeof c)for(e=c.call(e),a=0;!(u=e.next()).done;)u=u.value,c=t+h(u,a++),i+=d(u,c,r,o);else"object"===u&&(r=""+e,n("31","[object Object]"===r?"object with keys {"+Object.keys(e).join(", ")+"}":r,""));return i}function h(e,t){return"object"==typeof e&&null!==e&&null!=e.key?f(e.key):t.toString(36)}function y(e,t){e.func.call(e.context,t,e.count++)}function v(e,t,r){var n=e.result,o=e.keyPrefix;e=e.func.call(e.context,t,e.count++),Array.isArray(e)?m(e,n,r,_.thatReturnsArgument):null!=e&&(s(e)&&(t=o+(!e.key||t&&t.key===e.key?"":(""+e.key).replace(q,"$&/")+"/")+r,e={$$typeof:w,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}),n.push(e))}function m(e,t,r,n,o){var u="";null!=r&&(u=(""+r).replace(q,"$&/")+"/"),t=l(t,u,n,o),null==e||d(e,"",v,t),p(t)}/** @license React v16.2.0
* react.production.min.js
*
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var b=r(5),g=r(6),_=r(0),O="function"==typeof Symbol&&Symbol.for,w=O?Symbol.for("react.element"):60103,j=O?Symbol.for("react.call"):60104,k=O?Symbol.for("react.return"):60105,S=O?Symbol.for("react.portal"):60106,x=O?Symbol.for("react.fragment"):60107,P="function"==typeof Symbol&&Symbol.iterator,R={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}};o.prototype.isReactComponent={},o.prototype.setState=function(e,t){"object"!=typeof e&&"function"!=typeof e&&null!=e&&n("85"),this.updater.enqueueSetState(this,e,t,"setState")},o.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")},i.prototype=o.prototype;var C=u.prototype=new i;C.constructor=u,b(C,o.prototype),C.isPureReactComponent=!0;var E=a.prototype=new i;E.constructor=a,b(E,o.prototype),E.unstable_isAsyncReactComponent=!0,E.render=function(){return this.props.children};var M={current:null},T=Object.prototype.hasOwnProperty,U={key:!0,ref:!0,__self:!0,__source:!0},q=/\/+/g,A=[],F={Children:{map:function(e,t,r){if(null==e)return e;var n=[];return m(e,n,null,t,r),n},forEach:function(e,t,r){if(null==e)return e;t=l(null,null,t,r),null==e||d(e,"",y,t),p(t)},count:function(e){return null==e?0:d(e,"",_.thatReturnsNull,null)},toArray:function(e){var t=[];return m(e,t,null,_.thatReturnsArgument),t},only:function(e){return s(e)||n("143"),e}},Component:o,PureComponent:u,unstable_AsyncComponent:a,Fragment:x,createElement:c,cloneElement:function(e,t,r){var n=b({},e.props),o=e.key,u=e.ref,i=e._owner;if(null!=t){if(void 0!==t.ref&&(u=t.ref,i=M.current),void 0!==t.key&&(o=""+t.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(c in t)T.call(t,c)&&!U.hasOwnProperty(c)&&(n[c]=void 0===t[c]&&void 0!==a?a[c]:t[c])}var c=arguments.length-2;if(1===c)n.children=r;else if(1<c){a=Array(c);for(var s=0;s<c;s++)a[s]=arguments[s+2];n.children=a}return{$$typeof:w,type:e.type,key:o,ref:u,props:n,_owner:i}},createFactory:function(e){var t=c.bind(null,e);return t.type=e,t},isValidElement:s,version:"16.2.0",__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED:{ReactCurrentOwner:M,assign:b}},$=Object.freeze({default:F}),I=$&&F||$;e.exports=I.default?I.default:I},function(e,t,r){"use strict";function n(e){if(null===e||void 0===e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
var o=Object.getOwnPropertySymbols,u=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach(function(e){n[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var r,a,c=n(e),s=1;s<arguments.length;s++){r=Object(arguments[s]);for(var f in r)u.call(r,f)&&(c[f]=r[f]);if(o){a=o(r);for(var l=0;l<a.length;l++)i.call(r,a[l])&&(c[a[l]]=r[a[l]])}}return c}},function(e,t,r){"use strict";var n={};e.exports=n},function(e,t,r){e.exports=r(8)()},function(e,t,r){"use strict";var n=r(0),o=r(9),u=r(10);e.exports=function(){function e(e,t,r,n,i,a){a!==u&&o(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=n,r.PropTypes=r,r}},function(e,t,r){"use strict";function n(e,t,r,n,u,i,a,c){if(o(t),!e){var s;if(void 0===t)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var f=[r,n,u,i,a,c],l=0;s=new Error(t.replace(/%s/g,function(){return f[l++]})),s.name="Invariant Violation"}throw s.framesToPop=1,s}}var o=function(e){};e.exports=n},function(e,t,r){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}])});