diff --git a/package.json b/package.json index 4cb1abd..92f136f 100644 --- a/package.json +++ b/package.json @@ -33,5 +33,8 @@ "babel-preset-react": "^6.11.1", "react": "^15.2.1", "rimraf": "^2.5.3" + }, + "dependencies": { + "prop-types": "^15.0.0" } } diff --git a/src/Recorder.js b/src/Recorder.js index 1d93aa9..c94edc1 100644 --- a/src/Recorder.js +++ b/src/Recorder.js @@ -1,23 +1,24 @@ 'use strict' -import React, { PropTypes } from 'react' +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; -const Recorder = React.createClass({ +class Recorder extends Component { start () { this.mediaRecorder.start() - }, + } stop () { this.mediaRecorder.stop() - }, + } pause () { this.mediaRecorder.pause() - }, + } resume () { this.mediaRecorder.resume() - }, + } componentDidMount () { navigator.getUserMedia = (navigator.getUserMedia || @@ -26,7 +27,7 @@ const Recorder = React.createClass({ navigator.webkitGetUserMedia) if (navigator.getUserMedia && window.MediaRecorder) { - const constraints = {audio: true} + const { constraints } = this.props; this.chunks = [] const { blobOpts, onStop, onError, mediaOpts, onPause, onResume, onStart, gotStream } = this.props @@ -66,35 +67,40 @@ const Recorder = React.createClass({ window.alert('Your browser doesn\'t support native microphone recording. For best results, we recommend using Google Chrome or Mozilla Firefox to use this site.') } } - }, + } componentDidUpdate (prevProps) { if (this.props.command && this.props.command !== 'none' && prevProps.command !== this.props.command) { this[this.props.command]() } - }, + } componentWillUnmount () { if (this.props.onUnmount) this.props.onUnmount(this.stream) - }, + } render () { - return false - }, - - propTypes: { - command: PropTypes.oneOf(['start', 'stop', 'pause', 'resume', 'none']), - onStop: PropTypes.func.isRequired, - onMissingAPIs: PropTypes.func, - onError: PropTypes.func, - onPause: PropTypes.func, - onStart: PropTypes.func, - onResume: PropTypes.func, - onUnmount: PropTypes.func, - gotStream: PropTypes.func, - blobOpts: PropTypes.object, - mediaOpts: PropTypes.object + return false; } -}) +} + +Recorder.propTypes = { + command: PropTypes.oneOf(['start', 'stop', 'pause', 'resume', 'none']), + onStop: PropTypes.func.isRequired, + onMissingAPIs: PropTypes.func, + onError: PropTypes.func, + onPause: PropTypes.func, + onStart: PropTypes.func, + onResume: PropTypes.func, + onUnmount: PropTypes.func, + gotStream: PropTypes.func, + blobOpts: PropTypes.object, + mediaOpts: PropTypes.object, + constraints: PropTypes.object +} + +Recorder.defaultProps = { + constraints: {audio: true} +} export default Recorder