Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
"babel-preset-react": "^6.11.1",
"react": "^15.2.1",
"rimraf": "^2.5.3"
},
"dependencies": {
"prop-types": "^15.0.0"
}
}
58 changes: 32 additions & 26 deletions src/Recorder.js
Original file line number Diff line number Diff line change
@@ -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 ||
Expand All @@ -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

Expand Down Expand Up @@ -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