web-bluetooth: add requestAny + fromDevice for autodetect callers#1
Open
mannes wants to merge 1 commit into
Open
web-bluetooth: add requestAny + fromDevice for autodetect callers#1mannes wants to merge 1 commit into
mannes wants to merge 1 commit into
Conversation
`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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 chosenBluetoothDevicewithout 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 ofrequestAnyonce the identification step picks a config.buildFilters(configs[])helper exposes the strict + name-only OR-filter logic (formerly inline inrequest()); 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 aroundrequestAny([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
findDeviceByBleNameor in-protocolPrinterInfo(0x08)probe before wrapping.3 new tests; existing 22 tests still pass.
🤖 Generated with Claude Code