Skip to content
This repository was archived by the owner on Feb 18, 2022. It is now read-only.
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
54 changes: 54 additions & 0 deletions src/components/mic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// @flow
import React, { Component } from 'react';
import PropTypes from 'prop-types';

type Props = {
children?: any;
};

type Context = {
audioContext: Object;
connectNode: Object;
};

export default class Mic extends Component {
connectNode: Object;
context: Context;
props: Props;
static displayName = 'Mic';
static propTypes = {
children: PropTypes.node,
};
static contextTypes = {
audioContext: PropTypes.object,
connectNode: PropTypes.object,
};
static childContextTypes = {
audioContext: PropTypes.object,
connectNode: PropTypes.object,
};
constructor(props: Props, context: Context) {
super(props);
this.connectNode = context.audioContext.createGain();
this.connectNode.connect(context.connectNode);
}
getChildContext(): Object {
return {
...this.context,
connectNode: this.connectNode,
};
}
componentDidMount() {
navigator.mediaDevices.getUserMedia({ audio: true })
.then((stream) => {
const micSource = this.context.audioContext.createMediaStreamSource(stream);
micSource.connect(this.context.connectNode);
});
}
componentWillUnmount() {
this.connectNode.disconnect();
}
render(): React.Element<any> {
return <span>{this.props.children}</span>;
}
}
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Delay from './components/delay.js';
import Filter from './components/filter.js';
import Gain from './components/gain.js';
import LFO from './components/lfo.js';
import Mic from './components/mic.js';
import Monosynth from './components/monosynth.js';
import MoogFilter from './components/moog-filter.js';
import Overdrive from './components/overdrive.js';
Expand All @@ -27,6 +28,7 @@ export {
Filter,
Gain,
LFO,
Mic,
MoogFilter,
Monosynth,
Overdrive,
Expand Down