@capacitor-community/bluetooth-le 7.0.0 → 7.1.1
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 +17 -17
- package/LICENSE +21 -21
- package/README.md +94 -16
- package/android/build.gradle +68 -68
- package/android/src/main/AndroidManifest.xml +22 -22
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/BluetoothLe.kt +1068 -1009
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/Conversion.kt +51 -51
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/Device.kt +720 -718
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/DeviceList.kt +28 -28
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/DeviceScanner.kt +189 -189
- package/dist/docs.json +926 -78
- package/dist/esm/bleClient.d.ts +277 -277
- package/dist/esm/bleClient.js +349 -349
- 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/config.js.map +1 -1
- package/dist/esm/conversion.d.ts +34 -34
- package/dist/esm/conversion.js +84 -84
- package/dist/esm/conversion.js.map +1 -1
- package/dist/esm/definitions.d.ts +313 -292
- package/dist/esm/definitions.js +42 -42
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +5 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/plugin.d.ts +2 -2
- package/dist/esm/plugin.js +4 -4
- package/dist/esm/plugin.js.map +1 -1
- 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/timeout.js.map +1 -1
- 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 +56 -56
- package/dist/esm/web.js +340 -335
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +839 -834
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +839 -834
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Conversion.swift +83 -83
- package/ios/Plugin/Device.swift +423 -423
- package/ios/Plugin/DeviceManager.swift +401 -349
- package/ios/Plugin/Info.plist +24 -24
- package/ios/Plugin/Logging.swift +8 -8
- package/ios/Plugin/Plugin.h +10 -10
- package/ios/Plugin/Plugin.m +41 -41
- package/ios/Plugin/Plugin.swift +682 -636
- package/ios/Plugin/ThreadSafeDictionary.swift +13 -13
- package/package.json +101 -101
package/dist/esm/bleClient.d.ts
CHANGED
|
@@ -1,277 +1,277 @@
|
|
|
1
|
-
import type { DisplayStrings } from './config';
|
|
2
|
-
import type { BleDevice, BleService, ConnectionPriority, InitializeOptions, RequestBleDeviceOptions, ScanResult, TimeoutOptions } from './definitions';
|
|
3
|
-
export interface BleClientInterface {
|
|
4
|
-
/**
|
|
5
|
-
* Initialize Bluetooth Low Energy (BLE). If it fails, BLE might be unavailable on this device.
|
|
6
|
-
* On **Android** it will ask for the location permission. On **iOS** it will ask for the Bluetooth permission.
|
|
7
|
-
* For an example, see [usage](#usage).
|
|
8
|
-
*/
|
|
9
|
-
initialize(options?: InitializeOptions): Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
* Reports whether Bluetooth is enabled on this device.
|
|
12
|
-
* Always returns `true` on **web**.
|
|
13
|
-
*/
|
|
14
|
-
isEnabled(): Promise<boolean>;
|
|
15
|
-
/**
|
|
16
|
-
* Request enabling Bluetooth. Show a system activity that allows the user to turn on Bluetooth. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#ACTION_REQUEST_ENABLE
|
|
17
|
-
* Only available on **Android**.*/
|
|
18
|
-
requestEnable(): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Enable Bluetooth.
|
|
21
|
-
* Only available on **Android**.
|
|
22
|
-
* **Deprecated** Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()
|
|
23
|
-
* @deprecated Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()
|
|
24
|
-
*/
|
|
25
|
-
enable(): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Disable Bluetooth.
|
|
28
|
-
* Only available on **Android**.
|
|
29
|
-
* **Deprecated** Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()
|
|
30
|
-
* @deprecated Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()
|
|
31
|
-
*/
|
|
32
|
-
disable(): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Register a callback function that will be invoked when Bluetooth is enabled (true) or disabled (false) on this device.
|
|
35
|
-
* Not available on **web** (the callback will never be invoked).
|
|
36
|
-
* @param callback Callback function to use when the Bluetooth state changes.
|
|
37
|
-
*/
|
|
38
|
-
startEnabledNotifications(callback: (value: boolean) => void): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Stop the enabled notifications registered with `startEnabledNotifications`.
|
|
41
|
-
*/
|
|
42
|
-
stopEnabledNotifications(): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Reports whether Location Services are enabled on this device.
|
|
45
|
-
* Only available on **Android**.
|
|
46
|
-
*/
|
|
47
|
-
isLocationEnabled(): Promise<boolean>;
|
|
48
|
-
/**
|
|
49
|
-
* Open Location settings.
|
|
50
|
-
* Only available on **Android**.
|
|
51
|
-
*/
|
|
52
|
-
openLocationSettings(): Promise<void>;
|
|
53
|
-
/**
|
|
54
|
-
* Open Bluetooth settings.
|
|
55
|
-
* Only available on **Android**.
|
|
56
|
-
*/
|
|
57
|
-
openBluetoothSettings(): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* Open App settings.
|
|
60
|
-
* Not available on **web**.
|
|
61
|
-
* On **iOS** when a user declines the request to use Bluetooth on the first call of `initialize`, it is not possible
|
|
62
|
-
* to request for Bluetooth again from within the app. In this case Bluetooth has to be enabled in the app settings
|
|
63
|
-
* for the app to be able use it.
|
|
64
|
-
*/
|
|
65
|
-
openAppSettings(): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* Set the strings that are displayed in the `requestDevice` dialog.
|
|
68
|
-
* @param displayStrings
|
|
69
|
-
*/
|
|
70
|
-
setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* Request a peripheral BLE device to interact with. This will scan for available devices according to the filters in the options and show a dialog to pick a device.
|
|
73
|
-
* For an example, see [usage](#usage).
|
|
74
|
-
* @param options Device filters, see [RequestBleDeviceOptions](#RequestBleDeviceOptions)
|
|
75
|
-
*/
|
|
76
|
-
requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;
|
|
77
|
-
/**
|
|
78
|
-
* Start scanning for BLE devices to interact with according to the filters in the options. The callback will be invoked on each device that is found.
|
|
79
|
-
* Scanning will continue until `stopLEScan` is called. For an example, see [usage](#usage).
|
|
80
|
-
* **Note**: Use with care on **web** platform, the required API is still behind a flag in most browsers.
|
|
81
|
-
* @param options
|
|
82
|
-
* @param callback
|
|
83
|
-
*/
|
|
84
|
-
requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Stop scanning for BLE devices. For an example, see [usage](#usage).
|
|
87
|
-
*/
|
|
88
|
-
stopLEScan(): Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* On iOS and web, if you want to connect to a previously connected device without scanning first, you can use `getDevice`.
|
|
91
|
-
* Uses [retrievePeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1519127-retrieveperipherals) on iOS and
|
|
92
|
-
* [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.
|
|
93
|
-
* On Android, you can directly connect to the device with the deviceId.
|
|
94
|
-
* @param deviceIds List of device IDs, e.g. saved from a previous app run.
|
|
95
|
-
*/
|
|
96
|
-
getDevices(deviceIds: string[]): Promise<BleDevice[]>;
|
|
97
|
-
/**
|
|
98
|
-
* Get a list of currently bonded devices.
|
|
99
|
-
* Only available on **Android**.
|
|
100
|
-
* Uses [getBondedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getBondedDevices()) on Android
|
|
101
|
-
*/
|
|
102
|
-
getBondedDevices(): Promise<BleDevice[]>;
|
|
103
|
-
/**
|
|
104
|
-
* Get a list of currently connected devices.
|
|
105
|
-
* Uses [retrieveConnectedPeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals) on iOS,
|
|
106
|
-
* [getConnectedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getConnectedDevices(int)) on Android
|
|
107
|
-
* and [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.
|
|
108
|
-
* @param services List of services to filter the devices by. If no service is specified, no devices will be returned. Only applies to iOS.
|
|
109
|
-
*/
|
|
110
|
-
getConnectedDevices(services: string[]): Promise<BleDevice[]>;
|
|
111
|
-
/**
|
|
112
|
-
* Connect to a peripheral BLE device. For an example, see [usage](#usage).
|
|
113
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
114
|
-
* @param onDisconnect Optional disconnect callback function that will be used when the device disconnects
|
|
115
|
-
* @param options Options for plugin call
|
|
116
|
-
*/
|
|
117
|
-
connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void>;
|
|
118
|
-
/**
|
|
119
|
-
* Create a bond with a peripheral BLE device.
|
|
120
|
-
* Only available on **Android**. On iOS bonding is handled by the OS.
|
|
121
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
122
|
-
* @param options Options for plugin call
|
|
123
|
-
*/
|
|
124
|
-
createBond(deviceId: string, options?: TimeoutOptions): Promise<void>;
|
|
125
|
-
/**
|
|
126
|
-
* Report whether a peripheral BLE device is bonded.
|
|
127
|
-
* Only available on **Android**. On iOS bonding is handled by the OS.
|
|
128
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
129
|
-
*/
|
|
130
|
-
isBonded(deviceId: string): Promise<boolean>;
|
|
131
|
-
/**
|
|
132
|
-
* Disconnect from a peripheral BLE device. For an example, see [usage](#usage).
|
|
133
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
134
|
-
*/
|
|
135
|
-
disconnect(deviceId: string): Promise<void>;
|
|
136
|
-
/**
|
|
137
|
-
* Get services, characteristics and descriptors of a device.
|
|
138
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
139
|
-
*/
|
|
140
|
-
getServices(deviceId: string): Promise<BleService[]>;
|
|
141
|
-
/**
|
|
142
|
-
* Discover services, characteristics and descriptors of a device.
|
|
143
|
-
* You only need this method if your peripheral device changes its services and characteristics at runtime.
|
|
144
|
-
* If the discovery was successful, the remote services can be retrieved using the getServices function.
|
|
145
|
-
* Not available on **web**.
|
|
146
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
147
|
-
*/
|
|
148
|
-
discoverServices(deviceId: string): Promise<void>;
|
|
149
|
-
/**
|
|
150
|
-
* Get the MTU of a connected device. Note that the maximum write value length is 3 bytes less than the MTU.
|
|
151
|
-
* Not available on **web**.
|
|
152
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
153
|
-
*/
|
|
154
|
-
getMtu(deviceId: string): Promise<number>;
|
|
155
|
-
/**
|
|
156
|
-
* Request a connection parameter update.
|
|
157
|
-
* Only available on **Android**. https://developer.android.com/reference/android/bluetooth/BluetoothGatt#requestConnectionPriority(int)
|
|
158
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
159
|
-
* @param connectionPriority Request a specific connection priority. See [ConnectionPriority](#connectionpriority)
|
|
160
|
-
*/
|
|
161
|
-
requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void>;
|
|
162
|
-
/**
|
|
163
|
-
* Read the RSSI value of a connected device.
|
|
164
|
-
* Not available on **web**.
|
|
165
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
166
|
-
*/
|
|
167
|
-
readRssi(deviceId: string): Promise<number>;
|
|
168
|
-
/**
|
|
169
|
-
* Read the value of a characteristic. For an example, see [usage](#usage).
|
|
170
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
171
|
-
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
172
|
-
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
173
|
-
* @param options Options for plugin call
|
|
174
|
-
*/
|
|
175
|
-
read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView>;
|
|
176
|
-
/**
|
|
177
|
-
* Write a value to a characteristic. For an example, see [usage](#usage).
|
|
178
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
179
|
-
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
180
|
-
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
181
|
-
* @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])
|
|
182
|
-
* @param options Options for plugin call
|
|
183
|
-
*/
|
|
184
|
-
write(deviceId: string, service: string, characteristic: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
185
|
-
/**
|
|
186
|
-
* Write a value to a characteristic without waiting for a response.
|
|
187
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
188
|
-
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
189
|
-
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
190
|
-
* @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])
|
|
191
|
-
* @param options Options for plugin call
|
|
192
|
-
*/
|
|
193
|
-
writeWithoutResponse(deviceId: string, service: string, characteristic: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
194
|
-
/**
|
|
195
|
-
* Read the value of a descriptor.
|
|
196
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
197
|
-
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
198
|
-
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
199
|
-
* @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))
|
|
200
|
-
* @param options Options for plugin call
|
|
201
|
-
*/
|
|
202
|
-
readDescriptor(deviceId: string, service: string, characteristic: string, descriptor: string, options?: TimeoutOptions): Promise<DataView>;
|
|
203
|
-
/**
|
|
204
|
-
* Write a value to a descriptor.
|
|
205
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
206
|
-
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
207
|
-
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
208
|
-
* @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))
|
|
209
|
-
* @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])
|
|
210
|
-
* @param options Options for plugin call
|
|
211
|
-
*/
|
|
212
|
-
writeDescriptor(deviceId: string, service: string, characteristic: string, descriptor: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
213
|
-
/**
|
|
214
|
-
* Start listening to changes of the value of a characteristic.
|
|
215
|
-
* Note that you should only start the notifications once per characteristic in your app and share the data and
|
|
216
|
-
* not call `startNotifications` in every component that needs the data.
|
|
217
|
-
* For an example, see [usage](#usage).
|
|
218
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
219
|
-
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
220
|
-
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
221
|
-
* @param callback Callback function to use when the value of the characteristic changes
|
|
222
|
-
*/
|
|
223
|
-
startNotifications(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void): Promise<void>;
|
|
224
|
-
/**
|
|
225
|
-
* Stop listening to the changes of the value of a characteristic. For an example, see [usage](#usage).
|
|
226
|
-
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
227
|
-
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
228
|
-
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
229
|
-
*/
|
|
230
|
-
stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void>;
|
|
231
|
-
}
|
|
232
|
-
declare class BleClientClass implements BleClientInterface {
|
|
233
|
-
private scanListener;
|
|
234
|
-
private eventListeners;
|
|
235
|
-
private queue;
|
|
236
|
-
enableQueue(): void;
|
|
237
|
-
disableQueue(): void;
|
|
238
|
-
initialize(options?: InitializeOptions): Promise<void>;
|
|
239
|
-
isEnabled(): Promise<boolean>;
|
|
240
|
-
requestEnable(): Promise<void>;
|
|
241
|
-
enable(): Promise<void>;
|
|
242
|
-
disable(): Promise<void>;
|
|
243
|
-
startEnabledNotifications(callback: (value: boolean) => void): Promise<void>;
|
|
244
|
-
stopEnabledNotifications(): Promise<void>;
|
|
245
|
-
isLocationEnabled(): Promise<boolean>;
|
|
246
|
-
openLocationSettings(): Promise<void>;
|
|
247
|
-
openBluetoothSettings(): Promise<void>;
|
|
248
|
-
openAppSettings(): Promise<void>;
|
|
249
|
-
setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;
|
|
250
|
-
requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;
|
|
251
|
-
requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void>;
|
|
252
|
-
stopLEScan(): Promise<void>;
|
|
253
|
-
getDevices(deviceIds: string[]): Promise<BleDevice[]>;
|
|
254
|
-
getConnectedDevices(services: string[]): Promise<BleDevice[]>;
|
|
255
|
-
getBondedDevices(): Promise<BleDevice[]>;
|
|
256
|
-
connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void>;
|
|
257
|
-
createBond(deviceId: string, options?: TimeoutOptions): Promise<void>;
|
|
258
|
-
isBonded(deviceId: string): Promise<boolean>;
|
|
259
|
-
disconnect(deviceId: string): Promise<void>;
|
|
260
|
-
getServices(deviceId: string): Promise<BleService[]>;
|
|
261
|
-
discoverServices(deviceId: string): Promise<void>;
|
|
262
|
-
getMtu(deviceId: string): Promise<number>;
|
|
263
|
-
requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void>;
|
|
264
|
-
readRssi(deviceId: string): Promise<number>;
|
|
265
|
-
read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView>;
|
|
266
|
-
write(deviceId: string, service: string, characteristic: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
267
|
-
writeWithoutResponse(deviceId: string, service: string, characteristic: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
268
|
-
readDescriptor(deviceId: string, service: string, characteristic: string, descriptor: string, options?: TimeoutOptions): Promise<DataView>;
|
|
269
|
-
writeDescriptor(deviceId: string, service: string, characteristic: string, descriptor: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
270
|
-
startNotifications(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void): Promise<void>;
|
|
271
|
-
stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void>;
|
|
272
|
-
private validateRequestBleDeviceOptions;
|
|
273
|
-
private convertValue;
|
|
274
|
-
private convertObject;
|
|
275
|
-
}
|
|
276
|
-
export declare const BleClient: BleClientClass;
|
|
277
|
-
export {};
|
|
1
|
+
import type { DisplayStrings } from './config';
|
|
2
|
+
import type { BleDevice, BleService, ConnectionPriority, InitializeOptions, RequestBleDeviceOptions, ScanResult, TimeoutOptions } from './definitions';
|
|
3
|
+
export interface BleClientInterface {
|
|
4
|
+
/**
|
|
5
|
+
* Initialize Bluetooth Low Energy (BLE). If it fails, BLE might be unavailable on this device.
|
|
6
|
+
* On **Android** it will ask for the location permission. On **iOS** it will ask for the Bluetooth permission.
|
|
7
|
+
* For an example, see [usage](#usage).
|
|
8
|
+
*/
|
|
9
|
+
initialize(options?: InitializeOptions): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Reports whether Bluetooth is enabled on this device.
|
|
12
|
+
* Always returns `true` on **web**.
|
|
13
|
+
*/
|
|
14
|
+
isEnabled(): Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Request enabling Bluetooth. Show a system activity that allows the user to turn on Bluetooth. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#ACTION_REQUEST_ENABLE
|
|
17
|
+
* Only available on **Android**.*/
|
|
18
|
+
requestEnable(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Enable Bluetooth.
|
|
21
|
+
* Only available on **Android**.
|
|
22
|
+
* **Deprecated** Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()
|
|
23
|
+
* @deprecated Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()
|
|
24
|
+
*/
|
|
25
|
+
enable(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Disable Bluetooth.
|
|
28
|
+
* Only available on **Android**.
|
|
29
|
+
* **Deprecated** Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()
|
|
30
|
+
* @deprecated Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()
|
|
31
|
+
*/
|
|
32
|
+
disable(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Register a callback function that will be invoked when Bluetooth is enabled (true) or disabled (false) on this device.
|
|
35
|
+
* Not available on **web** (the callback will never be invoked).
|
|
36
|
+
* @param callback Callback function to use when the Bluetooth state changes.
|
|
37
|
+
*/
|
|
38
|
+
startEnabledNotifications(callback: (value: boolean) => void): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Stop the enabled notifications registered with `startEnabledNotifications`.
|
|
41
|
+
*/
|
|
42
|
+
stopEnabledNotifications(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Reports whether Location Services are enabled on this device.
|
|
45
|
+
* Only available on **Android**.
|
|
46
|
+
*/
|
|
47
|
+
isLocationEnabled(): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Open Location settings.
|
|
50
|
+
* Only available on **Android**.
|
|
51
|
+
*/
|
|
52
|
+
openLocationSettings(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Open Bluetooth settings.
|
|
55
|
+
* Only available on **Android**.
|
|
56
|
+
*/
|
|
57
|
+
openBluetoothSettings(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Open App settings.
|
|
60
|
+
* Not available on **web**.
|
|
61
|
+
* On **iOS** when a user declines the request to use Bluetooth on the first call of `initialize`, it is not possible
|
|
62
|
+
* to request for Bluetooth again from within the app. In this case Bluetooth has to be enabled in the app settings
|
|
63
|
+
* for the app to be able use it.
|
|
64
|
+
*/
|
|
65
|
+
openAppSettings(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Set the strings that are displayed in the `requestDevice` dialog.
|
|
68
|
+
* @param displayStrings
|
|
69
|
+
*/
|
|
70
|
+
setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Request a peripheral BLE device to interact with. This will scan for available devices according to the filters in the options and show a dialog to pick a device.
|
|
73
|
+
* For an example, see [usage](#usage).
|
|
74
|
+
* @param options Device filters, see [RequestBleDeviceOptions](#RequestBleDeviceOptions)
|
|
75
|
+
*/
|
|
76
|
+
requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;
|
|
77
|
+
/**
|
|
78
|
+
* Start scanning for BLE devices to interact with according to the filters in the options. The callback will be invoked on each device that is found.
|
|
79
|
+
* Scanning will continue until `stopLEScan` is called. For an example, see [usage](#usage).
|
|
80
|
+
* **Note**: Use with care on **web** platform, the required API is still behind a flag in most browsers.
|
|
81
|
+
* @param options
|
|
82
|
+
* @param callback
|
|
83
|
+
*/
|
|
84
|
+
requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Stop scanning for BLE devices. For an example, see [usage](#usage).
|
|
87
|
+
*/
|
|
88
|
+
stopLEScan(): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* On iOS and web, if you want to connect to a previously connected device without scanning first, you can use `getDevice`.
|
|
91
|
+
* Uses [retrievePeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1519127-retrieveperipherals) on iOS and
|
|
92
|
+
* [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.
|
|
93
|
+
* On Android, you can directly connect to the device with the deviceId.
|
|
94
|
+
* @param deviceIds List of device IDs, e.g. saved from a previous app run.
|
|
95
|
+
*/
|
|
96
|
+
getDevices(deviceIds: string[]): Promise<BleDevice[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Get a list of currently bonded devices.
|
|
99
|
+
* Only available on **Android**.
|
|
100
|
+
* Uses [getBondedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getBondedDevices()) on Android
|
|
101
|
+
*/
|
|
102
|
+
getBondedDevices(): Promise<BleDevice[]>;
|
|
103
|
+
/**
|
|
104
|
+
* Get a list of currently connected devices.
|
|
105
|
+
* Uses [retrieveConnectedPeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals) on iOS,
|
|
106
|
+
* [getConnectedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getConnectedDevices(int)) on Android
|
|
107
|
+
* and [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.
|
|
108
|
+
* @param services List of services to filter the devices by. If no service is specified, no devices will be returned. Only applies to iOS.
|
|
109
|
+
*/
|
|
110
|
+
getConnectedDevices(services: string[]): Promise<BleDevice[]>;
|
|
111
|
+
/**
|
|
112
|
+
* Connect to a peripheral BLE device. For an example, see [usage](#usage).
|
|
113
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
114
|
+
* @param onDisconnect Optional disconnect callback function that will be used when the device disconnects
|
|
115
|
+
* @param options Options for plugin call
|
|
116
|
+
*/
|
|
117
|
+
connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Create a bond with a peripheral BLE device.
|
|
120
|
+
* Only available on **Android**. On iOS bonding is handled by the OS.
|
|
121
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
122
|
+
* @param options Options for plugin call
|
|
123
|
+
*/
|
|
124
|
+
createBond(deviceId: string, options?: TimeoutOptions): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Report whether a peripheral BLE device is bonded.
|
|
127
|
+
* Only available on **Android**. On iOS bonding is handled by the OS.
|
|
128
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
129
|
+
*/
|
|
130
|
+
isBonded(deviceId: string): Promise<boolean>;
|
|
131
|
+
/**
|
|
132
|
+
* Disconnect from a peripheral BLE device. For an example, see [usage](#usage).
|
|
133
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
134
|
+
*/
|
|
135
|
+
disconnect(deviceId: string): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* Get services, characteristics and descriptors of a device.
|
|
138
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
139
|
+
*/
|
|
140
|
+
getServices(deviceId: string): Promise<BleService[]>;
|
|
141
|
+
/**
|
|
142
|
+
* Discover services, characteristics and descriptors of a device.
|
|
143
|
+
* You only need this method if your peripheral device changes its services and characteristics at runtime.
|
|
144
|
+
* If the discovery was successful, the remote services can be retrieved using the getServices function.
|
|
145
|
+
* Not available on **web**.
|
|
146
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
147
|
+
*/
|
|
148
|
+
discoverServices(deviceId: string): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Get the MTU of a connected device. Note that the maximum write value length is 3 bytes less than the MTU.
|
|
151
|
+
* Not available on **web**.
|
|
152
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
153
|
+
*/
|
|
154
|
+
getMtu(deviceId: string): Promise<number>;
|
|
155
|
+
/**
|
|
156
|
+
* Request a connection parameter update.
|
|
157
|
+
* Only available on **Android**. https://developer.android.com/reference/android/bluetooth/BluetoothGatt#requestConnectionPriority(int)
|
|
158
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
159
|
+
* @param connectionPriority Request a specific connection priority. See [ConnectionPriority](#connectionpriority)
|
|
160
|
+
*/
|
|
161
|
+
requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Read the RSSI value of a connected device.
|
|
164
|
+
* Not available on **web**.
|
|
165
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
166
|
+
*/
|
|
167
|
+
readRssi(deviceId: string): Promise<number>;
|
|
168
|
+
/**
|
|
169
|
+
* Read the value of a characteristic. For an example, see [usage](#usage).
|
|
170
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
171
|
+
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
172
|
+
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
173
|
+
* @param options Options for plugin call
|
|
174
|
+
*/
|
|
175
|
+
read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView>;
|
|
176
|
+
/**
|
|
177
|
+
* Write a value to a characteristic. For an example, see [usage](#usage).
|
|
178
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
179
|
+
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
180
|
+
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
181
|
+
* @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])
|
|
182
|
+
* @param options Options for plugin call
|
|
183
|
+
*/
|
|
184
|
+
write(deviceId: string, service: string, characteristic: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Write a value to a characteristic without waiting for a response.
|
|
187
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
188
|
+
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
189
|
+
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
190
|
+
* @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])
|
|
191
|
+
* @param options Options for plugin call
|
|
192
|
+
*/
|
|
193
|
+
writeWithoutResponse(deviceId: string, service: string, characteristic: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Read the value of a descriptor.
|
|
196
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
197
|
+
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
198
|
+
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
199
|
+
* @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))
|
|
200
|
+
* @param options Options for plugin call
|
|
201
|
+
*/
|
|
202
|
+
readDescriptor(deviceId: string, service: string, characteristic: string, descriptor: string, options?: TimeoutOptions): Promise<DataView>;
|
|
203
|
+
/**
|
|
204
|
+
* Write a value to a descriptor.
|
|
205
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
206
|
+
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
207
|
+
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
208
|
+
* @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))
|
|
209
|
+
* @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])
|
|
210
|
+
* @param options Options for plugin call
|
|
211
|
+
*/
|
|
212
|
+
writeDescriptor(deviceId: string, service: string, characteristic: string, descriptor: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Start listening to changes of the value of a characteristic.
|
|
215
|
+
* Note that you should only start the notifications once per characteristic in your app and share the data and
|
|
216
|
+
* not call `startNotifications` in every component that needs the data.
|
|
217
|
+
* For an example, see [usage](#usage).
|
|
218
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
219
|
+
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
220
|
+
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
221
|
+
* @param callback Callback function to use when the value of the characteristic changes
|
|
222
|
+
*/
|
|
223
|
+
startNotifications(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Stop listening to the changes of the value of a characteristic. For an example, see [usage](#usage).
|
|
226
|
+
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
227
|
+
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
228
|
+
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
229
|
+
*/
|
|
230
|
+
stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void>;
|
|
231
|
+
}
|
|
232
|
+
declare class BleClientClass implements BleClientInterface {
|
|
233
|
+
private scanListener;
|
|
234
|
+
private eventListeners;
|
|
235
|
+
private queue;
|
|
236
|
+
enableQueue(): void;
|
|
237
|
+
disableQueue(): void;
|
|
238
|
+
initialize(options?: InitializeOptions): Promise<void>;
|
|
239
|
+
isEnabled(): Promise<boolean>;
|
|
240
|
+
requestEnable(): Promise<void>;
|
|
241
|
+
enable(): Promise<void>;
|
|
242
|
+
disable(): Promise<void>;
|
|
243
|
+
startEnabledNotifications(callback: (value: boolean) => void): Promise<void>;
|
|
244
|
+
stopEnabledNotifications(): Promise<void>;
|
|
245
|
+
isLocationEnabled(): Promise<boolean>;
|
|
246
|
+
openLocationSettings(): Promise<void>;
|
|
247
|
+
openBluetoothSettings(): Promise<void>;
|
|
248
|
+
openAppSettings(): Promise<void>;
|
|
249
|
+
setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;
|
|
250
|
+
requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;
|
|
251
|
+
requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void>;
|
|
252
|
+
stopLEScan(): Promise<void>;
|
|
253
|
+
getDevices(deviceIds: string[]): Promise<BleDevice[]>;
|
|
254
|
+
getConnectedDevices(services: string[]): Promise<BleDevice[]>;
|
|
255
|
+
getBondedDevices(): Promise<BleDevice[]>;
|
|
256
|
+
connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void>;
|
|
257
|
+
createBond(deviceId: string, options?: TimeoutOptions): Promise<void>;
|
|
258
|
+
isBonded(deviceId: string): Promise<boolean>;
|
|
259
|
+
disconnect(deviceId: string): Promise<void>;
|
|
260
|
+
getServices(deviceId: string): Promise<BleService[]>;
|
|
261
|
+
discoverServices(deviceId: string): Promise<void>;
|
|
262
|
+
getMtu(deviceId: string): Promise<number>;
|
|
263
|
+
requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void>;
|
|
264
|
+
readRssi(deviceId: string): Promise<number>;
|
|
265
|
+
read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView>;
|
|
266
|
+
write(deviceId: string, service: string, characteristic: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
267
|
+
writeWithoutResponse(deviceId: string, service: string, characteristic: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
268
|
+
readDescriptor(deviceId: string, service: string, characteristic: string, descriptor: string, options?: TimeoutOptions): Promise<DataView>;
|
|
269
|
+
writeDescriptor(deviceId: string, service: string, characteristic: string, descriptor: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
270
|
+
startNotifications(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void): Promise<void>;
|
|
271
|
+
stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void>;
|
|
272
|
+
private validateRequestBleDeviceOptions;
|
|
273
|
+
private convertValue;
|
|
274
|
+
private convertObject;
|
|
275
|
+
}
|
|
276
|
+
export declare const BleClient: BleClientClass;
|
|
277
|
+
export {};
|