-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot read property 'oneOf' of undefined - Always thrown #4
Comments
I might of fixed this issue. "PropTypes" was moved out of "react" so I basically copied the component into a local file and made changes as needed. import React from 'react'
import PropTypes from 'prop-types';
class Recorder extends React.Component {
start () {
this.mediaRecorder.start()
}
stop () {
this.mediaRecorder.stop()
}
pause () {
this.mediaRecorder.pause()
}
resume () {
this.mediaRecorder.resume()
}
componentDidMount () {
navigator.getUserMedia = (navigator.getUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia ||
navigator.webkitGetUserMedia);
if (navigator.getUserMedia && window.MediaRecorder) {
const constraints = {audio: true};
this.chunks = [];
const { blobOpts, onStop, onError, mediaOpts, onPause, onResume, onStart, gotStream } = this.props;
const onErr = err => {
console.warn(err);
if (onError) onError(err)
};
const onSuccess = stream => {
this.mediaRecorder = new window.MediaRecorder(stream, mediaOpts || {});
this.mediaRecorder.ondataavailable = e => {
this.chunks.push(e.data)
};
this.mediaRecorder.onstop = e => {
const blob = new window.Blob(this.chunks, blobOpts || {type: 'audio/wav'});
this.chunks = [];
onStop(blob)
};
this.mediaRecorder.onerror = onErr;
if (onPause) this.mediaRecorder.onpause = onPause;
if (onResume) this.mediaRecorder.onresume = onResume;
if (onStart) this.mediaRecorder.onstart = onStart;
this.stream = stream;
if (gotStream) gotStream(stream)
};
navigator.getUserMedia(constraints, onSuccess, onErr)
} else {
console.warn('Audio recording APIs not supported by this browser');
const { onMissingAPIs } = this.props;
if (onMissingAPIs) {
onMissingAPIs(navigator.getUserMedia, window.MediaRecorder)
} else {
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
}
}
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
};
export default Recorder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regardless of whether or not I hardcode the 'command' prop to the component I get a 'oneOf' property error
My desire would be for
this.state.command
to be passed but that also throws the error.The text was updated successfully, but these errors were encountered: