audioInputsChanged: async()

in src/providers/DevicesProvider/AudioInputProvider.tsx [88:122]


      audioInputsChanged: async (newAudioInputs: MediaDeviceInfo[]) => {
        console.log('AudioInputProvider - audio inputs updated');

        const hasSelectedDevice = newAudioInputs.some(
          (device) => device.deviceId === selectedInputRef.current
        );

        let nextInput: string = 'default';
        if (
          selectedInputRef.current &&
          !hasSelectedDevice &&
          newAudioInputs.length
        ) {
          console.log(
            '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') {
          console.log(
            `Audio devices updated and "default" device is selected. Reselecting input.`
          );
        }

        const nextDevice = await replaceDevice(nextInput);
        try {
          await meetingManager.selectAudioInputDevice(nextDevice);
        } catch (e) {
          console.error(`Error in selecting audio input device - ${e}`);
        }

        setAudioInputs(newAudioInputs);
      },