opentok/opentok-react-native

Bluetooth headset reconnect does not work on android

Closed this issue · 4 comments

pietgk commented

Bug Report

Current behavior

Reconnecting a bleutooth headset to an android device does not work.

Steps to reproduce

  • Clone BasicVideoChat example Link
  • Connect a Bluetooth headset to the mobile device
  • Open the App on a physical Android device
  • Test that the Bluetooth(BT) headset microphone and sound works.
  • Disconnect the BT headset (turning off the BT Headset or turning off Phone Bluetooth).
  • Connect the BT Headset (turning on the device and make sure its connected to the phone).
  • Test that the BT Headset is used fails,
    the phone mic and speaker are still active and the BT headset mic and sound are not active)

Example Project

both using the latest version as of 2023-04-12.

What is the current bug behavior?
After reconnecting the BT Headset it does not connect. The sound still goes to the phone speaker and the phone microphone is used.
Note: The phone is connected to the BT headset, put the vonage session is not using it, it seems.

What is the expected correct behavior?
That after reconnecting the BT Headset it connects and the BT Headset microphone is used and the sound goes to the BT Headset.

Relevant logs and/or screenshots

Additional info

  • The issue is only for Android (iOS works).
  • after stopping the react-native app and start it again the BT headset connects again.
  • reconnect then fails again.

We test with the following combinations of android devices and BT headsets:

Samsung Galaxy-S20 android 12, JBL-Pro2,
Samsung Galaxy-S20 android 12, Jbl WH 5.0:,
Samsung Galaxy-S20 android 12, Apple AirPods 1

Samsung Galaxy-S10E android 12, LG HBS-FN6

Samsung Galaxy-S20 FE android 12, Apple Airpods
Samsung Galaxy S10e android 9, Apple Airpods
Samsung Galaxy S10e android 9, Powerbeats Pro

EdShel commented

Our team had the same problem. Explicitly asking Android permission android.permission.BLUETOOTH_CONNECT helped.

However, the permission is needed for Platform.Version >= 31 (Android version 12), and this doesn't explain why BT doesn't work for you on Android 9...

pietgk commented

We have a work around / fix by forcing the speaker off and enabling the already connected BT headset.

import InCallManager from "react-native-incall-manager";
import BluetoothStateManager from "react-native-bluetooth-state-manager";
const handleAudioDeviceChanged = async (audioDevice: string): Promise<void> => {
  // Check if Bluetooth is enabled
  const isBluetoothEnabled = await BluetoothStateManager.getState();
  if (isBluetoothEnabled !== "PoweredOn") {
    return;
  }
  // Check if a Bluetooth device is connected
  const isBluetoothDeviceConnected = audioDevice === "BLUETOOTH";
  setHeadsetConnected(isBluetoothDeviceConnected);
  if (isBluetoothDeviceConnected) {
    // Prevent the call from using the speaker if a Bluetooth headset is available
    InCallManager.setSpeakerphoneOn(false); // Turn off the speakerphone
    InCallManager.start({ media: "video" });
  } else {
    // If there is no Bluetooth headset connected, allow using the speaker
    InCallManager.setSpeakerphoneOn(true); // Turn on the speakerphone
  }
};

please note that you might need

  <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

please note that this issue is as far as we know on all the tested android versions.

pietgk commented

We also have an outstanding support request on this issue. also Vonage mentioned that they also looking into a BT issue that could overlap with this one.

This issue was fixed with v0.21.5 of the SDK.