react-media-recorder
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=_interopDefault(require("react")),PropTypes=_interopDefault(require("prop-types"));class ReactMediaRecorder extends React.Component{constructor(e){if(super(e),_initialiseProps.call(this),!window.MediaRecorder)throw new Error("React Media Recorder: Unsupported browser");let{audio:t,video:r,muted:i,blobPropertyBag:s=(r?{type:"video/mp4"}:{type:"audio/wav"})}=e;r&&i&&(t=!1),this.requiredMedia={audio:"boolean"==typeof t?!!t:t,video:"boolean"==typeof r?!!r:r},this.blobPropertyBag=s}}ReactMediaRecorder.propTypes={audio:PropTypes.oneOfType([PropTypes.bool,PropTypes.object]),video:PropTypes.oneOfType([PropTypes.bool,PropTypes.object]),muted:({muted:e,audio:t,video:r})=>"boolean"!=typeof e?new Error("Invalid prop: muted should be a boolan value. Please check your react-media-recorder component declaration"):e&&t&&!r?new Error("It looks like you tried to mute as well as record audio. Please check your react-media-recorder component declaration"):void 0,render:PropTypes.func.isRequired,blobPropertyBag:PropTypes.object},ReactMediaRecorder.defaultProps={audio:!0,muted:!1,render:()=>null};var _initialiseProps=function(){this.state={status:"idle"},this.chunks=[],this.componentDidMount=(async()=>{const e=await this.getMediaStream();e?this.stream=e:this.setState({status:"permission_denied"})}),this.getMediaStream=(async()=>{try{return await window.navigator.mediaDevices.getUserMedia(this.requiredMedia)}catch(e){return!1}}),this.onRecordingStop=(()=>{const e=new Blob(this.chunks,this.blobPropertyBag),t=URL.createObjectURL(e);this.setState({mediaBlob:t})}),this.onRecordingActive=(({data:e})=>{this.chunks.push(e)}),this.initMediaRecorder=(e=>{const t=new MediaRecorder(e);return t.ondataavailable=this.onRecordingActive,t.onstop=this.onRecordingStop,t.onerror=(()=>this.setState({status:"recorder_error"})),t}),this.startRecording=(async()=>{if(!this.stream||this.stream&&!this.stream.active){const e=await this.getMediaStream();if(!e)return void this.setState({status:"permission_denied"});this.stream=e}this.mediaRecorder=this.initMediaRecorder(this.stream),this.chunks=[],this.setState({mediaBlob:null}),this.mediaRecorder.start(),this.setState({status:"recording"})}),this.pauseRecording=(()=>{this.mediaRecorder&&"recording"===this.mediaRecorder.state&&(this.setState({status:"paused"}),this.mediaRecorder.pause())}),this.resumeRecording=(()=>{this.mediaRecorder&&"paused"===this.mediaRecorder.state&&(this.setState({status:"recording"}),this.mediaRecorder.resume())}),this.stopRecording=(()=>{this.mediaRecorder&&"inactive"!==this.mediaRecorder.state&&(this.mediaRecorder.stop(),this.mediaRecorder=null,this.setState({status:"stopped"}))}),this.render=(()=>this.props.render({status:this.state.status,startRecording:this.startRecording,stopRecording:this.stopRecording,pauseRecording:this.pauseRecording,resumeRecording:this.resumeRecording,mediaBlob:this.state.mediaBlob}))};module.exports=ReactMediaRecorder; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=_interopDefault(require("react")),PropTypes=_interopDefault(require("prop-types"));class ReactMediaRecorder extends React.Component{constructor(e){if(super(e),_initialiseProps.call(this),!window.MediaRecorder)throw new Error("React Media Recorder: Unsupported browser");let{audio:t,video:r,blobPropertyBag:i=(r?{type:"video/mp4"}:{type:"audio/wav"})}=e;this.requiredMedia={audio:"boolean"==typeof t?!!t:t,video:"boolean"==typeof r?!!r:r},this.blobPropertyBag=i}}ReactMediaRecorder.propTypes={audio:PropTypes.oneOfType([PropTypes.bool,PropTypes.object]),video:PropTypes.oneOfType([PropTypes.bool,PropTypes.object]),muted:({muted:e,audio:t,video:r})=>"boolean"!=typeof e?new Error("Invalid prop: muted should be a boolan value. Please check your react-media-recorder component declaration"):e&&t&&!r?new Error("It looks like you tried to mute as well as record audio. Please check your react-media-recorder component declaration"):void 0,render:PropTypes.func.isRequired,blobPropertyBag:PropTypes.object},ReactMediaRecorder.defaultProps={audio:!0,muted:!1,render:()=>null};var _initialiseProps=function(){this.state={status:"idle"},this.chunks=[],this.componentDidMount=(async()=>{const e=await this.getMediaStream();if(e){let[t]=e.getAudioTracks();t.enabled=!this.props.muted,this.stream=e}else this.setState({status:"permission_denied"})}),this.componentDidUpdate=(e=>{if(e.muted!==this.props.muted){let[e]=this.stream.getAudioTracks();e.enabled=!this.props.muted}}),this.getMediaStream=(async()=>{try{return await window.navigator.mediaDevices.getUserMedia(this.requiredMedia)}catch(e){return!1}}),this.onRecordingStop=(()=>{const e=new Blob(this.chunks,this.blobPropertyBag),t=URL.createObjectURL(e);this.setState({mediaBlob:t})}),this.onRecordingActive=(({data:e})=>{this.chunks.push(e)}),this.initMediaRecorder=(e=>{const t=new MediaRecorder(e);return t.ondataavailable=this.onRecordingActive,t.onstop=this.onRecordingStop,t.onerror=(()=>this.setState({status:"recorder_error"})),t}),this.startRecording=(async()=>{if(!this.stream||this.stream&&!this.stream.active){const e=await this.getMediaStream();if(!e)return void this.setState({status:"permission_denied"});this.stream=e}this.mediaRecorder=this.initMediaRecorder(this.stream),this.chunks=[],this.setState({mediaBlob:null}),this.mediaRecorder.start(),this.setState({status:"recording"})}),this.pauseRecording=(()=>{this.mediaRecorder&&"recording"===this.mediaRecorder.state&&(this.setState({status:"paused"}),this.mediaRecorder.pause())}),this.resumeRecording=(()=>{this.mediaRecorder&&"paused"===this.mediaRecorder.state&&(this.setState({status:"recording"}),this.mediaRecorder.resume())}),this.stopRecording=(()=>{this.mediaRecorder&&"inactive"!==this.mediaRecorder.state&&(this.mediaRecorder.stop(),this.mediaRecorder=null,this.setState({status:"stopped"}))}),this.render=(()=>this.props.render({status:this.state.status,startRecording:this.startRecording,stopRecording:this.stopRecording,pauseRecording:this.pauseRecording,resumeRecording:this.resumeRecording,mediaBlob:this.state.mediaBlob}))};module.exports=ReactMediaRecorder; |
{ | ||
"name": "react-media-recorder", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": | ||
@@ -5,0 +5,0 @@ "A React component based on MediaRecorder() API to record audio/video streams", |
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
8939
14