opentok / opentok-react-native

OpenTok React Native - a library for OpenTok iOS and Android SDKs
https://tokbox.com/
MIT License
210 stars 155 forks source link

Connecting a Bluetooth headset on Android while in a session is broken with Gradle Plugin 4.2.x or higher #624

Open OttoLaitinen opened 1 year ago

OttoLaitinen commented 1 year ago

Bug Report

Current behavior

Using Android Gradle Plugin 4.2.x or higher results in problems with Bluetooth on Android.

Steps to reproduce

  1. Clone BasicVideoChat example Link
  2. Change Gradle Plugin version to 4.2.2 in android/build.gradle (It needs Gradle version 6.7.1 so change that also)
  3. Open the App on a physical Android device
  4. Test sound without using a Bluetooth headset - microphone should work and output should be through the phone speaker
  5. Connect a Bluetooth headset to the mobile device
  6. Test sound -> Output is still coming through the device speaker and not the Bluetooth headset.

Example Project

Link to a fork with the problem

What is the current bug behavior?

Sound output doesn't come through a connected Bluetooth headset if the Bluetooth headset is connected to the mobile device during a session. (Sound comes through the mobile device speakers instead.)

If the Bluetooth headset is connected before opening the app (not session) then sound will come through the headset. However if headset is disconnected and reconnected the sound will keep coming through the mobile device speaker.

What is the expected correct behavior?

Sound output should come through the Bluetooth headset whenever it is connected to the mobile device. Otherwise the sound should come through the mobile device speakers.

Relevant logs and/or screenshots

N/A

enricop89 commented 1 year ago

WE are aware of it, it's an issue present also on the Android SDK. The team is working on a fix.

pietgk commented 1 year ago

FYI: we tried a workaround using enableStereoOutput: true option on the session. with it the inSession bluetooth disconnect connect is working. but we get an issue that the microphone is set as if we have the phone at your ear mode (not in speaker phone mode) when switching headset - speaker.

enricop89 commented 1 year ago

@OttoLaitinen can you try with opentok-react-native 0.21.1? https://github.com/OttoLaitinen/opentok-react-native-samples-gradle-plugin-issue/blob/main/BasicVideoChat/package.json#L13

OttoLaitinen commented 1 year ago

@OttoLaitinen can you try with opentok-react-native 0.21.1? https://github.com/OttoLaitinen/opentok-react-native-samples-gradle-plugin-issue/blob/main/BasicVideoChat/package.json#L13

Hi! Sorry it took some time to get back to you here on GH but I can confirm the bug can still be reproduced on 0.21.1 if every other version is kept the same as in the original issue description.

pietgk commented 1 year ago

@enricop89 i got feedback last week by mail from Roger Furtenheim, that the issue is solved in the android specific code. can you give any feedback on this?

pietgk commented 1 year ago

After testing BasicVideoChat with updated build.gradle

-    implementation 'com.opentok.android:opentok-android-sdk:2.23.1'
+    implementation 'com.opentok.android:opentok-android-sdk:2.24.1'

and OTSessionManager.java comment-out of @override

                    // @Override
                    public boolean isCamera2Capable() {
                        return isCamera2Capable;
                    }

the issue seems to be solved.

What remains an issue for us is getting a proper release including this update. As noted in the recent open issues, we will first need solving off the video freezing issue.

cnx-carlosvogt commented 1 year ago

Hi, I'm getting the same issue, but @pietgk answert didn't work for me, using the last version.

pietgk commented 1 year ago

@cnx-carlosvogt I am using the 0.21.3 version and tested it (it uses the android sdk 2.24.1). My reconnect bluetooth headset issue seems to be solved. We now experience that on android its not using speaker mode (low audio level), we are looking into that.

pietgk commented 12 months ago

I think we can close this issue from our point of view.

nicolasdevienne commented 8 months ago

Hi all! I've just test on 3 devices with the lastest version. On Samsung S9 (Android 9) and Huawei P20 (Android 9) it works : when I connect my bluetooth device during a video call, the switch from speaker to bluetooth device works. But on Pixel 5 (Android 14) the audio is always from speaker whereas the bluetooth device is connected. I must restart the app to use bluetooth device.

pietgk commented 5 months ago

@enricop89 We are running our app with the latest versions: opentok-react-native 2.27.2 react-native 0.73.6 All with the standard android config / versions from the standard RN upgrade to 0.73.6.

disconnecting a connected bluetooth headset in a call switches to speaker, reconnecting the bluetooth headset does not turn the sound to the headset (tested on Galaxy S10e, Android 9).

So the issue is NOT resolved.

This again blocks our release of the app.

We tried using react-native-incall-manager InCallManager.chooseAudioRoute to work around the issue but that does not solve the issue.

pietgk commented 5 months ago

tried enableStereoOutput in the session options to see if it makes a difference, but that crashes the app...

pietgk commented 5 months ago

I Created a Gist https://gist.github.com/pietgk/24d5dabb80cbe146de3bd6c4e3f3b6c1 that shows our workaround to get android headsets (bluetooth and wired) working:

the remaining open issue is that on mute on android 13 (probably >= 12) we need InCallManager.stop(); InCallManage.start({ media: "video"}); while on android 9 we tested that you can use InCallManager.setSpeakerphoneOn(false); InCallManage.start({ media: "video"}); The issue is that the stop() makes the speaker active for about 1s before bluetooth is activated again.

So as React-native is supported by Vonage. I Would like to STRESS that a proper headset support is added to a sample app with properly working (bluetooth) headsets.

Thanks in advance