Skip to content

fix(web): stop advertisement watching before GATT connect - #310

Draft
usmanmehmood55 wants to merge 2 commits into
Navideck:mainfrom
usmanmehmood55:fix/web-advertisement-connect
Draft

usmanmehmood55 wants to merge 2 commits into
Navideck:mainfrom
usmanmehmood55:fix/web-advertisement-connect

Conversation

@usmanmehmood55

@usmanmehmood55 usmanmehmood55 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Issue

On Web, BLE scan, disconnect, and reconnect cleanup could overlap with a new GATT connection. Chrome could begin connecting while advertisement watching was still stopping, or reconnect using stale service and subscription state. This caused intermittent connection failures that often succeeded on retry.

Changes

  • Wait for advertisement watching to stop before starting a GATT connection.
  • Wait for a fresh advertisement when reconnecting to a previously used device.
  • Fall back to the normal GATT connection when advertisement watching is unavailable or times out.
  • Reset reconnect tracking when the browser returns a freshly selected device.
  • Cancel stale connection and characteristic subscriptions during disconnect.
  • Clear cached services after failed connections and during teardown.
  • Explicitly emit the disconnected state after native disconnection.
  • Preserve caller-defined connection timeouts and existing Web advertisement support.

Validation

  • flutter analyze passed.
  • flutter test passed.
  • Manually tested

- Await advertisement subscription cancellation and browser unwatching before connection attempts.
- Preserve caller-provided connection timeouts and Web advertisement support.
- Clear stale service state after failed Web GATT connections.
@usmanmehmood55
usmanmehmood55 force-pushed the fix/web-advertisement-connect branch from eeff4c4 to dbd0e3a Compare September 22, 2026 10:26
@usmanmehmood55
usmanmehmood55 marked this pull request as draft September 23, 2026 07:33
- Wait for a fresh advertisement before reconnecting to a previously used device.
- Fall back to the normal GATT connection when advertisement watching is unavailable or times out.
- Reset reconnect tracking after the browser returns a freshly selected device.
- Cancel stale connection and characteristic subscriptions before disconnecting.
- Clear cached services and stop advertisement watching during teardown.
- Emit the disconnected state explicitly after native disconnection.
@fotiDim

fotiDim commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@usmanmehmood55 are you done with the changes? Should the PR be in draft?

@usmanmehmood55

Copy link
Copy Markdown
Contributor Author

@fotiDim I'd like to throughly test these changes, so in draft right now.

Rapidly connecting/disconnecting and auto-reconnect has shown lots of problems on web, so I want to make sure I'm fixing it in the right place (in my app or in universal_ble).

Probably I'll submit it for review on Tuesday.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants