-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add device ID to NiimbotCapacitorBleClient options
- Loading branch information
Showing
1 changed file
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,17 @@ import { ConnectResult } from "../packets"; | |
import { Utils } from "../utils"; | ||
import { BleCharacteristic, BleClient, BleDevice, BleService } from "@capacitor-community/bluetooth-le"; | ||
|
||
interface NiimbotCapacitorBleClientConnectOptions { | ||
/** | ||
* Skip device picker dialog and connect to given device ID. | ||
* | ||
* On **Android** this is the BLE MAC address. | ||
* | ||
* On **iOS** and **web** it is an identifier. | ||
*/ | ||
deviceId?: string; | ||
} | ||
|
||
/** | ||
* Uses [@capacitor-community/bluetooth-le](https://github.com/capacitor-community/bluetooth-le) | ||
* | ||
|
@@ -22,7 +33,7 @@ export class NiimbotCapacitorBleClient extends NiimbotAbstractClient { | |
private characteristicUUID?: string; | ||
private packetBuf = new Uint8Array(); | ||
|
||
public async connect(): Promise<ConnectionInfo> { | ||
public async connect(options?: NiimbotCapacitorBleClientConnectOptions): Promise<ConnectionInfo> { | ||
await this.disconnect(); | ||
|
||
await BleClient.initialize({ androidNeverForLocation: true }); | ||
|
@@ -33,7 +44,16 @@ export class NiimbotCapacitorBleClient extends NiimbotAbstractClient { | |
throw new Error("Bluetooth is not enabled"); | ||
} | ||
|
||
const device: BleDevice = await BleClient.requestDevice(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
MultiMote
Author
Owner
|
||
let device: BleDevice; | ||
|
||
if (options?.deviceId !== undefined) { | ||
device = { | ||
deviceId: options.deviceId, | ||
name: options.deviceId, | ||
}; | ||
} else { | ||
device = await BleClient.requestDevice(); | ||
} | ||
|
||
await BleClient.connect(device.deviceId, () => this.onBleDisconnect()); | ||
|
||
|
Is there a reason the Capacitor BLE has no "filtering" while the web one does?
It can easily become very long list: