From 55bc2c0d8db05b4577dcfb85c4441173606acc79 Mon Sep 17 00:00:00 2001 From: Vicken Simonian Date: Mon, 3 Apr 2017 00:09:04 -0700 Subject: [PATCH] Add constraints as a prop Defaults to `{audio: true}` --- README.md | 4 ++++ src/Recorder.js | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6230b90..cfae2d6 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,10 @@ The options passed to the `Blob` constructor, including specifying the MIMEType The options passed to the `MediaRecorder` constructor. Defaults to `{}`. +### constraints + +The constraints passed to `navigator.getUserMedia`. Defaults to `{audio: true}`. + ### command Useful for Redux-like environments where changes in state are communicated via props. When the `command` prop is changed, the corresponding method is called. Allowed values are the method name strings (`['start', 'stop', 'resume', 'pause']`) as well as `'none'`, representing no method call. Developers can also call these methods directly by accessing the component's `ref`. diff --git a/src/Recorder.js b/src/Recorder.js index 1d93aa9..b095991 100644 --- a/src/Recorder.js +++ b/src/Recorder.js @@ -26,9 +26,8 @@ const Recorder = React.createClass({ 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 { constraints, blobOpts, onStop, onError, mediaOpts, onPause, onResume, onStart, gotStream } = this.props const onErr = err => { console.warn(err) @@ -56,7 +55,7 @@ const Recorder = React.createClass({ if (gotStream) gotStream(stream) } - navigator.getUserMedia(constraints, onSuccess, onErr) + navigator.getUserMedia(constraints || {audio: true}, onSuccess, onErr) } else { console.warn('Audio recording APIs not supported by this browser') const { onMissingAPIs } = this.props @@ -93,7 +92,8 @@ const Recorder = React.createClass({ onUnmount: PropTypes.func, gotStream: PropTypes.func, blobOpts: PropTypes.object, - mediaOpts: PropTypes.object + mediaOpts: PropTypes.object, + constraints: PropTypes.object } })