From f09149b79895ca989b8a7d70333e2f413b85fd42 Mon Sep 17 00:00:00 2001 From: Brian Chirls Date: Tue, 7 Mar 2017 15:33:56 -0500 Subject: [PATCH] Attempt to detect HMD microphone #4 doesn't work all the time, but it couldn't hurt --- src/js/puppet-show-recorder.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/js/puppet-show-recorder.js b/src/js/puppet-show-recorder.js index 8475b53..4261818 100644 --- a/src/js/puppet-show-recorder.js +++ b/src/js/puppet-show-recorder.js @@ -4,6 +4,8 @@ import Recorder from 'recorderjs'; import eventEmitter from 'event-emitter'; import now from './now'; +const hmdLabelRegex = /vive/i; + function PuppetShowRecorder(options) { /* todo: @@ -104,16 +106,27 @@ function PuppetShowRecorder(options) { } navigator.mediaDevices.enumerateDevices().then(devices => { - audioInputDevices.length = 0; + const hmdGroupIds = {}; devices.forEach(dev => { if (dev.kind === 'audioinput') { audioInputDevices.push(dev); - // todo: prioritize Vive or Rift mic + // select default device if (dev.deviceId === 'default' || !audioInputDevice) { audioInputDevice = dev; } } + + if (hmdLabelRegex.test(dev.label)) { + hmdGroupIds[dev.groupId] = true; + } + }); + + // if a microphone device is in the same group as a HMD output, use it + audioInputDevices.forEach(dev => { + if (hmdGroupIds[dev.groupId]) { + audioInputDevice = dev; + } }); recordConstraints.audio.deviceId = audioInputDevice.deviceId;