@capacitor-community/bluetooth-le 7.3.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorCommunityBluetoothLe.podspec +2 -2
- package/Package.swift +28 -0
- package/README.md +2 -1
- package/android/build.gradle +17 -12
- package/dist/esm/bleClient.d.ts +278 -278
- package/dist/esm/bleClient.js +361 -361
- package/dist/esm/bleClient.js.map +1 -1
- package/dist/esm/config.d.ts +53 -53
- package/dist/esm/config.js +2 -2
- package/dist/esm/conversion.d.ts +56 -46
- package/dist/esm/conversion.js +134 -117
- package/dist/esm/conversion.js.map +1 -1
- package/dist/esm/definitions.d.ts +352 -352
- package/dist/esm/definitions.js +42 -42
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +5 -5
- package/dist/esm/plugin.d.ts +2 -2
- package/dist/esm/plugin.js +4 -4
- package/dist/esm/queue.d.ts +3 -3
- package/dist/esm/queue.js +17 -17
- package/dist/esm/queue.js.map +1 -1
- package/dist/esm/timeout.d.ts +1 -1
- package/dist/esm/timeout.js +9 -9
- package/dist/esm/validators.d.ts +1 -1
- package/dist/esm/validators.js +11 -11
- package/dist/esm/validators.js.map +1 -1
- package/dist/esm/web.d.ts +57 -57
- package/dist/esm/web.js +403 -403
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +965 -947
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +965 -947
- package/dist/plugin.js.map +1 -1
- package/ios/{Plugin → Sources/BluetoothLe}/DeviceListView.swift +1 -1
- package/ios/{Plugin → Sources/BluetoothLe}/DeviceManager.swift +1 -0
- package/ios/{Plugin → Sources/BluetoothLe}/Plugin.swift +39 -1
- package/ios/{Plugin → Sources/BluetoothLe}/ThreadSafeDictionary.swift +2 -0
- package/ios/Tests/BluetoothLeTests/ConversionTests.swift +55 -0
- package/ios/Tests/BluetoothLeTests/PluginTests.swift +27 -0
- package/package.json +18 -14
- package/ios/Plugin/Info.plist +0 -24
- package/ios/Plugin/Plugin.h +0 -10
- package/ios/Plugin/Plugin.m +0 -41
- /package/ios/{Plugin → Sources/BluetoothLe}/Conversion.swift +0 -0
- /package/ios/{Plugin → Sources/BluetoothLe}/Device.swift +0 -0
- /package/ios/{Plugin → Sources/BluetoothLe}/Logging.swift +0 -0
|
@@ -1,352 +1,352 @@
|
|
|
1
|
-
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
-
import type { DisplayStrings } from './config';
|
|
3
|
-
export interface InitializeOptions {
|
|
4
|
-
/**
|
|
5
|
-
* If your app doesn't use Bluetooth scan results to derive physical
|
|
6
|
-
* location information, you can strongly assert that your app
|
|
7
|
-
* doesn't derive physical location. (Android only)
|
|
8
|
-
* Requires adding 'neverForLocation' to AndroidManifest.xml
|
|
9
|
-
* https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location
|
|
10
|
-
* @default false
|
|
11
|
-
*/
|
|
12
|
-
androidNeverForLocation?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export interface RequestBleDeviceOptions {
|
|
15
|
-
/**
|
|
16
|
-
* Filter devices by service UUIDs.
|
|
17
|
-
* UUIDs have to be specified as 128 bit UUID strings,
|
|
18
|
-
* e.g. ['0000180d-0000-1000-8000-00805f9b34fb']
|
|
19
|
-
* There is a helper function to convert numbers to UUIDs.
|
|
20
|
-
* e.g. [numberToUUID(0x180f)]. (see [UUID format](#uuid-format))
|
|
21
|
-
*/
|
|
22
|
-
services?: string[];
|
|
23
|
-
/**
|
|
24
|
-
* Filter devices by name
|
|
25
|
-
*/
|
|
26
|
-
name?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Filter devices by name prefix
|
|
29
|
-
*/
|
|
30
|
-
namePrefix?: string;
|
|
31
|
-
/**
|
|
32
|
-
* For **web**, all services that will be used have to be listed under services or optionalServices,
|
|
33
|
-
* e.g. [numberToUUID(0x180f)] (see [UUID format](#uuid-format))
|
|
34
|
-
*/
|
|
35
|
-
optionalServices?: string[];
|
|
36
|
-
/**
|
|
37
|
-
* Normally scans will discard the second and subsequent advertisements from a single device.
|
|
38
|
-
* If you need to receive them, set allowDuplicates to true (only applicable in `requestLEScan`).
|
|
39
|
-
* (default: false)
|
|
40
|
-
*/
|
|
41
|
-
allowDuplicates?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Android scan mode (default: ScanMode.SCAN_MODE_BALANCED)
|
|
44
|
-
*/
|
|
45
|
-
scanMode?: ScanMode;
|
|
46
|
-
/**
|
|
47
|
-
* Allow scanning for devices with a specific manufacturer data
|
|
48
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice#manufacturerdata
|
|
49
|
-
*/
|
|
50
|
-
manufacturerData?: ManufacturerDataFilter[];
|
|
51
|
-
/**
|
|
52
|
-
* Display mode for the device list in `requestDevice` (**iOS** only).
|
|
53
|
-
* - `"alert"`: Classic alert dialog (default)
|
|
54
|
-
* - `"list"`: Scrollable list view
|
|
55
|
-
* @default "alert"
|
|
56
|
-
*/
|
|
57
|
-
displayMode?: 'alert' | 'list';
|
|
58
|
-
/**
|
|
59
|
-
* Allow scanning for devices with specific service data.
|
|
60
|
-
* Service data is data associated with a specific service UUID in the advertisement packet.
|
|
61
|
-
* Useful for protocols like OpenDroneID, EddyStone, and Open Beacon.
|
|
62
|
-
*/
|
|
63
|
-
serviceData?: ServiceDataFilter[];
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Android scan mode
|
|
67
|
-
*/
|
|
68
|
-
export declare enum ScanMode {
|
|
69
|
-
/**
|
|
70
|
-
* Perform Bluetooth LE scan in low power mode. This mode is enforced if the scanning application is not in foreground.
|
|
71
|
-
* https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_POWER
|
|
72
|
-
*/
|
|
73
|
-
SCAN_MODE_LOW_POWER = 0,
|
|
74
|
-
/**
|
|
75
|
-
* Perform Bluetooth LE scan in balanced power mode. (default) Scan results are returned at a rate that provides a good trade-off between scan frequency and power consumption.
|
|
76
|
-
* https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_BALANCED
|
|
77
|
-
*/
|
|
78
|
-
SCAN_MODE_BALANCED = 1,
|
|
79
|
-
/**
|
|
80
|
-
* Scan using highest duty cycle. It's recommended to only use this mode when the application is running in the foreground.
|
|
81
|
-
* https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_LATENCY
|
|
82
|
-
*/
|
|
83
|
-
SCAN_MODE_LOW_LATENCY = 2
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Android connection priority used in `requestConnectionPriority`
|
|
87
|
-
*/
|
|
88
|
-
export declare enum ConnectionPriority {
|
|
89
|
-
/**
|
|
90
|
-
* Use the connection parameters recommended by the Bluetooth SIG. This is the default value if no connection parameter update is requested.
|
|
91
|
-
* https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_BALANCED
|
|
92
|
-
*/
|
|
93
|
-
CONNECTION_PRIORITY_BALANCED = 0,
|
|
94
|
-
/**
|
|
95
|
-
* Request a high priority, low latency connection. An application should only request high priority connection parameters to transfer large amounts of data over LE quickly. Once the transfer is complete, the application should request CONNECTION_PRIORITY_BALANCED connection parameters to reduce energy use.
|
|
96
|
-
* https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_HIGH
|
|
97
|
-
*/
|
|
98
|
-
CONNECTION_PRIORITY_HIGH = 1,
|
|
99
|
-
/**
|
|
100
|
-
* Request low power, reduced data rate connection parameters.
|
|
101
|
-
* https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER
|
|
102
|
-
*/
|
|
103
|
-
CONNECTION_PRIORITY_LOW_POWER = 2
|
|
104
|
-
}
|
|
105
|
-
export interface ManufacturerDataFilter {
|
|
106
|
-
/**
|
|
107
|
-
* Company ID (sometimes called the manufacturer ID) to search for in the manufacturer data field.
|
|
108
|
-
*/
|
|
109
|
-
companyIdentifier: number;
|
|
110
|
-
/**
|
|
111
|
-
* Prefix to match in the manufacturer data field.
|
|
112
|
-
* On **Android** this field is mandatory.
|
|
113
|
-
* android, ios: DataView
|
|
114
|
-
* web: Uint8Array
|
|
115
|
-
*/
|
|
116
|
-
dataPrefix?: DataView | Uint8Array;
|
|
117
|
-
/**
|
|
118
|
-
* Set filter on partial manufacture data. For any bit in the mask, set it the 1 if it needs to match the one in manufacturer data, otherwise set it to 0.
|
|
119
|
-
* The `mask` must have the same length of dataPrefix.
|
|
120
|
-
* android, ios: DataView
|
|
121
|
-
* web: Uint8Array
|
|
122
|
-
*/
|
|
123
|
-
mask?: DataView | Uint8Array;
|
|
124
|
-
}
|
|
125
|
-
export interface ServiceDataFilter {
|
|
126
|
-
/**
|
|
127
|
-
* Service UUID to filter by. The service data must be associated with this UUID.
|
|
128
|
-
* UUIDs have to be specified as 128 bit UUID strings,
|
|
129
|
-
* e.g. '0000fffa-0000-1000-8000-00805f9b34fb'
|
|
130
|
-
*/
|
|
131
|
-
serviceUuid: string;
|
|
132
|
-
/**
|
|
133
|
-
* Prefix to match in the service data field.
|
|
134
|
-
* For example, OpenDroneID uses [0x0D] as the advertisement code.
|
|
135
|
-
* android, ios: string
|
|
136
|
-
* web: DataView
|
|
137
|
-
*/
|
|
138
|
-
dataPrefix?: DataView;
|
|
139
|
-
/**
|
|
140
|
-
* Set filter on partial service data. For any bit in the mask, set it to 1 if it needs to match the one in service data, otherwise set it to 0.
|
|
141
|
-
* The `mask` must have the same length as dataPrefix.
|
|
142
|
-
* android, ios: string
|
|
143
|
-
* web: DataView
|
|
144
|
-
*/
|
|
145
|
-
mask?: DataView;
|
|
146
|
-
}
|
|
147
|
-
export interface BleDevice {
|
|
148
|
-
/**
|
|
149
|
-
* ID of the device, which will be needed for further calls.
|
|
150
|
-
* On **Android** this is the BLE MAC address.
|
|
151
|
-
* On **iOS** and **web** it is an identifier.
|
|
152
|
-
*/
|
|
153
|
-
deviceId: string;
|
|
154
|
-
/**
|
|
155
|
-
* Name of the peripheral device.
|
|
156
|
-
*/
|
|
157
|
-
name?: string;
|
|
158
|
-
uuids?: string[];
|
|
159
|
-
}
|
|
160
|
-
export interface DeviceIdOptions {
|
|
161
|
-
deviceId: string;
|
|
162
|
-
}
|
|
163
|
-
export interface TimeoutOptions {
|
|
164
|
-
/**
|
|
165
|
-
* Timeout in milliseconds for plugin call.
|
|
166
|
-
* Default is 10000 for `connect` and 5000 for other plugin methods.
|
|
167
|
-
*/
|
|
168
|
-
timeout?: number;
|
|
169
|
-
}
|
|
170
|
-
export interface RequestConnectionPriorityOptions extends DeviceIdOptions {
|
|
171
|
-
connectionPriority: ConnectionPriority;
|
|
172
|
-
}
|
|
173
|
-
export interface GetDevicesOptions {
|
|
174
|
-
deviceIds: string[];
|
|
175
|
-
}
|
|
176
|
-
export interface GetConnectedDevicesOptions {
|
|
177
|
-
services: string[];
|
|
178
|
-
}
|
|
179
|
-
export interface BleService {
|
|
180
|
-
readonly uuid: string;
|
|
181
|
-
readonly characteristics: BleCharacteristic[];
|
|
182
|
-
}
|
|
183
|
-
export interface BleDescriptor {
|
|
184
|
-
readonly uuid: string;
|
|
185
|
-
}
|
|
186
|
-
export interface BleCharacteristic {
|
|
187
|
-
readonly uuid: string;
|
|
188
|
-
readonly properties: BleCharacteristicProperties;
|
|
189
|
-
readonly descriptors: BleDescriptor[];
|
|
190
|
-
}
|
|
191
|
-
export interface BleCharacteristicProperties {
|
|
192
|
-
readonly broadcast: boolean;
|
|
193
|
-
readonly read: boolean;
|
|
194
|
-
readonly writeWithoutResponse: boolean;
|
|
195
|
-
readonly write: boolean;
|
|
196
|
-
readonly notify: boolean;
|
|
197
|
-
readonly indicate: boolean;
|
|
198
|
-
readonly authenticatedSignedWrites: boolean;
|
|
199
|
-
readonly reliableWrite?: boolean;
|
|
200
|
-
readonly writableAuxiliaries?: boolean;
|
|
201
|
-
readonly extendedProperties?: boolean;
|
|
202
|
-
readonly notifyEncryptionRequired?: boolean;
|
|
203
|
-
readonly indicateEncryptionRequired?: boolean;
|
|
204
|
-
}
|
|
205
|
-
export interface BleServices {
|
|
206
|
-
services: BleService[];
|
|
207
|
-
}
|
|
208
|
-
export interface ReadOptions {
|
|
209
|
-
deviceId: string;
|
|
210
|
-
service: string;
|
|
211
|
-
characteristic: string;
|
|
212
|
-
}
|
|
213
|
-
export interface ReadDescriptorOptions {
|
|
214
|
-
deviceId: string;
|
|
215
|
-
service: string;
|
|
216
|
-
characteristic: string;
|
|
217
|
-
descriptor: string;
|
|
218
|
-
}
|
|
219
|
-
export type Data = DataView | string;
|
|
220
|
-
export interface WriteOptions {
|
|
221
|
-
deviceId: string;
|
|
222
|
-
service: string;
|
|
223
|
-
characteristic: string;
|
|
224
|
-
/**
|
|
225
|
-
* android, ios: string
|
|
226
|
-
* web: DataView
|
|
227
|
-
*/
|
|
228
|
-
value: Data;
|
|
229
|
-
}
|
|
230
|
-
export interface WriteDescriptorOptions {
|
|
231
|
-
deviceId: string;
|
|
232
|
-
service: string;
|
|
233
|
-
characteristic: string;
|
|
234
|
-
descriptor: string;
|
|
235
|
-
/**
|
|
236
|
-
* android, ios: string
|
|
237
|
-
* web: DataView
|
|
238
|
-
*/
|
|
239
|
-
value: Data;
|
|
240
|
-
}
|
|
241
|
-
export interface BooleanResult {
|
|
242
|
-
value: boolean;
|
|
243
|
-
}
|
|
244
|
-
export interface GetDevicesResult {
|
|
245
|
-
devices: BleDevice[];
|
|
246
|
-
}
|
|
247
|
-
export interface GetMtuResult {
|
|
248
|
-
value: number;
|
|
249
|
-
}
|
|
250
|
-
export interface ReadRssiResult {
|
|
251
|
-
value: string;
|
|
252
|
-
}
|
|
253
|
-
export interface ReadResult {
|
|
254
|
-
/**
|
|
255
|
-
* android, ios: string
|
|
256
|
-
* web: DataView
|
|
257
|
-
*/
|
|
258
|
-
value?: Data;
|
|
259
|
-
}
|
|
260
|
-
export interface ScanResultInternal<T = Data> {
|
|
261
|
-
device: BleDevice;
|
|
262
|
-
localName?: string;
|
|
263
|
-
rssi?: number;
|
|
264
|
-
txPower?: number;
|
|
265
|
-
manufacturerData?: {
|
|
266
|
-
[key: string]: T;
|
|
267
|
-
};
|
|
268
|
-
serviceData?: {
|
|
269
|
-
[key: string]: T;
|
|
270
|
-
};
|
|
271
|
-
uuids?: string[];
|
|
272
|
-
rawAdvertisement?: T;
|
|
273
|
-
}
|
|
274
|
-
export interface ScanResult {
|
|
275
|
-
/**
|
|
276
|
-
* The peripheral device that was found in the scan.
|
|
277
|
-
* **Android** and **web**: `device.name` is always identical to `localName`.
|
|
278
|
-
* **iOS**: `device.name` is identical to `localName` the first time a device is discovered, but after connecting `device.name` is the cached GAP name in subsequent scans.
|
|
279
|
-
*/
|
|
280
|
-
device: BleDevice;
|
|
281
|
-
/**
|
|
282
|
-
* The name of the peripheral device from the advertisement data.
|
|
283
|
-
*/
|
|
284
|
-
localName?: string;
|
|
285
|
-
/**
|
|
286
|
-
* Received Signal Strength Indication.
|
|
287
|
-
*/
|
|
288
|
-
rssi?: number;
|
|
289
|
-
/**
|
|
290
|
-
* Transmit power in dBm. A value of 127 indicates that it is not available.
|
|
291
|
-
*/
|
|
292
|
-
txPower?: number;
|
|
293
|
-
/**
|
|
294
|
-
* Manufacturer data, key is a company identifier and value is the data.
|
|
295
|
-
*/
|
|
296
|
-
manufacturerData?: {
|
|
297
|
-
[key: string]: DataView;
|
|
298
|
-
};
|
|
299
|
-
/**
|
|
300
|
-
* Service data, key is a service UUID and value is the data.
|
|
301
|
-
*/
|
|
302
|
-
serviceData?: {
|
|
303
|
-
[key: string]: DataView;
|
|
304
|
-
};
|
|
305
|
-
/**
|
|
306
|
-
* Advertised services.
|
|
307
|
-
*/
|
|
308
|
-
uuids?: string[];
|
|
309
|
-
/**
|
|
310
|
-
* Raw advertisement data (**Android** only).
|
|
311
|
-
*/
|
|
312
|
-
rawAdvertisement?: DataView;
|
|
313
|
-
}
|
|
314
|
-
export interface BluetoothLePlugin {
|
|
315
|
-
initialize(options?: InitializeOptions): Promise<void>;
|
|
316
|
-
isEnabled(): Promise<BooleanResult>;
|
|
317
|
-
requestEnable(): Promise<void>;
|
|
318
|
-
enable(): Promise<void>;
|
|
319
|
-
disable(): Promise<void>;
|
|
320
|
-
startEnabledNotifications(): Promise<void>;
|
|
321
|
-
stopEnabledNotifications(): Promise<void>;
|
|
322
|
-
isLocationEnabled(): Promise<BooleanResult>;
|
|
323
|
-
openLocationSettings(): Promise<void>;
|
|
324
|
-
openBluetoothSettings(): Promise<void>;
|
|
325
|
-
openAppSettings(): Promise<void>;
|
|
326
|
-
setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;
|
|
327
|
-
requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;
|
|
328
|
-
requestLEScan(options?: RequestBleDeviceOptions): Promise<void>;
|
|
329
|
-
stopLEScan(): Promise<void>;
|
|
330
|
-
getDevices(options: GetDevicesOptions): Promise<GetDevicesResult>;
|
|
331
|
-
getConnectedDevices(options: GetConnectedDevicesOptions): Promise<GetDevicesResult>;
|
|
332
|
-
getBondedDevices(): Promise<GetDevicesResult>;
|
|
333
|
-
addListener(eventName: 'onEnabledChanged', listenerFunc: (result: BooleanResult) => void): Promise<PluginListenerHandle>;
|
|
334
|
-
addListener(eventName: string, listenerFunc: (event: ReadResult) => void): Promise<PluginListenerHandle>;
|
|
335
|
-
addListener(eventName: 'onScanResult', listenerFunc: (result: ScanResultInternal) => void): Promise<PluginListenerHandle>;
|
|
336
|
-
connect(options: DeviceIdOptions & TimeoutOptions): Promise<void>;
|
|
337
|
-
createBond(options: DeviceIdOptions & TimeoutOptions): Promise<void>;
|
|
338
|
-
isBonded(options: DeviceIdOptions): Promise<BooleanResult>;
|
|
339
|
-
disconnect(options: DeviceIdOptions): Promise<void>;
|
|
340
|
-
getServices(options: DeviceIdOptions): Promise<BleServices>;
|
|
341
|
-
discoverServices(options: DeviceIdOptions): Promise<void>;
|
|
342
|
-
getMtu(options: DeviceIdOptions): Promise<GetMtuResult>;
|
|
343
|
-
requestConnectionPriority(options: RequestConnectionPriorityOptions): Promise<void>;
|
|
344
|
-
readRssi(options: DeviceIdOptions): Promise<ReadRssiResult>;
|
|
345
|
-
read(options: ReadOptions & TimeoutOptions): Promise<ReadResult>;
|
|
346
|
-
write(options: WriteOptions & TimeoutOptions): Promise<void>;
|
|
347
|
-
writeWithoutResponse(options: WriteOptions & TimeoutOptions): Promise<void>;
|
|
348
|
-
readDescriptor(options: ReadDescriptorOptions & TimeoutOptions): Promise<ReadResult>;
|
|
349
|
-
writeDescriptor(options: WriteDescriptorOptions & TimeoutOptions): Promise<void>;
|
|
350
|
-
startNotifications(options: ReadOptions & TimeoutOptions): Promise<void>;
|
|
351
|
-
stopNotifications(options: ReadOptions): Promise<void>;
|
|
352
|
-
}
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
import type { DisplayStrings } from './config';
|
|
3
|
+
export interface InitializeOptions {
|
|
4
|
+
/**
|
|
5
|
+
* If your app doesn't use Bluetooth scan results to derive physical
|
|
6
|
+
* location information, you can strongly assert that your app
|
|
7
|
+
* doesn't derive physical location. (Android only)
|
|
8
|
+
* Requires adding 'neverForLocation' to AndroidManifest.xml
|
|
9
|
+
* https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
androidNeverForLocation?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface RequestBleDeviceOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Filter devices by service UUIDs.
|
|
17
|
+
* UUIDs have to be specified as 128 bit UUID strings,
|
|
18
|
+
* e.g. ['0000180d-0000-1000-8000-00805f9b34fb']
|
|
19
|
+
* There is a helper function to convert numbers to UUIDs.
|
|
20
|
+
* e.g. [numberToUUID(0x180f)]. (see [UUID format](#uuid-format))
|
|
21
|
+
*/
|
|
22
|
+
services?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Filter devices by name
|
|
25
|
+
*/
|
|
26
|
+
name?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Filter devices by name prefix
|
|
29
|
+
*/
|
|
30
|
+
namePrefix?: string;
|
|
31
|
+
/**
|
|
32
|
+
* For **web**, all services that will be used have to be listed under services or optionalServices,
|
|
33
|
+
* e.g. [numberToUUID(0x180f)] (see [UUID format](#uuid-format))
|
|
34
|
+
*/
|
|
35
|
+
optionalServices?: string[];
|
|
36
|
+
/**
|
|
37
|
+
* Normally scans will discard the second and subsequent advertisements from a single device.
|
|
38
|
+
* If you need to receive them, set allowDuplicates to true (only applicable in `requestLEScan`).
|
|
39
|
+
* (default: false)
|
|
40
|
+
*/
|
|
41
|
+
allowDuplicates?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Android scan mode (default: ScanMode.SCAN_MODE_BALANCED)
|
|
44
|
+
*/
|
|
45
|
+
scanMode?: ScanMode;
|
|
46
|
+
/**
|
|
47
|
+
* Allow scanning for devices with a specific manufacturer data
|
|
48
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice#manufacturerdata
|
|
49
|
+
*/
|
|
50
|
+
manufacturerData?: ManufacturerDataFilter[];
|
|
51
|
+
/**
|
|
52
|
+
* Display mode for the device list in `requestDevice` (**iOS** only).
|
|
53
|
+
* - `"alert"`: Classic alert dialog (default)
|
|
54
|
+
* - `"list"`: Scrollable list view
|
|
55
|
+
* @default "alert"
|
|
56
|
+
*/
|
|
57
|
+
displayMode?: 'alert' | 'list';
|
|
58
|
+
/**
|
|
59
|
+
* Allow scanning for devices with specific service data.
|
|
60
|
+
* Service data is data associated with a specific service UUID in the advertisement packet.
|
|
61
|
+
* Useful for protocols like OpenDroneID, EddyStone, and Open Beacon.
|
|
62
|
+
*/
|
|
63
|
+
serviceData?: ServiceDataFilter[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Android scan mode
|
|
67
|
+
*/
|
|
68
|
+
export declare enum ScanMode {
|
|
69
|
+
/**
|
|
70
|
+
* Perform Bluetooth LE scan in low power mode. This mode is enforced if the scanning application is not in foreground.
|
|
71
|
+
* https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_POWER
|
|
72
|
+
*/
|
|
73
|
+
SCAN_MODE_LOW_POWER = 0,
|
|
74
|
+
/**
|
|
75
|
+
* Perform Bluetooth LE scan in balanced power mode. (default) Scan results are returned at a rate that provides a good trade-off between scan frequency and power consumption.
|
|
76
|
+
* https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_BALANCED
|
|
77
|
+
*/
|
|
78
|
+
SCAN_MODE_BALANCED = 1,
|
|
79
|
+
/**
|
|
80
|
+
* Scan using highest duty cycle. It's recommended to only use this mode when the application is running in the foreground.
|
|
81
|
+
* https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_LATENCY
|
|
82
|
+
*/
|
|
83
|
+
SCAN_MODE_LOW_LATENCY = 2
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Android connection priority used in `requestConnectionPriority`
|
|
87
|
+
*/
|
|
88
|
+
export declare enum ConnectionPriority {
|
|
89
|
+
/**
|
|
90
|
+
* Use the connection parameters recommended by the Bluetooth SIG. This is the default value if no connection parameter update is requested.
|
|
91
|
+
* https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_BALANCED
|
|
92
|
+
*/
|
|
93
|
+
CONNECTION_PRIORITY_BALANCED = 0,
|
|
94
|
+
/**
|
|
95
|
+
* Request a high priority, low latency connection. An application should only request high priority connection parameters to transfer large amounts of data over LE quickly. Once the transfer is complete, the application should request CONNECTION_PRIORITY_BALANCED connection parameters to reduce energy use.
|
|
96
|
+
* https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_HIGH
|
|
97
|
+
*/
|
|
98
|
+
CONNECTION_PRIORITY_HIGH = 1,
|
|
99
|
+
/**
|
|
100
|
+
* Request low power, reduced data rate connection parameters.
|
|
101
|
+
* https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER
|
|
102
|
+
*/
|
|
103
|
+
CONNECTION_PRIORITY_LOW_POWER = 2
|
|
104
|
+
}
|
|
105
|
+
export interface ManufacturerDataFilter {
|
|
106
|
+
/**
|
|
107
|
+
* Company ID (sometimes called the manufacturer ID) to search for in the manufacturer data field.
|
|
108
|
+
*/
|
|
109
|
+
companyIdentifier: number;
|
|
110
|
+
/**
|
|
111
|
+
* Prefix to match in the manufacturer data field.
|
|
112
|
+
* On **Android** this field is mandatory.
|
|
113
|
+
* android, ios: DataView
|
|
114
|
+
* web: Uint8Array
|
|
115
|
+
*/
|
|
116
|
+
dataPrefix?: DataView | Uint8Array;
|
|
117
|
+
/**
|
|
118
|
+
* Set filter on partial manufacture data. For any bit in the mask, set it the 1 if it needs to match the one in manufacturer data, otherwise set it to 0.
|
|
119
|
+
* The `mask` must have the same length of dataPrefix.
|
|
120
|
+
* android, ios: DataView
|
|
121
|
+
* web: Uint8Array
|
|
122
|
+
*/
|
|
123
|
+
mask?: DataView | Uint8Array;
|
|
124
|
+
}
|
|
125
|
+
export interface ServiceDataFilter {
|
|
126
|
+
/**
|
|
127
|
+
* Service UUID to filter by. The service data must be associated with this UUID.
|
|
128
|
+
* UUIDs have to be specified as 128 bit UUID strings,
|
|
129
|
+
* e.g. '0000fffa-0000-1000-8000-00805f9b34fb'
|
|
130
|
+
*/
|
|
131
|
+
serviceUuid: string;
|
|
132
|
+
/**
|
|
133
|
+
* Prefix to match in the service data field.
|
|
134
|
+
* For example, OpenDroneID uses [0x0D] as the advertisement code.
|
|
135
|
+
* android, ios: string
|
|
136
|
+
* web: DataView
|
|
137
|
+
*/
|
|
138
|
+
dataPrefix?: DataView;
|
|
139
|
+
/**
|
|
140
|
+
* Set filter on partial service data. For any bit in the mask, set it to 1 if it needs to match the one in service data, otherwise set it to 0.
|
|
141
|
+
* The `mask` must have the same length as dataPrefix.
|
|
142
|
+
* android, ios: string
|
|
143
|
+
* web: DataView
|
|
144
|
+
*/
|
|
145
|
+
mask?: DataView;
|
|
146
|
+
}
|
|
147
|
+
export interface BleDevice {
|
|
148
|
+
/**
|
|
149
|
+
* ID of the device, which will be needed for further calls.
|
|
150
|
+
* On **Android** this is the BLE MAC address.
|
|
151
|
+
* On **iOS** and **web** it is an identifier.
|
|
152
|
+
*/
|
|
153
|
+
deviceId: string;
|
|
154
|
+
/**
|
|
155
|
+
* Name of the peripheral device.
|
|
156
|
+
*/
|
|
157
|
+
name?: string;
|
|
158
|
+
uuids?: string[];
|
|
159
|
+
}
|
|
160
|
+
export interface DeviceIdOptions {
|
|
161
|
+
deviceId: string;
|
|
162
|
+
}
|
|
163
|
+
export interface TimeoutOptions {
|
|
164
|
+
/**
|
|
165
|
+
* Timeout in milliseconds for plugin call.
|
|
166
|
+
* Default is 10000 for `connect` and 5000 for other plugin methods.
|
|
167
|
+
*/
|
|
168
|
+
timeout?: number;
|
|
169
|
+
}
|
|
170
|
+
export interface RequestConnectionPriorityOptions extends DeviceIdOptions {
|
|
171
|
+
connectionPriority: ConnectionPriority;
|
|
172
|
+
}
|
|
173
|
+
export interface GetDevicesOptions {
|
|
174
|
+
deviceIds: string[];
|
|
175
|
+
}
|
|
176
|
+
export interface GetConnectedDevicesOptions {
|
|
177
|
+
services: string[];
|
|
178
|
+
}
|
|
179
|
+
export interface BleService {
|
|
180
|
+
readonly uuid: string;
|
|
181
|
+
readonly characteristics: BleCharacteristic[];
|
|
182
|
+
}
|
|
183
|
+
export interface BleDescriptor {
|
|
184
|
+
readonly uuid: string;
|
|
185
|
+
}
|
|
186
|
+
export interface BleCharacteristic {
|
|
187
|
+
readonly uuid: string;
|
|
188
|
+
readonly properties: BleCharacteristicProperties;
|
|
189
|
+
readonly descriptors: BleDescriptor[];
|
|
190
|
+
}
|
|
191
|
+
export interface BleCharacteristicProperties {
|
|
192
|
+
readonly broadcast: boolean;
|
|
193
|
+
readonly read: boolean;
|
|
194
|
+
readonly writeWithoutResponse: boolean;
|
|
195
|
+
readonly write: boolean;
|
|
196
|
+
readonly notify: boolean;
|
|
197
|
+
readonly indicate: boolean;
|
|
198
|
+
readonly authenticatedSignedWrites: boolean;
|
|
199
|
+
readonly reliableWrite?: boolean;
|
|
200
|
+
readonly writableAuxiliaries?: boolean;
|
|
201
|
+
readonly extendedProperties?: boolean;
|
|
202
|
+
readonly notifyEncryptionRequired?: boolean;
|
|
203
|
+
readonly indicateEncryptionRequired?: boolean;
|
|
204
|
+
}
|
|
205
|
+
export interface BleServices {
|
|
206
|
+
services: BleService[];
|
|
207
|
+
}
|
|
208
|
+
export interface ReadOptions {
|
|
209
|
+
deviceId: string;
|
|
210
|
+
service: string;
|
|
211
|
+
characteristic: string;
|
|
212
|
+
}
|
|
213
|
+
export interface ReadDescriptorOptions {
|
|
214
|
+
deviceId: string;
|
|
215
|
+
service: string;
|
|
216
|
+
characteristic: string;
|
|
217
|
+
descriptor: string;
|
|
218
|
+
}
|
|
219
|
+
export type Data = DataView | string;
|
|
220
|
+
export interface WriteOptions {
|
|
221
|
+
deviceId: string;
|
|
222
|
+
service: string;
|
|
223
|
+
characteristic: string;
|
|
224
|
+
/**
|
|
225
|
+
* android, ios: string
|
|
226
|
+
* web: DataView
|
|
227
|
+
*/
|
|
228
|
+
value: Data;
|
|
229
|
+
}
|
|
230
|
+
export interface WriteDescriptorOptions {
|
|
231
|
+
deviceId: string;
|
|
232
|
+
service: string;
|
|
233
|
+
characteristic: string;
|
|
234
|
+
descriptor: string;
|
|
235
|
+
/**
|
|
236
|
+
* android, ios: string
|
|
237
|
+
* web: DataView
|
|
238
|
+
*/
|
|
239
|
+
value: Data;
|
|
240
|
+
}
|
|
241
|
+
export interface BooleanResult {
|
|
242
|
+
value: boolean;
|
|
243
|
+
}
|
|
244
|
+
export interface GetDevicesResult {
|
|
245
|
+
devices: BleDevice[];
|
|
246
|
+
}
|
|
247
|
+
export interface GetMtuResult {
|
|
248
|
+
value: number;
|
|
249
|
+
}
|
|
250
|
+
export interface ReadRssiResult {
|
|
251
|
+
value: string;
|
|
252
|
+
}
|
|
253
|
+
export interface ReadResult {
|
|
254
|
+
/**
|
|
255
|
+
* android, ios: string
|
|
256
|
+
* web: DataView
|
|
257
|
+
*/
|
|
258
|
+
value?: Data;
|
|
259
|
+
}
|
|
260
|
+
export interface ScanResultInternal<T = Data> {
|
|
261
|
+
device: BleDevice;
|
|
262
|
+
localName?: string;
|
|
263
|
+
rssi?: number;
|
|
264
|
+
txPower?: number;
|
|
265
|
+
manufacturerData?: {
|
|
266
|
+
[key: string]: T;
|
|
267
|
+
};
|
|
268
|
+
serviceData?: {
|
|
269
|
+
[key: string]: T;
|
|
270
|
+
};
|
|
271
|
+
uuids?: string[];
|
|
272
|
+
rawAdvertisement?: T;
|
|
273
|
+
}
|
|
274
|
+
export interface ScanResult {
|
|
275
|
+
/**
|
|
276
|
+
* The peripheral device that was found in the scan.
|
|
277
|
+
* **Android** and **web**: `device.name` is always identical to `localName`.
|
|
278
|
+
* **iOS**: `device.name` is identical to `localName` the first time a device is discovered, but after connecting `device.name` is the cached GAP name in subsequent scans.
|
|
279
|
+
*/
|
|
280
|
+
device: BleDevice;
|
|
281
|
+
/**
|
|
282
|
+
* The name of the peripheral device from the advertisement data.
|
|
283
|
+
*/
|
|
284
|
+
localName?: string;
|
|
285
|
+
/**
|
|
286
|
+
* Received Signal Strength Indication.
|
|
287
|
+
*/
|
|
288
|
+
rssi?: number;
|
|
289
|
+
/**
|
|
290
|
+
* Transmit power in dBm. A value of 127 indicates that it is not available.
|
|
291
|
+
*/
|
|
292
|
+
txPower?: number;
|
|
293
|
+
/**
|
|
294
|
+
* Manufacturer data, key is a company identifier and value is the data.
|
|
295
|
+
*/
|
|
296
|
+
manufacturerData?: {
|
|
297
|
+
[key: string]: DataView;
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* Service data, key is a service UUID and value is the data.
|
|
301
|
+
*/
|
|
302
|
+
serviceData?: {
|
|
303
|
+
[key: string]: DataView;
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Advertised services.
|
|
307
|
+
*/
|
|
308
|
+
uuids?: string[];
|
|
309
|
+
/**
|
|
310
|
+
* Raw advertisement data (**Android** only).
|
|
311
|
+
*/
|
|
312
|
+
rawAdvertisement?: DataView;
|
|
313
|
+
}
|
|
314
|
+
export interface BluetoothLePlugin {
|
|
315
|
+
initialize(options?: InitializeOptions): Promise<void>;
|
|
316
|
+
isEnabled(): Promise<BooleanResult>;
|
|
317
|
+
requestEnable(): Promise<void>;
|
|
318
|
+
enable(): Promise<void>;
|
|
319
|
+
disable(): Promise<void>;
|
|
320
|
+
startEnabledNotifications(): Promise<void>;
|
|
321
|
+
stopEnabledNotifications(): Promise<void>;
|
|
322
|
+
isLocationEnabled(): Promise<BooleanResult>;
|
|
323
|
+
openLocationSettings(): Promise<void>;
|
|
324
|
+
openBluetoothSettings(): Promise<void>;
|
|
325
|
+
openAppSettings(): Promise<void>;
|
|
326
|
+
setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;
|
|
327
|
+
requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;
|
|
328
|
+
requestLEScan(options?: RequestBleDeviceOptions): Promise<void>;
|
|
329
|
+
stopLEScan(): Promise<void>;
|
|
330
|
+
getDevices(options: GetDevicesOptions): Promise<GetDevicesResult>;
|
|
331
|
+
getConnectedDevices(options: GetConnectedDevicesOptions): Promise<GetDevicesResult>;
|
|
332
|
+
getBondedDevices(): Promise<GetDevicesResult>;
|
|
333
|
+
addListener(eventName: 'onEnabledChanged', listenerFunc: (result: BooleanResult) => void): Promise<PluginListenerHandle>;
|
|
334
|
+
addListener(eventName: string, listenerFunc: (event: ReadResult) => void): Promise<PluginListenerHandle>;
|
|
335
|
+
addListener(eventName: 'onScanResult', listenerFunc: (result: ScanResultInternal) => void): Promise<PluginListenerHandle>;
|
|
336
|
+
connect(options: DeviceIdOptions & TimeoutOptions): Promise<void>;
|
|
337
|
+
createBond(options: DeviceIdOptions & TimeoutOptions): Promise<void>;
|
|
338
|
+
isBonded(options: DeviceIdOptions): Promise<BooleanResult>;
|
|
339
|
+
disconnect(options: DeviceIdOptions): Promise<void>;
|
|
340
|
+
getServices(options: DeviceIdOptions): Promise<BleServices>;
|
|
341
|
+
discoverServices(options: DeviceIdOptions): Promise<void>;
|
|
342
|
+
getMtu(options: DeviceIdOptions): Promise<GetMtuResult>;
|
|
343
|
+
requestConnectionPriority(options: RequestConnectionPriorityOptions): Promise<void>;
|
|
344
|
+
readRssi(options: DeviceIdOptions): Promise<ReadRssiResult>;
|
|
345
|
+
read(options: ReadOptions & TimeoutOptions): Promise<ReadResult>;
|
|
346
|
+
write(options: WriteOptions & TimeoutOptions): Promise<void>;
|
|
347
|
+
writeWithoutResponse(options: WriteOptions & TimeoutOptions): Promise<void>;
|
|
348
|
+
readDescriptor(options: ReadDescriptorOptions & TimeoutOptions): Promise<ReadResult>;
|
|
349
|
+
writeDescriptor(options: WriteDescriptorOptions & TimeoutOptions): Promise<void>;
|
|
350
|
+
startNotifications(options: ReadOptions & TimeoutOptions): Promise<void>;
|
|
351
|
+
stopNotifications(options: ReadOptions): Promise<void>;
|
|
352
|
+
}
|