@capacitor-community/bluetooth-le 7.2.0 → 8.0.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.
Files changed (55) hide show
  1. package/CapacitorCommunityBluetoothLe.podspec +17 -17
  2. package/LICENSE +21 -21
  3. package/Package.swift +28 -0
  4. package/README.md +68 -161
  5. package/android/build.gradle +71 -68
  6. package/android/src/main/AndroidManifest.xml +22 -22
  7. package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/BluetoothLe.kt +1094 -1070
  8. package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/Conversion.kt +51 -51
  9. package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/Device.kt +771 -767
  10. package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/DeviceList.kt +28 -28
  11. package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/DeviceScanner.kt +189 -189
  12. package/dist/docs.json +906 -849
  13. package/dist/esm/bleClient.d.ts +278 -278
  14. package/dist/esm/bleClient.js +361 -347
  15. package/dist/esm/bleClient.js.map +1 -1
  16. package/dist/esm/config.d.ts +53 -53
  17. package/dist/esm/config.js +2 -2
  18. package/dist/esm/conversion.d.ts +56 -34
  19. package/dist/esm/conversion.js +134 -84
  20. package/dist/esm/conversion.js.map +1 -1
  21. package/dist/esm/definitions.d.ts +352 -313
  22. package/dist/esm/definitions.js +42 -42
  23. package/dist/esm/definitions.js.map +1 -1
  24. package/dist/esm/index.d.ts +5 -5
  25. package/dist/esm/index.js +5 -5
  26. package/dist/esm/plugin.d.ts +2 -2
  27. package/dist/esm/plugin.js +4 -4
  28. package/dist/esm/queue.d.ts +3 -3
  29. package/dist/esm/queue.js +17 -17
  30. package/dist/esm/queue.js.map +1 -1
  31. package/dist/esm/timeout.d.ts +1 -1
  32. package/dist/esm/timeout.js +9 -9
  33. package/dist/esm/validators.d.ts +1 -1
  34. package/dist/esm/validators.js +11 -11
  35. package/dist/esm/validators.js.map +1 -1
  36. package/dist/esm/web.d.ts +57 -56
  37. package/dist/esm/web.js +403 -340
  38. package/dist/esm/web.js.map +1 -1
  39. package/dist/plugin.cjs.js +967 -837
  40. package/dist/plugin.cjs.js.map +1 -1
  41. package/dist/plugin.js +967 -837
  42. package/dist/plugin.js.map +1 -1
  43. package/ios/{Plugin → Sources/BluetoothLe}/Conversion.swift +83 -83
  44. package/ios/{Plugin → Sources/BluetoothLe}/Device.swift +423 -423
  45. package/ios/Sources/BluetoothLe/DeviceListView.swift +121 -0
  46. package/ios/{Plugin → Sources/BluetoothLe}/DeviceManager.swift +503 -401
  47. package/ios/{Plugin → Sources/BluetoothLe}/Logging.swift +8 -8
  48. package/ios/{Plugin → Sources/BluetoothLe}/Plugin.swift +775 -682
  49. package/ios/{Plugin → Sources/BluetoothLe}/ThreadSafeDictionary.swift +15 -13
  50. package/ios/Tests/BluetoothLeTests/ConversionTests.swift +55 -0
  51. package/ios/Tests/BluetoothLeTests/PluginTests.swift +27 -0
  52. package/package.json +115 -101
  53. package/ios/Plugin/Info.plist +0 -24
  54. package/ios/Plugin/Plugin.h +0 -10
  55. package/ios/Plugin/Plugin.m +0 -41
@@ -1,313 +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
- /**
53
- * Android scan mode
54
- */
55
- export declare enum ScanMode {
56
- /**
57
- * Perform Bluetooth LE scan in low power mode. This mode is enforced if the scanning application is not in foreground.
58
- * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_POWER
59
- */
60
- SCAN_MODE_LOW_POWER = 0,
61
- /**
62
- * 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.
63
- * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_BALANCED
64
- */
65
- SCAN_MODE_BALANCED = 1,
66
- /**
67
- * Scan using highest duty cycle. It's recommended to only use this mode when the application is running in the foreground.
68
- * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_LATENCY
69
- */
70
- SCAN_MODE_LOW_LATENCY = 2
71
- }
72
- /**
73
- * Android connection priority used in `requestConnectionPriority`
74
- */
75
- export declare enum ConnectionPriority {
76
- /**
77
- * Use the connection parameters recommended by the Bluetooth SIG. This is the default value if no connection parameter update is requested.
78
- * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_BALANCED
79
- */
80
- CONNECTION_PRIORITY_BALANCED = 0,
81
- /**
82
- * 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.
83
- * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_HIGH
84
- */
85
- CONNECTION_PRIORITY_HIGH = 1,
86
- /**
87
- * Request low power, reduced data rate connection parameters.
88
- * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER
89
- */
90
- CONNECTION_PRIORITY_LOW_POWER = 2
91
- }
92
- export interface ManufacturerDataFilter {
93
- /**
94
- * Company ID (sometimes called the manufacturer ID) to search for in the manufacturer data field.
95
- */
96
- companyIdentifier: number;
97
- /**
98
- * Prefix to match in the manufacturer data field.
99
- * On **Android** this field is mandatory.
100
- */
101
- dataPrefix?: Uint8Array;
102
- /**
103
- * 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.
104
- * The `mask` must have the same length of dataPrefix.
105
- */
106
- mask?: Uint8Array;
107
- }
108
- export interface BleDevice {
109
- /**
110
- * ID of the device, which will be needed for further calls.
111
- * On **Android** this is the BLE MAC address.
112
- * On **iOS** and **web** it is an identifier.
113
- */
114
- deviceId: string;
115
- /**
116
- * Name of the peripheral device.
117
- */
118
- name?: string;
119
- uuids?: string[];
120
- }
121
- export interface DeviceIdOptions {
122
- deviceId: string;
123
- }
124
- export interface TimeoutOptions {
125
- /**
126
- * Timeout in milliseconds for plugin call.
127
- * Default is 10000 for `connect` and 5000 for other plugin methods.
128
- */
129
- timeout?: number;
130
- }
131
- export interface RequestConnectionPriorityOptions extends DeviceIdOptions {
132
- connectionPriority: ConnectionPriority;
133
- }
134
- export interface GetDevicesOptions {
135
- deviceIds: string[];
136
- }
137
- export interface GetConnectedDevicesOptions {
138
- services: string[];
139
- }
140
- export interface BleService {
141
- readonly uuid: string;
142
- readonly characteristics: BleCharacteristic[];
143
- }
144
- export interface BleDescriptor {
145
- readonly uuid: string;
146
- }
147
- export interface BleCharacteristic {
148
- readonly uuid: string;
149
- readonly properties: BleCharacteristicProperties;
150
- readonly descriptors: BleDescriptor[];
151
- }
152
- export interface BleCharacteristicProperties {
153
- readonly broadcast: boolean;
154
- readonly read: boolean;
155
- readonly writeWithoutResponse: boolean;
156
- readonly write: boolean;
157
- readonly notify: boolean;
158
- readonly indicate: boolean;
159
- readonly authenticatedSignedWrites: boolean;
160
- readonly reliableWrite?: boolean;
161
- readonly writableAuxiliaries?: boolean;
162
- readonly extendedProperties?: boolean;
163
- readonly notifyEncryptionRequired?: boolean;
164
- readonly indicateEncryptionRequired?: boolean;
165
- }
166
- export interface BleServices {
167
- services: BleService[];
168
- }
169
- export interface ReadOptions {
170
- deviceId: string;
171
- service: string;
172
- characteristic: string;
173
- }
174
- export interface ReadDescriptorOptions {
175
- deviceId: string;
176
- service: string;
177
- characteristic: string;
178
- descriptor: string;
179
- }
180
- export type Data = DataView | string;
181
- export interface WriteOptions {
182
- deviceId: string;
183
- service: string;
184
- characteristic: string;
185
- /**
186
- * android, ios: string
187
- * web: DataView
188
- */
189
- value: Data;
190
- }
191
- export interface WriteDescriptorOptions {
192
- deviceId: string;
193
- service: string;
194
- characteristic: string;
195
- descriptor: string;
196
- /**
197
- * android, ios: string
198
- * web: DataView
199
- */
200
- value: Data;
201
- }
202
- export interface BooleanResult {
203
- value: boolean;
204
- }
205
- export interface GetDevicesResult {
206
- devices: BleDevice[];
207
- }
208
- export interface GetMtuResult {
209
- value: number;
210
- }
211
- export interface ReadRssiResult {
212
- value: string;
213
- }
214
- export interface ReadResult {
215
- /**
216
- * android, ios: string
217
- * web: DataView
218
- */
219
- value?: Data;
220
- }
221
- export interface ScanResultInternal<T = Data> {
222
- device: BleDevice;
223
- localName?: string;
224
- rssi?: number;
225
- txPower?: number;
226
- manufacturerData?: {
227
- [key: string]: T;
228
- };
229
- serviceData?: {
230
- [key: string]: T;
231
- };
232
- uuids?: string[];
233
- rawAdvertisement?: T;
234
- }
235
- export interface ScanResult {
236
- /**
237
- * The peripheral device that was found in the scan.
238
- * **Android** and **web**: `device.name` is always identical to `localName`.
239
- * **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.
240
- */
241
- device: BleDevice;
242
- /**
243
- * The name of the peripheral device from the advertisement data.
244
- */
245
- localName?: string;
246
- /**
247
- * Received Signal Strength Indication.
248
- */
249
- rssi?: number;
250
- /**
251
- * Transmit power in dBm. A value of 127 indicates that it is not available.
252
- */
253
- txPower?: number;
254
- /**
255
- * Manufacturer data, key is a company identifier and value is the data.
256
- */
257
- manufacturerData?: {
258
- [key: string]: DataView;
259
- };
260
- /**
261
- * Service data, key is a service UUID and value is the data.
262
- */
263
- serviceData?: {
264
- [key: string]: DataView;
265
- };
266
- /**
267
- * Advertised services.
268
- */
269
- uuids?: string[];
270
- /**
271
- * Raw advertisement data (**Android** only).
272
- */
273
- rawAdvertisement?: DataView;
274
- }
275
- export interface BluetoothLePlugin {
276
- initialize(options?: InitializeOptions): Promise<void>;
277
- isEnabled(): Promise<BooleanResult>;
278
- requestEnable(): Promise<void>;
279
- enable(): Promise<void>;
280
- disable(): Promise<void>;
281
- startEnabledNotifications(): Promise<void>;
282
- stopEnabledNotifications(): Promise<void>;
283
- isLocationEnabled(): Promise<BooleanResult>;
284
- openLocationSettings(): Promise<void>;
285
- openBluetoothSettings(): Promise<void>;
286
- openAppSettings(): Promise<void>;
287
- setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;
288
- requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;
289
- requestLEScan(options?: RequestBleDeviceOptions): Promise<void>;
290
- stopLEScan(): Promise<void>;
291
- getDevices(options: GetDevicesOptions): Promise<GetDevicesResult>;
292
- getConnectedDevices(options: GetConnectedDevicesOptions): Promise<GetDevicesResult>;
293
- getBondedDevices(): Promise<GetDevicesResult>;
294
- addListener(eventName: 'onEnabledChanged', listenerFunc: (result: BooleanResult) => void): Promise<PluginListenerHandle>;
295
- addListener(eventName: string, listenerFunc: (event: ReadResult) => void): Promise<PluginListenerHandle>;
296
- addListener(eventName: 'onScanResult', listenerFunc: (result: ScanResultInternal) => void): Promise<PluginListenerHandle>;
297
- connect(options: DeviceIdOptions & TimeoutOptions): Promise<void>;
298
- createBond(options: DeviceIdOptions & TimeoutOptions): Promise<void>;
299
- isBonded(options: DeviceIdOptions): Promise<BooleanResult>;
300
- disconnect(options: DeviceIdOptions): Promise<void>;
301
- getServices(options: DeviceIdOptions): Promise<BleServices>;
302
- discoverServices(options: DeviceIdOptions): Promise<void>;
303
- getMtu(options: DeviceIdOptions): Promise<GetMtuResult>;
304
- requestConnectionPriority(options: RequestConnectionPriorityOptions): Promise<void>;
305
- readRssi(options: DeviceIdOptions): Promise<ReadRssiResult>;
306
- read(options: ReadOptions & TimeoutOptions): Promise<ReadResult>;
307
- write(options: WriteOptions & TimeoutOptions): Promise<void>;
308
- writeWithoutResponse(options: WriteOptions & TimeoutOptions): Promise<void>;
309
- readDescriptor(options: ReadDescriptorOptions & TimeoutOptions): Promise<ReadResult>;
310
- writeDescriptor(options: WriteDescriptorOptions & TimeoutOptions): Promise<void>;
311
- startNotifications(options: ReadOptions & TimeoutOptions): Promise<void>;
312
- stopNotifications(options: ReadOptions): Promise<void>;
313
- }
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
+ }