From 624a9501cd118fbbbf280b689b7b98d8fad5bd3f Mon Sep 17 00:00:00 2001 From: Dmitry Dodzin Date: Sun, 2 Jul 2017 20:55:42 +0300 Subject: [PATCH 1/3] Adding the ability to change the navigator.getUserMedia constraints --- package.json | 3 ++- src/Recorder.js | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4cb1abd..f8847ce 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "MediaRecorder" ], "peerDependencies": { - "react": "^0.14.0 || ^15.0.0" + "react": "^0.14.0 || ^15.0.0", + "prop-types": "^15.0.0" }, "author": "Alex Grasley", "license": "MIT", diff --git a/src/Recorder.js b/src/Recorder.js index 1d93aa9..0bd090f 100644 --- a/src/Recorder.js +++ b/src/Recorder.js @@ -1,6 +1,7 @@ 'use strict' -import React, { PropTypes } from 'react' +import React from 'react'; +import PropTypes from 'prop-types'; const Recorder = React.createClass({ start () { @@ -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 @@ -93,7 +94,12 @@ const Recorder = React.createClass({ onUnmount: PropTypes.func, gotStream: PropTypes.func, blobOpts: PropTypes.object, - mediaOpts: PropTypes.object + mediaOpts: PropTypes.object, + constraints: PropTypes.object + }, + + defaultProps: { + constraints: {audio: true} } }) From 6d547907396d9fc65926156074c0cf4e922a45a9 Mon Sep 17 00:00:00 2001 From: Dmitry Dodzin Date: Sun, 2 Jul 2017 21:09:12 +0300 Subject: [PATCH 2/3] Changed to dependency after reading https://github.com/facebook/prop-types#how-to-depend-on-this-package --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f8847ce..92f136f 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,7 @@ "MediaRecorder" ], "peerDependencies": { - "react": "^0.14.0 || ^15.0.0", - "prop-types": "^15.0.0" + "react": "^0.14.0 || ^15.0.0" }, "author": "Alex Grasley", "license": "MIT", @@ -34,5 +33,8 @@ "babel-preset-react": "^6.11.1", "react": "^15.2.1", "rimraf": "^2.5.3" + }, + "dependencies": { + "prop-types": "^15.0.0" } } From f02964923b38b185135dfc02dc3bd38dd8b11323 Mon Sep 17 00:00:00 2001 From: Dmitry Dodzin Date: Sun, 2 Jul 2017 22:30:14 +0300 Subject: [PATCH 3/3] Converted the player to a class --- src/Recorder.js | 60 ++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Recorder.js b/src/Recorder.js index 0bd090f..c94edc1 100644 --- a/src/Recorder.js +++ b/src/Recorder.js @@ -1,24 +1,24 @@ 'use strict' -import React 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 || @@ -67,40 +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, - constraints: PropTypes.object - }, - - defaultProps: { - constraints: {audio: true} + 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