Skip to content

web-bluetooth: add requestAny + fromDevice for autodetect callers#1

Open
mannes wants to merge 1 commit into
mainfrom
feat/niimbot-autodetect
Open

web-bluetooth: add requestAny + fromDevice for autodetect callers#1
mannes wants to merge 1 commit into
mainfrom
feat/niimbot-autodetect

Conversation

@mannes
Copy link
Copy Markdown

@mannes mannes commented May 21, 2026

Factors WebBluetoothTransport.request(config) so the picker call and the GATT back half are independently callable:

  • requestAny(configs[]) — opens the picker with a union OR-filter across multiple device configs, returns the chosen BluetoothDevice without opening GATT. Used by callers that want to identify the device (advertised name, in-protocol probe) before committing to one config.
  • fromDevice(device, config) — connects GATT + resolves TX/RX on an already-paired device, skipping the picker entirely. Used to wrap the result of requestAny once the identification step picks a config.
  • buildFilters(configs[]) helper exposes the strict + name-only OR-filter logic (formerly inline in request()); each name-prefixed config emits both a {namePrefix, services} filter and a name-only fallback to catch chassis that advertise a generic BLE-UART service instead of the driver's primary service (e.g. Niimbot B1 + MCHP-UART).

request(config) is now a thin wrapper around requestAny([config]) → fromDevice(device, config); its behaviour is unchanged.

Consumer: thermal-label/niimbot's autodetect — opens the picker with a union of every registered niimbot chassis, then identifies via findDeviceByBleName or in-protocol PrinterInfo(0x08) probe before wrapping.

3 new tests; existing 22 tests still pass.

🤖 Generated with Claude Code

`request(config)` is now factored as `requestAny([config])` over
the picker call, plus `fromDevice(device, config)` for the GATT
back half. Lets a caller open the picker with a union filter
across multiple device configs, then wrap the chosen device with
the right config after identifying it — without re-prompting the
user.

`requestAny` builds the picker filter as a union of every config's
{namePrefix, services} pair plus a name-only fallback per
namePrefixed config, and unions `optionalServices` so post-pair
`getPrimaryService(...)` resolves regardless of which config the
autodetect lands on.

Used by `@thermal-label/niimbot-web`'s `requestPrinters` to open
the BLE picker with every registered niimbot chassis at once,
identify via advertised name (`findDeviceByBleName`) or in-protocol
probe (`identifyNiimbot`), and wrap the result.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant