livekit / client-sdk-flutter

Flutter Client SDK for LiveKit
https://docs.livekit.io
Apache License 2.0
244 stars 122 forks source link

Devices list on mobile doesn't match with room's selectedAudioInputDeviceId[bug] #262

Closed lindev0915 closed 1 week ago

lindev0915 commented 1 year ago

Describe the bug I was creating mobile app by using flutter livekit. But devices list is not working correctly. Hardware.instance.enumerateDevices() I got devices list. And it's returning like this. [MediaDevice{deviceId: 0, label: bottom, kind: audioinput}, MediaDevice{deviceId: 1, label: back, kind: audioinput}, MediaDevice{deviceId: 2, label: , kind: audioinput}] deviceId: 2 is wired headset. And I enabled microphone and get current selectedDeviceId. room?.selectedAudioInputDeviceId It's returning headset Because it's different, can't show selected device to users To Reproduce

Expected behavior

  1. It has to show correct label for wired headset.
  2. need to match deviceId between selectedAudioInputDeviceId and audioinputs devices list. Platform information I tested on android
    • Flutter version: 3.7.8
    • Plugin version:
    • Flutter target OS:
    • Flutter target OS version:
    • Flutter console log:
cloudwebrtc commented 1 year ago

fixed the label get for Wired Headset https://github.com/flutter-webrtc/flutter-webrtc/pull/1305

cloudwebrtc commented 1 year ago

However, due to the device control mechanism of the Android system, when the input is selected as Wired Headset, the audio output must also be selected as the same, otherwise the input selection will be invalid

davidzhao commented 1 year ago

Is it possible to handle that combination automatically within our SDK? so that the user doesn't get stuck in a weird state.

cloudwebrtc commented 1 year ago

My idea is to notify the default device to be switched to currentDevice through onDeviceChange. This event will be triggered when a wired headset is plugged in. The Android system will automatically switch the device to a wired headset, so we need to synchronize currentDevice to our SDK and notify the user of the current audio input/output is changed by the system

https://github.com/flutter-webrtc/flutter-webrtc/blob/main/android/src/main/java/com/cloudwebrtc/webrtc/FlutterWebRTCPlugin.java#L116

cloudwebrtc commented 1 week ago

In the mobile version of the new livekit sdk, the audio output/input has been taken over by the system, and you can only set whether you prefer to output from the speaker.