PhilipsHue / flutter_reactive_ble

Flutter library that handles BLE operations for multiple devices.
https://developers.meethue.com/
Other
661 stars 321 forks source link

connectToAdvertisingDevice while already scanning #872

Open maBarabas opened 2 months ago

maBarabas commented 2 months ago

Describe the bug

When connecting to a device while a scan is in progress, TimeoutException is thrown.

It looks like the intention was that the existing scan results can be reused for the connection and the connection should work. However, this only happens if the existing scan ends within the timeout here. If the scan ends early, then connection is attempted before prescanDuration has elapsed, so it seems like it doesn't work as intended. If the scan doesn't end within the timeout, then the connection is never attempted even if the device was scanned by the existing scan session.

To Reproduce Steps to reproduce the behavior:

  1. Scan for devices
  2. Connect to device using connectToAdvertisingDevice() while keeping the scan going
  3. Connection fails with a prescanDuration + 1s timeout, and no stack trace

Expected behavior Existing scan results are used to connect to the advertising device, instead of waiting for the existing scan to end in prescanDuration + 1s, then failing if it doesn't end.

Smartphone / tablet

Peripheral device doesn't matter

Additional context