connectToAdvertisingDevice always waits for prescanDuration before attempting to connect to a device. It causes every connection attempt to take at least prescanDuration.
If the device is scanned before prescanDuration, then we should connect to it immediately, instead of waiting out the prescanDuration to speed up connections.
To Reproduce
Steps to reproduce the behavior:
Start a stopwatch
Connect to one device using connectToAdvertisingDevice(), prescanDuration = 5 seconds
Wait until connected
End stopwatch
Observe measured time is about 5 seconds.
Expected behavior
A clear and concise description of what you expected to happen.
If the device is scanned in 100ms, then start connecting after 100ms instead of waiting for the full prescanDuration.
[ ] I tried doing the same with a general BLE scanner application (e.g. nRF Connect) and it exhibits the expected behavior as described above not a feature in a BLE scanner app
Smartphone / tablet
Device: any
OS: any
Package version: any
Peripheral device
Vendor, model: [e.g. Fitbit Versa, iPhone SE, or CUSTOM]
Does it run a custom firmware / software: yes / no
Additional context
Add any other context about the problem here.
Describe the bug
connectToAdvertisingDevice always waits for prescanDuration before attempting to connect to a device. It causes every connection attempt to take at least prescanDuration.
The scan sessions is set up to end in prescanDuration here: https://github.com/PhilipsHue/flutter_reactive_ble/blame/96e083ac9edd2b6cb070f6534bb2309057257aa0/packages/flutter_reactive_ble/lib/src/device_connector.dart#L127, and the return below waits for the entire session to end before deciding if it should connect to the device or not.
If the device is scanned before prescanDuration, then we should connect to it immediately, instead of waiting out the prescanDuration to speed up connections.
To Reproduce Steps to reproduce the behavior:
connectToAdvertisingDevice()
, prescanDuration = 5 secondsObserve measured time is about 5 seconds.
Expected behavior A clear and concise description of what you expected to happen.
If the device is scanned in 100ms, then start connecting after 100ms instead of waiting for the full prescanDuration.
I tried doing the same with a general BLE scanner application (e.g. nRF Connect) and it exhibits the expected behavior as described abovenot a feature in a BLE scanner appSmartphone / tablet
Peripheral device
Additional context Add any other context about the problem here.