Skip to content

Commit

Permalink
feat: Allow selecting mics and speakers configured in the OS
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaymankar committed Oct 17, 2024
1 parent d382043 commit 925b492
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions src/script/media/MediaDevicesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,30 +234,12 @@ export class MediaDevicesHandler {
device => device.kind === MediaDeviceType.VIDEO_INPUT,
);

/*
* On Windows the same device can be listed multiple times with different group ids ("default", "communications", etc.).
* In such a scenario, the device listed as "communications" device is preferred for conferencing calls, so we filter its duplicates.
*/
const microphones = mediaDevices.filter(device => device.kind === MediaDeviceType.AUDIO_INPUT);
const dedupedMicrophones = microphones.reduce<Record<string, MediaDeviceInfo>>((microphoneList, microphone) => {
if (!microphoneList.hasOwnProperty(microphone.deviceId) || microphone.deviceId === 'communications') {
microphoneList[microphone.groupId] = microphone;
}
return microphoneList;
}, {});

const speakers = mediaDevices.filter(device => device.kind === MediaDeviceType.AUDIO_OUTPUT);
const dedupedSpeakers = speakers.reduce<Record<string, MediaDeviceInfo>>((speakerList, speaker) => {
if (!speakerList.hasOwnProperty(speaker.deviceId) || speaker.deviceId === 'communications') {
speakerList[speaker.groupId] = speaker;
}
return speakerList;
}, {});

return {
cameras: videoInputDevices,
microphones: Object.values(dedupedMicrophones),
speakers: Object.values(dedupedSpeakers),
microphones: microphones,
speakers: speakers,
};
}

Expand Down

0 comments on commit 925b492

Please sign in to comment.