@capacitor-community/bluetooth-le 7.3.0 → 7.3.2
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/dist/docs.json +22 -22
- package/dist/esm/bleClient.js +1 -0
- package/dist/esm/bleClient.js.map +1 -1
- package/dist/plugin.cjs.js +1 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/DeviceManager.swift +2 -90
- package/ios/Plugin/Plugin.swift +0 -12
- package/ios/Plugin/ScanFilters.swift +114 -0
- package/package.json +1 -1
package/dist/docs.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"returns": "Promise<void>",
|
|
19
19
|
"tags": [],
|
|
20
|
-
"docs": "Initialize Bluetooth Low Energy (BLE). If it fails, BLE might be unavailable on this device.\nOn **Android** it will ask for the location permission. On **iOS** it will ask for the Bluetooth permission.\nFor an example, see [usage](#usage).",
|
|
20
|
+
"docs": "Initialize Bluetooth Low Energy (BLE). If it fails, BLE might be unavailable on this device.\r\nOn **Android** it will ask for the location permission. On **iOS** it will ask for the Bluetooth permission.\r\nFor an example, see [usage](#usage).",
|
|
21
21
|
"complexTypes": [
|
|
22
22
|
"InitializeOptions"
|
|
23
23
|
],
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"parameters": [],
|
|
30
30
|
"returns": "Promise<boolean>",
|
|
31
31
|
"tags": [],
|
|
32
|
-
"docs": "Reports whether Bluetooth is enabled on this device.\nAlways returns `true` on **web**.",
|
|
32
|
+
"docs": "Reports whether Bluetooth is enabled on this device.\r\nAlways returns `true` on **web**.",
|
|
33
33
|
"complexTypes": [],
|
|
34
34
|
"slug": "isenabled"
|
|
35
35
|
},
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"parameters": [],
|
|
40
40
|
"returns": "Promise<void>",
|
|
41
41
|
"tags": [],
|
|
42
|
-
"docs": "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\nOnly available on **Android**.",
|
|
42
|
+
"docs": "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\r\nOnly available on **Android**.",
|
|
43
43
|
"complexTypes": [],
|
|
44
44
|
"slug": "requestenable"
|
|
45
45
|
},
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"text": "Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()"
|
|
55
55
|
}
|
|
56
56
|
],
|
|
57
|
-
"docs": "Enable Bluetooth.\nOnly available on **Android**.\n**Deprecated** Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()",
|
|
57
|
+
"docs": "Enable Bluetooth.\r\nOnly available on **Android**.\r\n**Deprecated** Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()",
|
|
58
58
|
"complexTypes": [],
|
|
59
59
|
"slug": "enable"
|
|
60
60
|
},
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"text": "Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()"
|
|
70
70
|
}
|
|
71
71
|
],
|
|
72
|
-
"docs": "Disable Bluetooth.\nOnly available on **Android**.\n**Deprecated** Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()",
|
|
72
|
+
"docs": "Disable Bluetooth.\r\nOnly available on **Android**.\r\n**Deprecated** Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()",
|
|
73
73
|
"complexTypes": [],
|
|
74
74
|
"slug": "disable"
|
|
75
75
|
},
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"text": "callback Callback function to use when the Bluetooth state changes."
|
|
91
91
|
}
|
|
92
92
|
],
|
|
93
|
-
"docs": "Register a callback function that will be invoked when Bluetooth is enabled (true) or disabled (false) on this device.\nNot available on **web** (the callback will never be invoked).",
|
|
93
|
+
"docs": "Register a callback function that will be invoked when Bluetooth is enabled (true) or disabled (false) on this device.\r\nNot available on **web** (the callback will never be invoked).",
|
|
94
94
|
"complexTypes": [],
|
|
95
95
|
"slug": "startenablednotifications"
|
|
96
96
|
},
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"parameters": [],
|
|
111
111
|
"returns": "Promise<boolean>",
|
|
112
112
|
"tags": [],
|
|
113
|
-
"docs": "Reports whether Location Services are enabled on this device.\nOnly available on **Android**.",
|
|
113
|
+
"docs": "Reports whether Location Services are enabled on this device.\r\nOnly available on **Android**.",
|
|
114
114
|
"complexTypes": [],
|
|
115
115
|
"slug": "islocationenabled"
|
|
116
116
|
},
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
"parameters": [],
|
|
121
121
|
"returns": "Promise<void>",
|
|
122
122
|
"tags": [],
|
|
123
|
-
"docs": "Open Location settings.\nOnly available on **Android**.",
|
|
123
|
+
"docs": "Open Location settings.\r\nOnly available on **Android**.",
|
|
124
124
|
"complexTypes": [],
|
|
125
125
|
"slug": "openlocationsettings"
|
|
126
126
|
},
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
"parameters": [],
|
|
131
131
|
"returns": "Promise<void>",
|
|
132
132
|
"tags": [],
|
|
133
|
-
"docs": "Open Bluetooth settings.\nOnly available on **Android**.",
|
|
133
|
+
"docs": "Open Bluetooth settings.\r\nOnly available on **Android**.",
|
|
134
134
|
"complexTypes": [],
|
|
135
135
|
"slug": "openbluetoothsettings"
|
|
136
136
|
},
|
|
@@ -140,7 +140,7 @@
|
|
|
140
140
|
"parameters": [],
|
|
141
141
|
"returns": "Promise<void>",
|
|
142
142
|
"tags": [],
|
|
143
|
-
"docs": "Open App settings.\nNot available on **web**.\nOn **iOS** when a user declines the request to use Bluetooth on the first call of `initialize`, it is not possible\nto request for Bluetooth again from within the app. In this case Bluetooth has to be enabled in the app settings\nfor the app to be able use it.",
|
|
143
|
+
"docs": "Open App settings.\r\nNot available on **web**.\r\nOn **iOS** when a user declines the request to use Bluetooth on the first call of `initialize`, it is not possible\r\nto request for Bluetooth again from within the app. In this case Bluetooth has to be enabled in the app settings\r\nfor the app to be able use it.",
|
|
144
144
|
"complexTypes": [],
|
|
145
145
|
"slug": "openappsettings"
|
|
146
146
|
},
|
|
@@ -184,7 +184,7 @@
|
|
|
184
184
|
"text": "options Device filters, see [RequestBleDeviceOptions](#RequestBleDeviceOptions)"
|
|
185
185
|
}
|
|
186
186
|
],
|
|
187
|
-
"docs": "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.\nFor an example, see [usage](#usage).",
|
|
187
|
+
"docs": "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.\r\nFor an example, see [usage](#usage).",
|
|
188
188
|
"complexTypes": [
|
|
189
189
|
"BleDevice",
|
|
190
190
|
"RequestBleDeviceOptions"
|
|
@@ -217,7 +217,7 @@
|
|
|
217
217
|
"text": "callback"
|
|
218
218
|
}
|
|
219
219
|
],
|
|
220
|
-
"docs": "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.\nScanning will continue until `stopLEScan` is called. For an example, see [usage](#usage).\n**Note**: Use with care on **web** platform, the required API is still behind a flag in most browsers.",
|
|
220
|
+
"docs": "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.\r\nScanning will continue until `stopLEScan` is called. For an example, see [usage](#usage).\r\n**Note**: Use with care on **web** platform, the required API is still behind a flag in most browsers.",
|
|
221
221
|
"complexTypes": [
|
|
222
222
|
"RequestBleDeviceOptions",
|
|
223
223
|
"ScanResult"
|
|
@@ -251,7 +251,7 @@
|
|
|
251
251
|
"text": "deviceIds List of device IDs, e.g. saved from a previous app run."
|
|
252
252
|
}
|
|
253
253
|
],
|
|
254
|
-
"docs": "On iOS and web, if you want to connect to a previously connected device without scanning first, you can use `getDevice`.\nUses [retrievePeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1519127-retrieveperipherals) on iOS and\n[getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.\nOn Android, you can directly connect to the device with the deviceId.",
|
|
254
|
+
"docs": "On iOS and web, if you want to connect to a previously connected device without scanning first, you can use `getDevice`.\r\nUses [retrievePeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1519127-retrieveperipherals) on iOS and\r\n[getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.\r\nOn Android, you can directly connect to the device with the deviceId.",
|
|
255
255
|
"complexTypes": [
|
|
256
256
|
"BleDevice"
|
|
257
257
|
],
|
|
@@ -263,7 +263,7 @@
|
|
|
263
263
|
"parameters": [],
|
|
264
264
|
"returns": "Promise<BleDevice[]>",
|
|
265
265
|
"tags": [],
|
|
266
|
-
"docs": "Get a list of currently bonded devices.\nOnly available on **Android**.\nUses [getBondedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getBondedDevices()) on Android",
|
|
266
|
+
"docs": "Get a list of currently bonded devices.\r\nOnly available on **Android**.\r\nUses [getBondedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getBondedDevices()) on Android",
|
|
267
267
|
"complexTypes": [
|
|
268
268
|
"BleDevice"
|
|
269
269
|
],
|
|
@@ -286,7 +286,7 @@
|
|
|
286
286
|
"text": "services List of services to filter the devices by. If no service is specified, no devices will be returned. Only applies to iOS."
|
|
287
287
|
}
|
|
288
288
|
],
|
|
289
|
-
"docs": "Get a list of currently connected devices.\nUses [retrieveConnectedPeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals) on iOS,\n[getConnectedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getConnectedDevices(int)) on Android\nand [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.",
|
|
289
|
+
"docs": "Get a list of currently connected devices.\r\nUses [retrieveConnectedPeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals) on iOS,\r\n[getConnectedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getConnectedDevices(int)) on Android\r\nand [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.",
|
|
290
290
|
"complexTypes": [
|
|
291
291
|
"BleDevice"
|
|
292
292
|
],
|
|
@@ -359,7 +359,7 @@
|
|
|
359
359
|
"text": "options Options for plugin call"
|
|
360
360
|
}
|
|
361
361
|
],
|
|
362
|
-
"docs": "Create a bond with a peripheral BLE device.\nOnly available on **Android**. On iOS bonding is handled by the OS.",
|
|
362
|
+
"docs": "Create a bond with a peripheral BLE device.\r\nOnly available on **Android**. On iOS bonding is handled by the OS.",
|
|
363
363
|
"complexTypes": [
|
|
364
364
|
"TimeoutOptions"
|
|
365
365
|
],
|
|
@@ -382,7 +382,7 @@
|
|
|
382
382
|
"text": "deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))"
|
|
383
383
|
}
|
|
384
384
|
],
|
|
385
|
-
"docs": "Report whether a peripheral BLE device is bonded.\nOnly available on **Android**. On iOS bonding is handled by the OS.",
|
|
385
|
+
"docs": "Report whether a peripheral BLE device is bonded.\r\nOnly available on **Android**. On iOS bonding is handled by the OS.",
|
|
386
386
|
"complexTypes": [],
|
|
387
387
|
"slug": "isbonded"
|
|
388
388
|
},
|
|
@@ -447,7 +447,7 @@
|
|
|
447
447
|
"text": "deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))"
|
|
448
448
|
}
|
|
449
449
|
],
|
|
450
|
-
"docs": "Discover services, characteristics and descriptors of a device.\nYou only need this method if your peripheral device changes its services and characteristics at runtime.\nIf the discovery was successful, the remote services can be retrieved using the getServices function.\nNot available on **web**.",
|
|
450
|
+
"docs": "Discover services, characteristics and descriptors of a device.\r\nYou only need this method if your peripheral device changes its services and characteristics at runtime.\r\nIf the discovery was successful, the remote services can be retrieved using the getServices function.\r\nNot available on **web**.",
|
|
451
451
|
"complexTypes": [],
|
|
452
452
|
"slug": "discoverservices"
|
|
453
453
|
},
|
|
@@ -468,7 +468,7 @@
|
|
|
468
468
|
"text": "deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))"
|
|
469
469
|
}
|
|
470
470
|
],
|
|
471
|
-
"docs": "Get the MTU of a connected device. Note that the maximum write value length is 3 bytes less than the MTU.\nNot available on **web**.",
|
|
471
|
+
"docs": "Get the MTU of a connected device. Note that the maximum write value length is 3 bytes less than the MTU.\r\nNot available on **web**.",
|
|
472
472
|
"complexTypes": [],
|
|
473
473
|
"slug": "getmtu"
|
|
474
474
|
},
|
|
@@ -498,7 +498,7 @@
|
|
|
498
498
|
"text": "connectionPriority Request a specific connection priority. See [ConnectionPriority](#connectionpriority)"
|
|
499
499
|
}
|
|
500
500
|
],
|
|
501
|
-
"docs": "Request a connection parameter update.\nOnly available on **Android**. https://developer.android.com/reference/android/bluetooth/BluetoothGatt#requestConnectionPriority(int)",
|
|
501
|
+
"docs": "Request a connection parameter update.\r\nOnly available on **Android**. https://developer.android.com/reference/android/bluetooth/BluetoothGatt#requestConnectionPriority(int)",
|
|
502
502
|
"complexTypes": [
|
|
503
503
|
"ConnectionPriority"
|
|
504
504
|
],
|
|
@@ -521,7 +521,7 @@
|
|
|
521
521
|
"text": "deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))"
|
|
522
522
|
}
|
|
523
523
|
],
|
|
524
|
-
"docs": "Read the RSSI value of a connected device.\nNot available on **web**.",
|
|
524
|
+
"docs": "Read the RSSI value of a connected device.\r\nNot available on **web**.",
|
|
525
525
|
"complexTypes": [],
|
|
526
526
|
"slug": "readrssi"
|
|
527
527
|
},
|
|
@@ -878,7 +878,7 @@
|
|
|
878
878
|
"text": "options Options for plugin call. Timeout not supported on **web**."
|
|
879
879
|
}
|
|
880
880
|
],
|
|
881
|
-
"docs": "Start listening to changes of the value of a characteristic.\nNote that you should only start the notifications once per characteristic in your app and share the data and\nnot call `startNotifications` in every component that needs the data.\nFor an example, see [usage](#usage).",
|
|
881
|
+
"docs": "Start listening to changes of the value of a characteristic.\r\nNote that you should only start the notifications once per characteristic in your app and share the data and\r\nnot call `startNotifications` in every component that needs the data.\r\nFor an example, see [usage](#usage).",
|
|
882
882
|
"complexTypes": [
|
|
883
883
|
"DataView",
|
|
884
884
|
"TimeoutOptions"
|
package/dist/esm/bleClient.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bleClient.js","sourceRoot":"","sources":["../../src/bleClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAanG,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAySzC,MAAM,cAAc;IAApB;QACU,iBAAY,GAAgC,IAAI,CAAC;QACjD,mBAAc,GAAG,IAAI,GAAG,EAAgC,CAAC;QACzD,UAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAicjC,CAAC;IA/bC,WAAW;QACT,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,YAAY;QACV,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,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AC,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,iCAC/D,MAAM,KACT,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,EAC3C,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,IAC/B,CAAC,CAAC;aACL;SACF;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,YAAY,CAAC,KAAY;QAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;SACnC;aAAM,IAAI,KAAK,KAAK,SAAS,EAAE;YAC9B,OAAO,IAAI,QAAQ,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;SACzC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,aAAa,CAAC,GAA6B;QACjD,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,OAAO,SAAS,CAAC;SAClB;QACD,MAAM,MAAM,GAAgC,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAClC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;SAC3C;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,cAAc,EAAE,CAAC","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\nimport { Capacitor } from '@capacitor/core';\n\nimport type { DisplayStrings } from './config';\nimport { dataViewToHexString, hexStringToDataView, toUint8Array, toHexString } from './conversion';\nimport type {\n BleDevice,\n BleService,\n ConnectionPriority,\n Data,\n InitializeOptions,\n ReadResult,\n RequestBleDeviceOptions,\n ScanResult,\n ScanResultInternal,\n TimeoutOptions,\n} from './definitions';\nimport { BluetoothLe } from './plugin';\nimport { getQueue } from './queue';\nimport { parseUUID } from './validators';\n\nexport interface BleClientInterface {\n /**\n * Initialize Bluetooth Low Energy (BLE). If it fails, BLE might be unavailable on this device.\n * On **Android** it will ask for the location permission. On **iOS** it will ask for the Bluetooth permission.\n * For an example, see [usage](#usage).\n */\n initialize(options?: InitializeOptions): Promise<void>;\n\n /**\n * Reports whether Bluetooth is enabled on this device.\n * Always returns `true` on **web**.\n */\n isEnabled(): Promise<boolean>;\n\n /**\n * 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\n * Only available on **Android**.*/\n requestEnable(): Promise<void>;\n\n /**\n * Enable Bluetooth.\n * Only available on **Android**.\n * **Deprecated** Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()\n * @deprecated Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()\n */\n enable(): Promise<void>;\n\n /**\n * Disable Bluetooth.\n * Only available on **Android**.\n * **Deprecated** Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()\n * @deprecated Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()\n */\n disable(): Promise<void>;\n\n /**\n * Register a callback function that will be invoked when Bluetooth is enabled (true) or disabled (false) on this device.\n * Not available on **web** (the callback will never be invoked).\n * @param callback Callback function to use when the Bluetooth state changes.\n */\n startEnabledNotifications(callback: (value: boolean) => void): Promise<void>;\n\n /**\n * Stop the enabled notifications registered with `startEnabledNotifications`.\n */\n stopEnabledNotifications(): Promise<void>;\n\n /**\n * Reports whether Location Services are enabled on this device.\n * Only available on **Android**.\n */\n isLocationEnabled(): Promise<boolean>;\n\n /**\n * Open Location settings.\n * Only available on **Android**.\n */\n openLocationSettings(): Promise<void>;\n\n /**\n * Open Bluetooth settings.\n * Only available on **Android**.\n */\n openBluetoothSettings(): Promise<void>;\n\n /**\n * Open App settings.\n * Not available on **web**.\n * On **iOS** when a user declines the request to use Bluetooth on the first call of `initialize`, it is not possible\n * to request for Bluetooth again from within the app. In this case Bluetooth has to be enabled in the app settings\n * for the app to be able use it.\n */\n openAppSettings(): Promise<void>;\n\n /**\n * Set the strings that are displayed in the `requestDevice` dialog.\n * @param displayStrings\n */\n setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;\n\n /**\n * 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.\n * For an example, see [usage](#usage).\n * @param options Device filters, see [RequestBleDeviceOptions](#RequestBleDeviceOptions)\n */\n requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;\n\n /**\n * 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.\n * Scanning will continue until `stopLEScan` is called. For an example, see [usage](#usage).\n * **Note**: Use with care on **web** platform, the required API is still behind a flag in most browsers.\n * @param options\n * @param callback\n */\n requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void>;\n\n /**\n * Stop scanning for BLE devices. For an example, see [usage](#usage).\n */\n stopLEScan(): Promise<void>;\n\n /**\n * On iOS and web, if you want to connect to a previously connected device without scanning first, you can use `getDevice`.\n * Uses [retrievePeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1519127-retrieveperipherals) on iOS and\n * [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.\n * On Android, you can directly connect to the device with the deviceId.\n * @param deviceIds List of device IDs, e.g. saved from a previous app run.\n */\n getDevices(deviceIds: string[]): Promise<BleDevice[]>;\n\n /**\n * Get a list of currently bonded devices.\n * Only available on **Android**.\n * Uses [getBondedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getBondedDevices()) on Android\n */\n getBondedDevices(): Promise<BleDevice[]>;\n\n /**\n * Get a list of currently connected devices.\n * Uses [retrieveConnectedPeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals) on iOS,\n * [getConnectedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getConnectedDevices(int)) on Android\n * and [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.\n * @param services List of services to filter the devices by. If no service is specified, no devices will be returned. Only applies to iOS.\n */\n getConnectedDevices(services: string[]): Promise<BleDevice[]>;\n\n /**\n * Connect to a peripheral BLE device. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param onDisconnect Optional disconnect callback function that will be used when the device disconnects\n * @param options Options for plugin call\n */\n connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void>;\n\n /**\n * Create a bond with a peripheral BLE device.\n * Only available on **Android**. On iOS bonding is handled by the OS.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param options Options for plugin call\n */\n createBond(deviceId: string, options?: TimeoutOptions): Promise<void>;\n\n /**\n * Report whether a peripheral BLE device is bonded.\n * Only available on **Android**. On iOS bonding is handled by the OS.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n isBonded(deviceId: string): Promise<boolean>;\n\n /**\n * Disconnect from a peripheral BLE device. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n disconnect(deviceId: string): Promise<void>;\n\n /**\n * Get services, characteristics and descriptors of a device.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n getServices(deviceId: string): Promise<BleService[]>;\n\n /**\n * Discover services, characteristics and descriptors of a device.\n * You only need this method if your peripheral device changes its services and characteristics at runtime.\n * If the discovery was successful, the remote services can be retrieved using the getServices function.\n * Not available on **web**.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n discoverServices(deviceId: string): Promise<void>;\n\n /**\n * Get the MTU of a connected device. Note that the maximum write value length is 3 bytes less than the MTU.\n * Not available on **web**.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n getMtu(deviceId: string): Promise<number>;\n\n /**\n * Request a connection parameter update.\n * Only available on **Android**. https://developer.android.com/reference/android/bluetooth/BluetoothGatt#requestConnectionPriority(int)\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param connectionPriority Request a specific connection priority. See [ConnectionPriority](#connectionpriority)\n */\n requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void>;\n\n /**\n * Read the RSSI value of a connected device.\n * Not available on **web**.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n readRssi(deviceId: string): Promise<number>;\n\n /**\n * Read the value of a characteristic. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param options Options for plugin call\n */\n read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView>;\n\n /**\n * Write a value to a characteristic. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @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])\n * @param options Options for plugin call\n */\n write(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions,\n ): Promise<void>;\n\n /**\n * Write a value to a characteristic without waiting for a response.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @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])\n * @param options Options for plugin call\n */\n writeWithoutResponse(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions,\n ): Promise<void>;\n\n /**\n * Read the value of a descriptor.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))\n * @param options Options for plugin call\n */\n readDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n options?: TimeoutOptions,\n ): Promise<DataView>;\n\n /**\n * Write a value to a descriptor.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))\n * @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])\n * @param options Options for plugin call\n */\n writeDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n value: DataView,\n options?: TimeoutOptions,\n ): Promise<void>;\n\n /**\n * Start listening to changes of the value of a characteristic.\n * Note that you should only start the notifications once per characteristic in your app and share the data and\n * not call `startNotifications` in every component that needs the data.\n * For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param callback Callback function to use when the value of the characteristic changes\n * @param options Options for plugin call. Timeout not supported on **web**.\n */\n startNotifications(\n deviceId: string,\n service: string,\n characteristic: string,\n callback: (value: DataView) => void,\n options?: TimeoutOptions,\n ): Promise<void>;\n\n /**\n * Stop listening to the changes of the value of a characteristic. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n */\n stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void>;\n}\n\nclass BleClientClass implements BleClientInterface {\n private scanListener: PluginListenerHandle | null = null;\n private eventListeners = new Map<string, PluginListenerHandle>();\n private queue = getQueue(true);\n\n enableQueue() {\n this.queue = getQueue(true);\n }\n\n disableQueue() {\n this.queue = getQueue(false);\n }\n\n async initialize(options?: InitializeOptions): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.initialize(options);\n });\n }\n\n async isEnabled(): Promise<boolean> {\n const enabled = await this.queue(async () => {\n const result = await BluetoothLe.isEnabled();\n return result.value;\n });\n return enabled;\n }\n\n async requestEnable(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.requestEnable();\n });\n }\n\n async enable(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.enable();\n });\n }\n\n async disable(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.disable();\n });\n }\n\n async startEnabledNotifications(callback: (value: boolean) => void): Promise<void> {\n await this.queue(async () => {\n const key = `onEnabledChanged`;\n await this.eventListeners.get(key)?.remove();\n const listener = await BluetoothLe.addListener(key, (result) => {\n callback(result.value);\n });\n this.eventListeners.set(key, listener);\n await BluetoothLe.startEnabledNotifications();\n });\n }\n\n async stopEnabledNotifications(): Promise<void> {\n await this.queue(async () => {\n const key = `onEnabledChanged`;\n await this.eventListeners.get(key)?.remove();\n this.eventListeners.delete(key);\n await BluetoothLe.stopEnabledNotifications();\n });\n }\n\n async isLocationEnabled(): Promise<boolean> {\n const enabled = await this.queue(async () => {\n const result = await BluetoothLe.isLocationEnabled();\n return result.value;\n });\n return enabled;\n }\n\n async openLocationSettings(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.openLocationSettings();\n });\n }\n\n async openBluetoothSettings(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.openBluetoothSettings();\n });\n }\n\n async openAppSettings(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.openAppSettings();\n });\n }\n\n async setDisplayStrings(displayStrings: DisplayStrings): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.setDisplayStrings(displayStrings);\n });\n }\n\n async requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice> {\n options = options ? this.validateRequestBleDeviceOptions(options) : undefined;\n const result = await this.queue(async () => {\n const device = await BluetoothLe.requestDevice(options);\n return device;\n });\n return result;\n }\n\n async requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void> {\n options = this.validateRequestBleDeviceOptions(options);\n await this.queue(async () => {\n await this.scanListener?.remove();\n this.scanListener = await BluetoothLe.addListener('onScanResult', (resultInternal: ScanResultInternal) => {\n const result: ScanResult = {\n ...resultInternal,\n manufacturerData: this.convertObject(resultInternal.manufacturerData),\n serviceData: this.convertObject(resultInternal.serviceData),\n rawAdvertisement: resultInternal.rawAdvertisement\n ? this.convertValue(resultInternal.rawAdvertisement)\n : undefined,\n };\n callback(result);\n });\n await BluetoothLe.requestLEScan(options);\n });\n }\n\n async stopLEScan(): Promise<void> {\n await this.queue(async () => {\n await this.scanListener?.remove();\n this.scanListener = null;\n await BluetoothLe.stopLEScan();\n });\n }\n\n async getDevices(deviceIds: string[]): Promise<BleDevice[]> {\n if (!Array.isArray(deviceIds)) {\n throw new Error('deviceIds must be an array');\n }\n return this.queue(async () => {\n const result = await BluetoothLe.getDevices({ deviceIds });\n return result.devices;\n });\n }\n\n async getConnectedDevices(services: string[]): Promise<BleDevice[]> {\n if (!Array.isArray(services)) {\n throw new Error('services must be an array');\n }\n services = services.map(parseUUID);\n return this.queue(async () => {\n const result = await BluetoothLe.getConnectedDevices({ services });\n return result.devices;\n });\n }\n\n async getBondedDevices(): Promise<BleDevice[]> {\n return this.queue(async () => {\n const result = await BluetoothLe.getBondedDevices();\n return result.devices;\n });\n }\n\n async connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void> {\n await this.queue(async () => {\n if (onDisconnect) {\n const key = `disconnected|${deviceId}`;\n await this.eventListeners.get(key)?.remove();\n const listener = await BluetoothLe.addListener(key, () => {\n onDisconnect(deviceId);\n });\n this.eventListeners.set(key, listener);\n }\n await BluetoothLe.connect({ deviceId, ...options });\n });\n }\n\n async createBond(deviceId: string, options?: TimeoutOptions): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.createBond({ deviceId, ...options });\n });\n }\n\n async isBonded(deviceId: string): Promise<boolean> {\n const isBonded = await this.queue(async () => {\n const result = await BluetoothLe.isBonded({ deviceId });\n return result.value;\n });\n return isBonded;\n }\n\n async disconnect(deviceId: string): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.disconnect({ deviceId });\n });\n }\n\n async getServices(deviceId: string): Promise<BleService[]> {\n const services = await this.queue(async () => {\n const result = await BluetoothLe.getServices({ deviceId });\n return result.services;\n });\n return services;\n }\n\n async discoverServices(deviceId: string): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.discoverServices({ deviceId });\n });\n }\n\n async getMtu(deviceId: string): Promise<number> {\n const value = await this.queue(async () => {\n const result = await BluetoothLe.getMtu({ deviceId });\n return result.value;\n });\n return value;\n }\n\n async requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.requestConnectionPriority({ deviceId, connectionPriority });\n });\n }\n\n async readRssi(deviceId: string): Promise<number> {\n const value = await this.queue(async () => {\n const result = await BluetoothLe.readRssi({ deviceId });\n return parseFloat(result.value);\n });\n return value;\n }\n\n async read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n const value = await this.queue(async () => {\n const result = await BluetoothLe.read({\n deviceId,\n service,\n characteristic,\n ...options,\n });\n return this.convertValue(result.value);\n });\n return value;\n }\n\n async write(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions,\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n return this.queue(async () => {\n if (!value?.buffer) {\n throw new Error('Invalid data.');\n }\n let writeValue: DataView | string = value;\n if (Capacitor.getPlatform() !== 'web') {\n // on native we can only write strings\n writeValue = dataViewToHexString(value);\n }\n await BluetoothLe.write({\n deviceId,\n service,\n characteristic,\n value: writeValue,\n ...options,\n });\n });\n }\n\n async writeWithoutResponse(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions,\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n await this.queue(async () => {\n if (!value?.buffer) {\n throw new Error('Invalid data.');\n }\n let writeValue: DataView | string = value;\n if (Capacitor.getPlatform() !== 'web') {\n // on native we can only write strings\n writeValue = dataViewToHexString(value);\n }\n await BluetoothLe.writeWithoutResponse({\n deviceId,\n service,\n characteristic,\n value: writeValue,\n ...options,\n });\n });\n }\n\n async readDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n options?: TimeoutOptions,\n ): Promise<DataView> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n descriptor = parseUUID(descriptor);\n const value = await this.queue(async () => {\n const result = await BluetoothLe.readDescriptor({\n deviceId,\n service,\n characteristic,\n descriptor,\n ...options,\n });\n return this.convertValue(result.value);\n });\n return value;\n }\n\n async writeDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n value: DataView,\n options?: TimeoutOptions,\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n descriptor = parseUUID(descriptor);\n return this.queue(async () => {\n if (!value?.buffer) {\n throw new Error('Invalid data.');\n }\n let writeValue: DataView | string = value;\n if (Capacitor.getPlatform() !== 'web') {\n // on native we can only write strings\n writeValue = dataViewToHexString(value);\n }\n await BluetoothLe.writeDescriptor({\n deviceId,\n service,\n characteristic,\n descriptor,\n value: writeValue,\n ...options,\n });\n });\n }\n\n async startNotifications(\n deviceId: string,\n service: string,\n characteristic: string,\n callback: (value: DataView) => void,\n options?: TimeoutOptions,\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n await this.queue(async () => {\n const key = `notification|${deviceId}|${service}|${characteristic}`;\n await this.eventListeners.get(key)?.remove();\n const listener = await BluetoothLe.addListener(key, (event: ReadResult) => {\n callback(this.convertValue(event?.value));\n });\n this.eventListeners.set(key, listener);\n await BluetoothLe.startNotifications({\n deviceId,\n service,\n characteristic,\n ...options,\n });\n });\n }\n\n async stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n await this.queue(async () => {\n const key = `notification|${deviceId}|${service}|${characteristic}`;\n await this.eventListeners.get(key)?.remove();\n this.eventListeners.delete(key);\n await BluetoothLe.stopNotifications({\n deviceId,\n service,\n characteristic,\n });\n });\n }\n\n private validateRequestBleDeviceOptions(options: RequestBleDeviceOptions): RequestBleDeviceOptions {\n if (options.services) {\n options.services = options.services.map(parseUUID);\n }\n if (options.optionalServices) {\n options.optionalServices = options.optionalServices.map(parseUUID);\n }\n if (options.serviceData && Capacitor.getPlatform() !== 'web') {\n // Native platforms: convert to hex strings\n options.serviceData = options.serviceData.map((filter) => ({\n ...filter,\n serviceUuid: parseUUID(filter.serviceUuid),\n dataPrefix: toHexString(filter.dataPrefix),\n mask: toHexString(filter.mask),\n })) as any;\n }\n if (options.manufacturerData) {\n if (Capacitor.getPlatform() !== 'web') {\n // Native platforms: convert to hex strings\n options.manufacturerData = options.manufacturerData.map((filter) => ({\n ...filter,\n dataPrefix: toHexString(filter.dataPrefix),\n mask: toHexString(filter.mask),\n })) as any;\n } else {\n // Web platform: convert to Uint8Array for Web Bluetooth API\n options.manufacturerData = options.manufacturerData.map((filter) => ({\n ...filter,\n dataPrefix: toUint8Array(filter.dataPrefix),\n mask: toUint8Array(filter.mask),\n }));\n }\n }\n return options;\n }\n\n private convertValue(value?: Data): DataView {\n if (typeof value === 'string') {\n return hexStringToDataView(value);\n } else if (value === undefined) {\n return new DataView(new ArrayBuffer(0));\n }\n return value;\n }\n\n private convertObject(obj?: { [key: string]: Data }): { [key: string]: DataView } | undefined {\n if (obj === undefined) {\n return undefined;\n }\n const result: { [key: string]: DataView } = {};\n for (const key of Object.keys(obj)) {\n result[key] = this.convertValue(obj[key]);\n }\n return result;\n }\n}\n\nexport const BleClient = new BleClientClass();\n"]}
|
|
1
|
+
{"version":3,"file":"bleClient.js","sourceRoot":"","sources":["../../src/bleClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAanG,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAySzC,MAAM,cAAc;IAApB;QACU,iBAAY,GAAgC,IAAI,CAAC;QACjD,mBAAc,GAAG,IAAI,GAAG,EAAgC,CAAC;QACzD,UAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAkcjC,CAAC;IAhcC,WAAW;QACT,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,YAAY;QACV,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,K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gBAC5D,OAAO,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,iCAC/D,MAAM,KACT,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,EAC3C,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,IAC/B,CAAC,CAAC;aACL;SACF;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,YAAY,CAAC,KAAY;QAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;SACnC;aAAM,IAAI,KAAK,KAAK,SAAS,EAAE;YAC9B,OAAO,IAAI,QAAQ,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;SACzC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,aAAa,CAAC,GAA6B;QACjD,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,OAAO,SAAS,CAAC;SAClB;QACD,MAAM,MAAM,GAAgC,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAClC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;SAC3C;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,cAAc,EAAE,CAAC","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\r\nimport { Capacitor } from '@capacitor/core';\r\n\r\nimport type { DisplayStrings } from './config';\r\nimport { dataViewToHexString, hexStringToDataView, toUint8Array, toHexString } from './conversion';\r\nimport type {\r\n BleDevice,\r\n BleService,\r\n ConnectionPriority,\r\n Data,\r\n InitializeOptions,\r\n ReadResult,\r\n RequestBleDeviceOptions,\r\n ScanResult,\r\n ScanResultInternal,\r\n TimeoutOptions,\r\n} from './definitions';\r\nimport { BluetoothLe } from './plugin';\r\nimport { getQueue } from './queue';\r\nimport { parseUUID } from './validators';\r\n\r\nexport interface BleClientInterface {\r\n /**\r\n * Initialize Bluetooth Low Energy (BLE). If it fails, BLE might be unavailable on this device.\r\n * On **Android** it will ask for the location permission. On **iOS** it will ask for the Bluetooth permission.\r\n * For an example, see [usage](#usage).\r\n */\r\n initialize(options?: InitializeOptions): Promise<void>;\r\n\r\n /**\r\n * Reports whether Bluetooth is enabled on this device.\r\n * Always returns `true` on **web**.\r\n */\r\n isEnabled(): Promise<boolean>;\r\n\r\n /**\r\n * 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\r\n * Only available on **Android**.*/\r\n requestEnable(): Promise<void>;\r\n\r\n /**\r\n * Enable Bluetooth.\r\n * Only available on **Android**.\r\n * **Deprecated** Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()\r\n * @deprecated Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()\r\n */\r\n enable(): Promise<void>;\r\n\r\n /**\r\n * Disable Bluetooth.\r\n * Only available on **Android**.\r\n * **Deprecated** Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()\r\n * @deprecated Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()\r\n */\r\n disable(): Promise<void>;\r\n\r\n /**\r\n * Register a callback function that will be invoked when Bluetooth is enabled (true) or disabled (false) on this device.\r\n * Not available on **web** (the callback will never be invoked).\r\n * @param callback Callback function to use when the Bluetooth state changes.\r\n */\r\n startEnabledNotifications(callback: (value: boolean) => void): Promise<void>;\r\n\r\n /**\r\n * Stop the enabled notifications registered with `startEnabledNotifications`.\r\n */\r\n stopEnabledNotifications(): Promise<void>;\r\n\r\n /**\r\n * Reports whether Location Services are enabled on this device.\r\n * Only available on **Android**.\r\n */\r\n isLocationEnabled(): Promise<boolean>;\r\n\r\n /**\r\n * Open Location settings.\r\n * Only available on **Android**.\r\n */\r\n openLocationSettings(): Promise<void>;\r\n\r\n /**\r\n * Open Bluetooth settings.\r\n * Only available on **Android**.\r\n */\r\n openBluetoothSettings(): Promise<void>;\r\n\r\n /**\r\n * Open App settings.\r\n * Not available on **web**.\r\n * On **iOS** when a user declines the request to use Bluetooth on the first call of `initialize`, it is not possible\r\n * to request for Bluetooth again from within the app. In this case Bluetooth has to be enabled in the app settings\r\n * for the app to be able use it.\r\n */\r\n openAppSettings(): Promise<void>;\r\n\r\n /**\r\n * Set the strings that are displayed in the `requestDevice` dialog.\r\n * @param displayStrings\r\n */\r\n setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;\r\n\r\n /**\r\n * 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.\r\n * For an example, see [usage](#usage).\r\n * @param options Device filters, see [RequestBleDeviceOptions](#RequestBleDeviceOptions)\r\n */\r\n requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;\r\n\r\n /**\r\n * 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.\r\n * Scanning will continue until `stopLEScan` is called. For an example, see [usage](#usage).\r\n * **Note**: Use with care on **web** platform, the required API is still behind a flag in most browsers.\r\n * @param options\r\n * @param callback\r\n */\r\n requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void>;\r\n\r\n /**\r\n * Stop scanning for BLE devices. For an example, see [usage](#usage).\r\n */\r\n stopLEScan(): Promise<void>;\r\n\r\n /**\r\n * On iOS and web, if you want to connect to a previously connected device without scanning first, you can use `getDevice`.\r\n * Uses [retrievePeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1519127-retrieveperipherals) on iOS and\r\n * [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.\r\n * On Android, you can directly connect to the device with the deviceId.\r\n * @param deviceIds List of device IDs, e.g. saved from a previous app run.\r\n */\r\n getDevices(deviceIds: string[]): Promise<BleDevice[]>;\r\n\r\n /**\r\n * Get a list of currently bonded devices.\r\n * Only available on **Android**.\r\n * Uses [getBondedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#getBondedDevices()) on Android\r\n */\r\n getBondedDevices(): Promise<BleDevice[]>;\r\n\r\n /**\r\n * Get a list of currently connected devices.\r\n * Uses [retrieveConnectedPeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals) on iOS,\r\n * [getConnectedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getConnectedDevices(int)) on Android\r\n * and [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.\r\n * @param services List of services to filter the devices by. If no service is specified, no devices will be returned. Only applies to iOS.\r\n */\r\n getConnectedDevices(services: string[]): Promise<BleDevice[]>;\r\n\r\n /**\r\n * Connect to a peripheral BLE device. For an example, see [usage](#usage).\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n * @param onDisconnect Optional disconnect callback function that will be used when the device disconnects\r\n * @param options Options for plugin call\r\n */\r\n connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void>;\r\n\r\n /**\r\n * Create a bond with a peripheral BLE device.\r\n * Only available on **Android**. On iOS bonding is handled by the OS.\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n * @param options Options for plugin call\r\n */\r\n createBond(deviceId: string, options?: TimeoutOptions): Promise<void>;\r\n\r\n /**\r\n * Report whether a peripheral BLE device is bonded.\r\n * Only available on **Android**. On iOS bonding is handled by the OS.\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n */\r\n isBonded(deviceId: string): Promise<boolean>;\r\n\r\n /**\r\n * Disconnect from a peripheral BLE device. For an example, see [usage](#usage).\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n */\r\n disconnect(deviceId: string): Promise<void>;\r\n\r\n /**\r\n * Get services, characteristics and descriptors of a device.\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n */\r\n getServices(deviceId: string): Promise<BleService[]>;\r\n\r\n /**\r\n * Discover services, characteristics and descriptors of a device.\r\n * You only need this method if your peripheral device changes its services and characteristics at runtime.\r\n * If the discovery was successful, the remote services can be retrieved using the getServices function.\r\n * Not available on **web**.\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n */\r\n discoverServices(deviceId: string): Promise<void>;\r\n\r\n /**\r\n * Get the MTU of a connected device. Note that the maximum write value length is 3 bytes less than the MTU.\r\n * Not available on **web**.\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n */\r\n getMtu(deviceId: string): Promise<number>;\r\n\r\n /**\r\n * Request a connection parameter update.\r\n * Only available on **Android**. https://developer.android.com/reference/android/bluetooth/BluetoothGatt#requestConnectionPriority(int)\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n * @param connectionPriority Request a specific connection priority. See [ConnectionPriority](#connectionpriority)\r\n */\r\n requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void>;\r\n\r\n /**\r\n * Read the RSSI value of a connected device.\r\n * Not available on **web**.\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n */\r\n readRssi(deviceId: string): Promise<number>;\r\n\r\n /**\r\n * Read the value of a characteristic. For an example, see [usage](#usage).\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n * @param service UUID of the service (see [UUID format](#uuid-format))\r\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\r\n * @param options Options for plugin call\r\n */\r\n read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView>;\r\n\r\n /**\r\n * Write a value to a characteristic. For an example, see [usage](#usage).\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n * @param service UUID of the service (see [UUID format](#uuid-format))\r\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\r\n * @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])\r\n * @param options Options for plugin call\r\n */\r\n write(\r\n deviceId: string,\r\n service: string,\r\n characteristic: string,\r\n value: DataView,\r\n options?: TimeoutOptions,\r\n ): Promise<void>;\r\n\r\n /**\r\n * Write a value to a characteristic without waiting for a response.\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n * @param service UUID of the service (see [UUID format](#uuid-format))\r\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\r\n * @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])\r\n * @param options Options for plugin call\r\n */\r\n writeWithoutResponse(\r\n deviceId: string,\r\n service: string,\r\n characteristic: string,\r\n value: DataView,\r\n options?: TimeoutOptions,\r\n ): Promise<void>;\r\n\r\n /**\r\n * Read the value of a descriptor.\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n * @param service UUID of the service (see [UUID format](#uuid-format))\r\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\r\n * @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))\r\n * @param options Options for plugin call\r\n */\r\n readDescriptor(\r\n deviceId: string,\r\n service: string,\r\n characteristic: string,\r\n descriptor: string,\r\n options?: TimeoutOptions,\r\n ): Promise<DataView>;\r\n\r\n /**\r\n * Write a value to a descriptor.\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n * @param service UUID of the service (see [UUID format](#uuid-format))\r\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\r\n * @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))\r\n * @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])\r\n * @param options Options for plugin call\r\n */\r\n writeDescriptor(\r\n deviceId: string,\r\n service: string,\r\n characteristic: string,\r\n descriptor: string,\r\n value: DataView,\r\n options?: TimeoutOptions,\r\n ): Promise<void>;\r\n\r\n /**\r\n * Start listening to changes of the value of a characteristic.\r\n * Note that you should only start the notifications once per characteristic in your app and share the data and\r\n * not call `startNotifications` in every component that needs the data.\r\n * For an example, see [usage](#usage).\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n * @param service UUID of the service (see [UUID format](#uuid-format))\r\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\r\n * @param callback Callback function to use when the value of the characteristic changes\r\n * @param options Options for plugin call. Timeout not supported on **web**.\r\n */\r\n startNotifications(\r\n deviceId: string,\r\n service: string,\r\n characteristic: string,\r\n callback: (value: DataView) => void,\r\n options?: TimeoutOptions,\r\n ): Promise<void>;\r\n\r\n /**\r\n * Stop listening to the changes of the value of a characteristic. For an example, see [usage](#usage).\r\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\r\n * @param service UUID of the service (see [UUID format](#uuid-format))\r\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\r\n */\r\n stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void>;\r\n}\r\n\r\nclass BleClientClass implements BleClientInterface {\r\n private scanListener: PluginListenerHandle | null = null;\r\n private eventListeners = new Map<string, PluginListenerHandle>();\r\n private queue = getQueue(true);\r\n\r\n enableQueue() {\r\n this.queue = getQueue(true);\r\n }\r\n\r\n disableQueue() {\r\n this.queue = getQueue(false);\r\n }\r\n\r\n async initialize(options?: InitializeOptions): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.initialize(options);\r\n });\r\n }\r\n\r\n async isEnabled(): Promise<boolean> {\r\n const enabled = await this.queue(async () => {\r\n const result = await BluetoothLe.isEnabled();\r\n return result.value;\r\n });\r\n return enabled;\r\n }\r\n\r\n async requestEnable(): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.requestEnable();\r\n });\r\n }\r\n\r\n async enable(): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.enable();\r\n });\r\n }\r\n\r\n async disable(): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.disable();\r\n });\r\n }\r\n\r\n async startEnabledNotifications(callback: (value: boolean) => void): Promise<void> {\r\n await this.queue(async () => {\r\n const key = `onEnabledChanged`;\r\n await this.eventListeners.get(key)?.remove();\r\n const listener = await BluetoothLe.addListener(key, (result) => {\r\n callback(result.value);\r\n });\r\n this.eventListeners.set(key, listener);\r\n await BluetoothLe.startEnabledNotifications();\r\n });\r\n }\r\n\r\n async stopEnabledNotifications(): Promise<void> {\r\n await this.queue(async () => {\r\n const key = `onEnabledChanged`;\r\n await this.eventListeners.get(key)?.remove();\r\n this.eventListeners.delete(key);\r\n await BluetoothLe.stopEnabledNotifications();\r\n });\r\n }\r\n\r\n async isLocationEnabled(): Promise<boolean> {\r\n const enabled = await this.queue(async () => {\r\n const result = await BluetoothLe.isLocationEnabled();\r\n return result.value;\r\n });\r\n return enabled;\r\n }\r\n\r\n async openLocationSettings(): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.openLocationSettings();\r\n });\r\n }\r\n\r\n async openBluetoothSettings(): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.openBluetoothSettings();\r\n });\r\n }\r\n\r\n async openAppSettings(): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.openAppSettings();\r\n });\r\n }\r\n\r\n async setDisplayStrings(displayStrings: DisplayStrings): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.setDisplayStrings(displayStrings);\r\n });\r\n }\r\n\r\n async requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice> {\r\n options = options ? this.validateRequestBleDeviceOptions(options) : undefined;\r\n const result = await this.queue(async () => {\r\n const device = await BluetoothLe.requestDevice(options);\r\n return device;\r\n });\r\n return result;\r\n }\r\n\r\n async requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void> {\r\n options = this.validateRequestBleDeviceOptions(options);\r\n await this.queue(async () => {\r\n await this.scanListener?.remove();\r\n this.scanListener = await BluetoothLe.addListener('onScanResult', (resultInternal: ScanResultInternal) => {\r\n const result: ScanResult = {\r\n ...resultInternal,\r\n manufacturerData: this.convertObject(resultInternal.manufacturerData),\r\n serviceData: this.convertObject(resultInternal.serviceData),\r\n rawAdvertisement: resultInternal.rawAdvertisement\r\n ? this.convertValue(resultInternal.rawAdvertisement)\r\n : undefined,\r\n };\r\n callback(result);\r\n });\r\n await BluetoothLe.requestLEScan(options);\r\n });\r\n }\r\n\r\n async stopLEScan(): Promise<void> {\r\n await this.queue(async () => {\r\n await this.scanListener?.remove();\r\n this.scanListener = null;\r\n await BluetoothLe.stopLEScan();\r\n });\r\n }\r\n\r\n async getDevices(deviceIds: string[]): Promise<BleDevice[]> {\r\n if (!Array.isArray(deviceIds)) {\r\n throw new Error('deviceIds must be an array');\r\n }\r\n return this.queue(async () => {\r\n const result = await BluetoothLe.getDevices({ deviceIds });\r\n return result.devices;\r\n });\r\n }\r\n\r\n async getConnectedDevices(services: string[]): Promise<BleDevice[]> {\r\n if (!Array.isArray(services)) {\r\n throw new Error('services must be an array');\r\n }\r\n services = services.map(parseUUID);\r\n return this.queue(async () => {\r\n const result = await BluetoothLe.getConnectedDevices({ services });\r\n return result.devices;\r\n });\r\n }\r\n\r\n async getBondedDevices(): Promise<BleDevice[]> {\r\n return this.queue(async () => {\r\n const result = await BluetoothLe.getBondedDevices();\r\n return result.devices;\r\n });\r\n }\r\n\r\n async connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void> {\r\n await this.queue(async () => {\r\n if (onDisconnect) {\r\n const key = `disconnected|${deviceId}`;\r\n await this.eventListeners.get(key)?.remove();\r\n const listener = await BluetoothLe.addListener(key, () => {\r\n onDisconnect(deviceId);\r\n });\r\n this.eventListeners.set(key, listener);\r\n }\r\n await BluetoothLe.connect({ deviceId, ...options });\r\n });\r\n }\r\n\r\n async createBond(deviceId: string, options?: TimeoutOptions): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.createBond({ deviceId, ...options });\r\n });\r\n }\r\n\r\n async isBonded(deviceId: string): Promise<boolean> {\r\n const isBonded = await this.queue(async () => {\r\n const result = await BluetoothLe.isBonded({ deviceId });\r\n return result.value;\r\n });\r\n return isBonded;\r\n }\r\n\r\n async disconnect(deviceId: string): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.disconnect({ deviceId });\r\n });\r\n }\r\n\r\n async getServices(deviceId: string): Promise<BleService[]> {\r\n const services = await this.queue(async () => {\r\n const result = await BluetoothLe.getServices({ deviceId });\r\n return result.services;\r\n });\r\n return services;\r\n }\r\n\r\n async discoverServices(deviceId: string): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.discoverServices({ deviceId });\r\n });\r\n }\r\n\r\n async getMtu(deviceId: string): Promise<number> {\r\n const value = await this.queue(async () => {\r\n const result = await BluetoothLe.getMtu({ deviceId });\r\n return result.value;\r\n });\r\n return value;\r\n }\r\n\r\n async requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void> {\r\n await this.queue(async () => {\r\n await BluetoothLe.requestConnectionPriority({ deviceId, connectionPriority });\r\n });\r\n }\r\n\r\n async readRssi(deviceId: string): Promise<number> {\r\n const value = await this.queue(async () => {\r\n const result = await BluetoothLe.readRssi({ deviceId });\r\n return parseFloat(result.value);\r\n });\r\n return value;\r\n }\r\n\r\n async read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView> {\r\n service = parseUUID(service);\r\n characteristic = parseUUID(characteristic);\r\n const value = await this.queue(async () => {\r\n const result = await BluetoothLe.read({\r\n deviceId,\r\n service,\r\n characteristic,\r\n ...options,\r\n });\r\n return this.convertValue(result.value);\r\n });\r\n return value;\r\n }\r\n\r\n async write(\r\n deviceId: string,\r\n service: string,\r\n characteristic: string,\r\n value: DataView,\r\n options?: TimeoutOptions,\r\n ): Promise<void> {\r\n service = parseUUID(service);\r\n characteristic = parseUUID(characteristic);\r\n return this.queue(async () => {\r\n if (!value?.buffer) {\r\n throw new Error('Invalid data.');\r\n }\r\n let writeValue: DataView | string = value;\r\n if (Capacitor.getPlatform() !== 'web') {\r\n // on native we can only write strings\r\n writeValue = dataViewToHexString(value);\r\n }\r\n await BluetoothLe.write({\r\n deviceId,\r\n service,\r\n characteristic,\r\n value: writeValue,\r\n ...options,\r\n });\r\n });\r\n }\r\n\r\n async writeWithoutResponse(\r\n deviceId: string,\r\n service: string,\r\n characteristic: string,\r\n value: DataView,\r\n options?: TimeoutOptions,\r\n ): Promise<void> {\r\n service = parseUUID(service);\r\n characteristic = parseUUID(characteristic);\r\n await this.queue(async () => {\r\n if (!value?.buffer) {\r\n throw new Error('Invalid data.');\r\n }\r\n let writeValue: DataView | string = value;\r\n if (Capacitor.getPlatform() !== 'web') {\r\n // on native we can only write strings\r\n writeValue = dataViewToHexString(value);\r\n }\r\n await BluetoothLe.writeWithoutResponse({\r\n deviceId,\r\n service,\r\n characteristic,\r\n value: writeValue,\r\n ...options,\r\n });\r\n });\r\n }\r\n\r\n async readDescriptor(\r\n deviceId: string,\r\n service: string,\r\n characteristic: string,\r\n descriptor: string,\r\n options?: TimeoutOptions,\r\n ): Promise<DataView> {\r\n service = parseUUID(service);\r\n characteristic = parseUUID(characteristic);\r\n descriptor = parseUUID(descriptor);\r\n const value = await this.queue(async () => {\r\n const result = await BluetoothLe.readDescriptor({\r\n deviceId,\r\n service,\r\n characteristic,\r\n descriptor,\r\n ...options,\r\n });\r\n return this.convertValue(result.value);\r\n });\r\n return value;\r\n }\r\n\r\n async writeDescriptor(\r\n deviceId: string,\r\n service: string,\r\n characteristic: string,\r\n descriptor: string,\r\n value: DataView,\r\n options?: TimeoutOptions,\r\n ): Promise<void> {\r\n service = parseUUID(service);\r\n characteristic = parseUUID(characteristic);\r\n descriptor = parseUUID(descriptor);\r\n return this.queue(async () => {\r\n if (!value?.buffer) {\r\n throw new Error('Invalid data.');\r\n }\r\n let writeValue: DataView | string = value;\r\n if (Capacitor.getPlatform() !== 'web') {\r\n // on native we can only write strings\r\n writeValue = dataViewToHexString(value);\r\n }\r\n await BluetoothLe.writeDescriptor({\r\n deviceId,\r\n service,\r\n characteristic,\r\n descriptor,\r\n value: writeValue,\r\n ...options,\r\n });\r\n });\r\n }\r\n\r\n async startNotifications(\r\n deviceId: string,\r\n service: string,\r\n characteristic: string,\r\n callback: (value: DataView) => void,\r\n options?: TimeoutOptions,\r\n ): Promise<void> {\r\n service = parseUUID(service);\r\n characteristic = parseUUID(characteristic);\r\n await this.queue(async () => {\r\n const key = `notification|${deviceId}|${service}|${characteristic}`;\r\n await this.eventListeners.get(key)?.remove();\r\n const listener = await BluetoothLe.addListener(key, (event: ReadResult) => {\r\n callback(this.convertValue(event?.value));\r\n });\r\n this.eventListeners.set(key, listener);\r\n await BluetoothLe.startNotifications({\r\n deviceId,\r\n service,\r\n characteristic,\r\n ...options,\r\n });\r\n });\r\n }\r\n\r\n async stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void> {\r\n service = parseUUID(service);\r\n characteristic = parseUUID(characteristic);\r\n await this.queue(async () => {\r\n const key = `notification|${deviceId}|${service}|${characteristic}`;\r\n await this.eventListeners.get(key)?.remove();\r\n this.eventListeners.delete(key);\r\n await BluetoothLe.stopNotifications({\r\n deviceId,\r\n service,\r\n characteristic,\r\n });\r\n });\r\n }\r\n\r\n private validateRequestBleDeviceOptions(options: RequestBleDeviceOptions): RequestBleDeviceOptions {\r\n options = { ...options };\r\n if (options.services) {\r\n options.services = options.services.map(parseUUID);\r\n }\r\n if (options.optionalServices) {\r\n options.optionalServices = options.optionalServices.map(parseUUID);\r\n }\r\n if (options.serviceData && Capacitor.getPlatform() !== 'web') {\r\n // Native platforms: convert to hex strings\r\n options.serviceData = options.serviceData.map((filter) => ({\r\n ...filter,\r\n serviceUuid: parseUUID(filter.serviceUuid),\r\n dataPrefix: toHexString(filter.dataPrefix),\r\n mask: toHexString(filter.mask),\r\n })) as any;\r\n }\r\n if (options.manufacturerData) {\r\n if (Capacitor.getPlatform() !== 'web') {\r\n // Native platforms: convert to hex strings\r\n options.manufacturerData = options.manufacturerData.map((filter) => ({\r\n ...filter,\r\n dataPrefix: toHexString(filter.dataPrefix),\r\n mask: toHexString(filter.mask),\r\n })) as any;\r\n } else {\r\n // Web platform: convert to Uint8Array for Web Bluetooth API\r\n options.manufacturerData = options.manufacturerData.map((filter) => ({\r\n ...filter,\r\n dataPrefix: toUint8Array(filter.dataPrefix),\r\n mask: toUint8Array(filter.mask),\r\n }));\r\n }\r\n }\r\n return options;\r\n }\r\n\r\n private convertValue(value?: Data): DataView {\r\n if (typeof value === 'string') {\r\n return hexStringToDataView(value);\r\n } else if (value === undefined) {\r\n return new DataView(new ArrayBuffer(0));\r\n }\r\n return value;\r\n }\r\n\r\n private convertObject(obj?: { [key: string]: Data }): { [key: string]: DataView } | undefined {\r\n if (obj === undefined) {\r\n return undefined;\r\n }\r\n const result: { [key: string]: DataView } = {};\r\n for (const key of Object.keys(obj)) {\r\n result[key] = this.convertValue(obj[key]);\r\n }\r\n return result;\r\n }\r\n}\r\n\r\nexport const BleClient = new BleClientClass();\r\n"]}
|