Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency in connectToDevice Timeout Behavior Between iOS and Android #1135

Closed
4 tasks done
DevGeorge opened this issue Nov 15, 2023 · 3 comments · Fixed by #1226
Closed
4 tasks done

Inconsistency in connectToDevice Timeout Behavior Between iOS and Android #1135

DevGeorge opened this issue Nov 15, 2023 · 3 comments · Fixed by #1226
Labels

Comments

@DevGeorge
Copy link

DevGeorge commented Nov 15, 2023

Prerequisites

  • I checked the documentation and FAQ without finding a solution
  • I checked to make sure that this issue has not already been filed
  • I'm sure that question is related to the library itself and not Bluetooth Low Energy or Classic in general. If that so, please post your question on StackOverflow.
  • I'm running the latest version

Question

We have encountered a significant inconsistency in the behavior of the timeout parameter in the connectToDevice method between iOS and Android platforms when using the react-native-ble-plx library.

Behavior:
On iOS, the timeout parameter functions as expected. It sets a limit on the duration for attempting a Bluetooth connection to a device.

On Android, however, the timeout parameter behaves differently and unexpectedly. Rather than acting solely as a connection attempt limiter, it appears to be functioning as a maximum duration for the connection itself. This means that once a connection is established, it automatically disconnects after the specified timeout duration. This behaviour is inconsistent with the iOS implementation and the expected functionality of a connection timeout. Also a disconnectListener gets fired up with an error of 'null'.

Steps to Reproduce:

Initialize the BLE manager and call the connectToDevice method with a timeout parameter on an Android device.
Observe that the device connects successfully but then disconnects after the specified timeout duration.
Perform the same steps on an iOS device and observe that the timeout only limits the connection attempt duration without affecting the connection's stability post-establishment.

@outinspace
Copy link

I was also able to reproduce this issue using 3.1.1.

@silsergey
Copy link

I can confirm the issue (3.1.2) on Android (Samsung S23). If the timeout is not specified, the device will keep the connection.
When the timeout is specified, the connection drops after some seconds with error: null as if it was disconnected by cancelDeviceConnection

A bit more information
The communication is done by writeCharacteristicWithoutResponseForDevice and monitorCharacteristicForDevice. May be this is helpful. No issues for iOS

@DaAitch
Copy link

DaAitch commented Dec 22, 2023

We have the same problem 👍.

Seems like on Android the timeout-timer is not reset after successful device connection or so, so it will trigger a disconnect after the timeout no matter connected successfully or not. On iOS it works.

I checked https://github.com/dotintent/react-native-ble-plx/blob/master/android/src/main/java/com/bleplx/adapter/BleModule.java#L1263 and I believe the Observable is leaking and never resolves? Shouldn't it be like connect.take(1).subscribe(...) or something like this? (it's been years I was using rx, sorry 🙄).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants