in src/providers/DevicesProvider/AudioInputProvider.tsx [71:117]
audioInputsChanged: async (newAudioInputs: MediaDeviceInfo[]) => {
logger.info('AudioInputProvider - audio inputs updated');
if (
meetingManager.getDeviceLabels() !== DeviceLabels.Audio &&
meetingManager.getDeviceLabels() !== DeviceLabels.AudioAndVideo
) {
logger.info(
'Device labels do not allow audio, skipping audio input selection on audioInputsChanged'
);
return;
}
const hasSelectedDevice = newAudioInputs.some(
(device) => device.deviceId === selectedInputRef.current
);
let nextInput: string = 'default';
if (
selectedInputRef.current &&
!hasSelectedDevice &&
newAudioInputs.length
) {
logger.info(
'Previously selected audio input lost. Selecting a default device.'
);
nextInput = newAudioInputs[0].deviceId;
// Safari and Firefox don't have this "default" as device Id
// Only Chrome have this "default" device
} else if (selectedInputRef.current === 'default') {
logger.info(
`Audio devices updated and "default" device is selected. Reselecting input.`
);
}
const nextDevice = await replaceDevice(nextInput);
try {
await meetingManager.startAudioInputDevice(nextDevice);
} catch (e) {
logger.error(
`Failed to select audio input device on audioInputsChanged: ${e}`
);
}
setAudioInputs(newAudioInputs);
},