Merge pull request #70 from towerofnix/fix-firefox-loudness

Don't use mediaStream property, which is missing on Firefox
This commit is contained in:
Eric Rosenbaum 2018-01-16 15:39:58 -05:00 committed by GitHub
commit 84fdf5c76a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -271,6 +271,7 @@ class AudioEngine {
if (!this.mic && !this.connectingToMic) { if (!this.mic && !this.connectingToMic) {
this.connectingToMic = true; // prevent multiple connection attempts this.connectingToMic = true; // prevent multiple connection attempts
navigator.mediaDevices.getUserMedia({audio: true}).then(stream => { navigator.mediaDevices.getUserMedia({audio: true}).then(stream => {
this.audioStream = stream;
this.mic = this.audioContext.createMediaStreamSource(stream); this.mic = this.audioContext.createMediaStreamSource(stream);
this.analyser = this.audioContext.createAnalyser(); this.analyser = this.audioContext.createAnalyser();
this.mic.connect(this.analyser); this.mic.connect(this.analyser);
@ -282,7 +283,7 @@ class AudioEngine {
} }
// If the microphone is set up and active, measure the loudness // If the microphone is set up and active, measure the loudness
if (this.mic && this.mic.mediaStream.active) { if (this.mic && this.audioStream.active) {
this.analyser.getFloatTimeDomainData(this.micDataArray); this.analyser.getFloatTimeDomainData(this.micDataArray);
let sum = 0; let sum = 0;
// compute the RMS of the sound // compute the RMS of the sound