@capacitor-community/bluetooth-le 7.1.0 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -12
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/BluetoothLe.kt +7 -0
- package/dist/docs.json +35 -1
- package/dist/esm/definitions.d.ts +17 -5
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +39 -41
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +39 -41
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<a href="https://www.npmjs.com/package/@capacitor-community/bluetooth-le"><img src="https://img.shields.io/npm/dw/@capacitor-community/bluetooth-le?style=flat-square" /></a>
|
|
14
14
|
<a href="https://www.npmjs.com/package/@capacitor-community/bluetooth-le"><img src="https://img.shields.io/npm/v/@capacitor-community/bluetooth-le?style=flat-square" /></a>
|
|
15
15
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
16
|
-
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-
|
|
16
|
+
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-23-orange?style=flat-square" /></a>
|
|
17
17
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
18
18
|
</p>
|
|
19
19
|
|
|
@@ -255,7 +255,7 @@ export async function main(): Promise<void> {
|
|
|
255
255
|
HEART_RATE_MEASUREMENT_CHARACTERISTIC,
|
|
256
256
|
(value) => {
|
|
257
257
|
console.log('current heart rate', parseHeartRate(value));
|
|
258
|
-
}
|
|
258
|
+
},
|
|
259
259
|
);
|
|
260
260
|
|
|
261
261
|
// disconnect after 10 sec
|
|
@@ -305,7 +305,7 @@ export async function scan(): Promise<void> {
|
|
|
305
305
|
},
|
|
306
306
|
(result) => {
|
|
307
307
|
console.log('received new scan result', result);
|
|
308
|
-
}
|
|
308
|
+
},
|
|
309
309
|
);
|
|
310
310
|
|
|
311
311
|
setTimeout(async () => {
|
|
@@ -928,15 +928,23 @@ Stop listening to the changes of the value of a characteristic. For an example,
|
|
|
928
928
|
|
|
929
929
|
#### RequestBleDeviceOptions
|
|
930
930
|
|
|
931
|
-
| Prop | Type
|
|
932
|
-
| ---------------------- |
|
|
933
|
-
| **`services`** | <code>string[]</code>
|
|
934
|
-
| **`name`** | <code>string</code>
|
|
935
|
-
| **`namePrefix`** | <code>string</code>
|
|
936
|
-
| **`optionalServices`** | <code>string[]</code>
|
|
937
|
-
| **`allowDuplicates`** | <code>boolean</code>
|
|
938
|
-
| **`scanMode`** | <code><a href="#scanmode">ScanMode</a></code>
|
|
939
|
-
| **`manufacturerData`** | <code>
|
|
931
|
+
| Prop | Type | Description |
|
|
932
|
+
| ---------------------- | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
933
|
+
| **`services`** | <code>string[]</code> | Filter devices by service UUIDs. UUIDs have to be specified as 128 bit UUID strings, e.g. ['0000180d-0000-1000-8000-00805f9b34fb'] There is a helper function to convert numbers to UUIDs. e.g. [numberToUUID(0x180f)]. (see [UUID format](#uuid-format)) |
|
|
934
|
+
| **`name`** | <code>string</code> | Filter devices by name |
|
|
935
|
+
| **`namePrefix`** | <code>string</code> | Filter devices by name prefix |
|
|
936
|
+
| **`optionalServices`** | <code>string[]</code> | For **web**, all services that will be used have to be listed under services or optionalServices, e.g. [numberToUUID(0x180f)] (see [UUID format](#uuid-format)) |
|
|
937
|
+
| **`allowDuplicates`** | <code>boolean</code> | Normally scans will discard the second and subsequent advertisements from a single device. If you need to receive them, set allowDuplicates to true (only applicable in `requestLEScan`). (default: false) |
|
|
938
|
+
| **`scanMode`** | <code><a href="#scanmode">ScanMode</a></code> | Android scan mode (default: <a href="#scanmode">ScanMode.SCAN_MODE_BALANCED</a>) |
|
|
939
|
+
| **`manufacturerData`** | <code>ManufacturerDataFilter[]</code> | Allow scanning for devices with a specific manufacturer data https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice#manufacturerdata |
|
|
940
|
+
|
|
941
|
+
#### ManufacturerDataFilter
|
|
942
|
+
|
|
943
|
+
| Prop | Type | Description |
|
|
944
|
+
| ----------------------- | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
945
|
+
| **`companyIdentifier`** | <code>number</code> | Company ID (sometimes called the manufacturer ID) to search for in the manufacturer data field. |
|
|
946
|
+
| **`dataPrefix`** | <code><a href="#uint8array">Uint8Array</a></code> | Prefix to match in the manufacturer data field. On **Android** this field is mandatory. |
|
|
947
|
+
| **`mask`** | <code><a href="#uint8array">Uint8Array</a></code> | 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. The `mask` must have the same length of dataPrefix. |
|
|
940
948
|
|
|
941
949
|
#### Uint8Array
|
|
942
950
|
|
|
@@ -1201,6 +1209,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
1201
1209
|
</tr>
|
|
1202
1210
|
<tr>
|
|
1203
1211
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/gion-andri"><img src="https://avatars.githubusercontent.com/u/540998?v=4?s=100" width="100px;" alt="Gion-Andri Cantieni"/><br /><sub><b>Gion-Andri Cantieni</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=gion-andri" title="Code">💻</a></td>
|
|
1212
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/JasonAsmk"><img src="https://avatars.githubusercontent.com/u/994111?v=4?s=100" width="100px;" alt="Iason Asimakopoulos"/><br /><sub><b>Iason Asimakopoulos</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=JasonAsmk" title="Code">💻</a></td>
|
|
1204
1213
|
</tr>
|
|
1205
1214
|
</tbody>
|
|
1206
1215
|
</table>
|
|
@@ -874,6 +874,13 @@ class BluetoothLe : Plugin() {
|
|
|
874
874
|
filters.add(filterBuilder.build())
|
|
875
875
|
}
|
|
876
876
|
}
|
|
877
|
+
// Create filters when providing only name
|
|
878
|
+
if (name != null && filters.isEmpty()) {
|
|
879
|
+
val filterBuilder = ScanFilter.Builder()
|
|
880
|
+
filterBuilder.setDeviceName(name)
|
|
881
|
+
filters.add(filterBuilder.build())
|
|
882
|
+
}
|
|
883
|
+
|
|
877
884
|
return filters;
|
|
878
885
|
} catch (e: IllegalArgumentException) {
|
|
879
886
|
call.reject("Invalid UUID or Manufacturer data provided.")
|
package/dist/docs.json
CHANGED
|
@@ -1113,10 +1113,44 @@
|
|
|
1113
1113
|
"name": "manufacturerData",
|
|
1114
1114
|
"tags": [],
|
|
1115
1115
|
"docs": "Allow scanning for devices with a specific manufacturer data\r\nhttps://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice#manufacturerdata",
|
|
1116
|
+
"complexTypes": [
|
|
1117
|
+
"ManufacturerDataFilter"
|
|
1118
|
+
],
|
|
1119
|
+
"type": "ManufacturerDataFilter[] | undefined"
|
|
1120
|
+
}
|
|
1121
|
+
]
|
|
1122
|
+
},
|
|
1123
|
+
{
|
|
1124
|
+
"name": "ManufacturerDataFilter",
|
|
1125
|
+
"slug": "manufacturerdatafilter",
|
|
1126
|
+
"docs": "",
|
|
1127
|
+
"tags": [],
|
|
1128
|
+
"methods": [],
|
|
1129
|
+
"properties": [
|
|
1130
|
+
{
|
|
1131
|
+
"name": "companyIdentifier",
|
|
1132
|
+
"tags": [],
|
|
1133
|
+
"docs": "Company ID (sometimes called the manufacturer ID) to search for in the manufacturer data field.",
|
|
1134
|
+
"complexTypes": [],
|
|
1135
|
+
"type": "number"
|
|
1136
|
+
},
|
|
1137
|
+
{
|
|
1138
|
+
"name": "dataPrefix",
|
|
1139
|
+
"tags": [],
|
|
1140
|
+
"docs": "Prefix to match in the manufacturer data field.\r\nOn **Android** this field is mandatory.",
|
|
1141
|
+
"complexTypes": [
|
|
1142
|
+
"Uint8Array"
|
|
1143
|
+
],
|
|
1144
|
+
"type": "Uint8Array"
|
|
1145
|
+
},
|
|
1146
|
+
{
|
|
1147
|
+
"name": "mask",
|
|
1148
|
+
"tags": [],
|
|
1149
|
+
"docs": "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.\r\nThe `mask` must have the same length of dataPrefix.",
|
|
1116
1150
|
"complexTypes": [
|
|
1117
1151
|
"Uint8Array"
|
|
1118
1152
|
],
|
|
1119
|
-
"type": "
|
|
1153
|
+
"type": "Uint8Array"
|
|
1120
1154
|
}
|
|
1121
1155
|
]
|
|
1122
1156
|
},
|
|
@@ -47,11 +47,7 @@ export interface RequestBleDeviceOptions {
|
|
|
47
47
|
* Allow scanning for devices with a specific manufacturer data
|
|
48
48
|
* https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice#manufacturerdata
|
|
49
49
|
*/
|
|
50
|
-
manufacturerData?:
|
|
51
|
-
companyIdentifier: number;
|
|
52
|
-
dataPrefix?: Uint8Array;
|
|
53
|
-
mask?: Uint8Array;
|
|
54
|
-
}[];
|
|
50
|
+
manufacturerData?: ManufacturerDataFilter[];
|
|
55
51
|
}
|
|
56
52
|
/**
|
|
57
53
|
* Android scan mode
|
|
@@ -93,6 +89,22 @@ export declare enum ConnectionPriority {
|
|
|
93
89
|
*/
|
|
94
90
|
CONNECTION_PRIORITY_LOW_POWER = 2
|
|
95
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
|
+
}
|
|
96
108
|
export interface BleDevice {
|
|
97
109
|
/**
|
|
98
110
|
* ID of the device, which will be needed for further calls.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAuDA;;GAEG;AACH,MAAM,CAAN,IAAY,QAgBX;AAhBD,WAAY,QAAQ;IAClB;;;OAGG;IACH,qEAAuB,CAAA;IACvB;;;OAGG;IACH,mEAAsB,CAAA;IACtB;;;OAGG;IACH,yEAAyB,CAAA;AAC3B,CAAC,EAhBW,QAAQ,KAAR,QAAQ,QAgBnB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,kBAgBX;AAhBD,WAAY,kBAAkB;IAC5B;;;OAGG;IACH,2GAAgC,CAAA;IAChC;;;OAGG;IACH,mGAA4B,CAAA;IAC5B;;;OAGG;IACH,6GAAiC,CAAA;AACnC,CAAC,EAhBW,kBAAkB,KAAlB,kBAAkB,QAgB7B","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\r\n\r\nimport type { DisplayStrings } from './config';\r\n\r\nexport interface InitializeOptions {\r\n /**\r\n * If your app doesn't use Bluetooth scan results to derive physical\r\n * location information, you can strongly assert that your app\r\n * doesn't derive physical location. (Android only)\r\n * Requires adding 'neverForLocation' to AndroidManifest.xml\r\n * https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location\r\n * @default false\r\n */\r\n androidNeverForLocation?: boolean;\r\n}\r\n\r\nexport interface RequestBleDeviceOptions {\r\n /**\r\n * Filter devices by service UUIDs.\r\n * UUIDs have to be specified as 128 bit UUID strings,\r\n * e.g. ['0000180d-0000-1000-8000-00805f9b34fb']\r\n * There is a helper function to convert numbers to UUIDs.\r\n * e.g. [numberToUUID(0x180f)]. (see [UUID format](#uuid-format))\r\n */\r\n services?: string[];\r\n /**\r\n * Filter devices by name\r\n */\r\n name?: string;\r\n /**\r\n * Filter devices by name prefix\r\n */\r\n namePrefix?: string;\r\n /**\r\n * For **web**, all services that will be used have to be listed under services or optionalServices,\r\n * e.g. [numberToUUID(0x180f)] (see [UUID format](#uuid-format))\r\n */\r\n optionalServices?: string[];\r\n /**\r\n * Normally scans will discard the second and subsequent advertisements from a single device.\r\n * If you need to receive them, set allowDuplicates to true (only applicable in `requestLEScan`).\r\n * (default: false)\r\n */\r\n allowDuplicates?: boolean;\r\n /**\r\n * Android scan mode (default: ScanMode.SCAN_MODE_BALANCED)\r\n */\r\n scanMode?: ScanMode;\r\n /**\r\n * Allow scanning for devices with a specific manufacturer data\r\n * https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice#manufacturerdata\r\n */\r\n manufacturerData?: { companyIdentifier: number; dataPrefix?: Uint8Array; mask?: Uint8Array }[];\r\n}\r\n\r\n/**\r\n * Android scan mode\r\n */\r\nexport enum ScanMode {\r\n /**\r\n * Perform Bluetooth LE scan in low power mode. This mode is enforced if the scanning application is not in foreground.\r\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_POWER\r\n */\r\n SCAN_MODE_LOW_POWER = 0,\r\n /**\r\n * 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.\r\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_BALANCED\r\n */\r\n SCAN_MODE_BALANCED = 1,\r\n /**\r\n * Scan using highest duty cycle. It's recommended to only use this mode when the application is running in the foreground.\r\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_LATENCY\r\n */\r\n SCAN_MODE_LOW_LATENCY = 2,\r\n}\r\n\r\n/**\r\n * Android connection priority used in `requestConnectionPriority`\r\n */\r\nexport enum ConnectionPriority {\r\n /**\r\n * Use the connection parameters recommended by the Bluetooth SIG. This is the default value if no connection parameter update is requested.\r\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_BALANCED\r\n */\r\n CONNECTION_PRIORITY_BALANCED = 0,\r\n /**\r\n * 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.\r\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_HIGH\r\n */\r\n CONNECTION_PRIORITY_HIGH = 1,\r\n /**\r\n * Request low power, reduced data rate connection parameters.\r\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER\r\n */\r\n CONNECTION_PRIORITY_LOW_POWER = 2,\r\n}\r\n\r\nexport interface BleDevice {\r\n /**\r\n * ID of the device, which will be needed for further calls.\r\n * On **Android** this is the BLE MAC address.\r\n * On **iOS** and **web** it is an identifier.\r\n */\r\n deviceId: string;\r\n /**\r\n * Name of the peripheral device.\r\n */\r\n name?: string;\r\n uuids?: string[];\r\n}\r\n\r\nexport interface DeviceIdOptions {\r\n deviceId: string;\r\n}\r\nexport interface TimeoutOptions {\r\n /**\r\n * Timeout in milliseconds for plugin call.\r\n * Default is 10000 for `connect` and 5000 for other plugin methods.\r\n */\r\n timeout?: number;\r\n}\r\n\r\nexport interface RequestConnectionPriorityOptions extends DeviceIdOptions {\r\n connectionPriority: ConnectionPriority;\r\n}\r\n\r\nexport interface GetDevicesOptions {\r\n deviceIds: string[];\r\n}\r\n\r\nexport interface GetConnectedDevicesOptions {\r\n services: string[];\r\n}\r\n\r\nexport interface BleService {\r\n readonly uuid: string;\r\n readonly characteristics: BleCharacteristic[];\r\n}\r\n\r\nexport interface BleDescriptor {\r\n readonly uuid: string;\r\n}\r\n\r\nexport interface BleCharacteristic {\r\n readonly uuid: string;\r\n readonly properties: BleCharacteristicProperties;\r\n readonly descriptors: BleDescriptor[];\r\n}\r\n\r\nexport interface BleCharacteristicProperties {\r\n readonly broadcast: boolean;\r\n readonly read: boolean;\r\n readonly writeWithoutResponse: boolean;\r\n readonly write: boolean;\r\n readonly notify: boolean;\r\n readonly indicate: boolean;\r\n readonly authenticatedSignedWrites: boolean;\r\n readonly reliableWrite?: boolean;\r\n readonly writableAuxiliaries?: boolean;\r\n readonly extendedProperties?: boolean;\r\n readonly notifyEncryptionRequired?: boolean;\r\n readonly indicateEncryptionRequired?: boolean;\r\n}\r\n\r\nexport interface BleServices {\r\n services: BleService[];\r\n}\r\n\r\nexport interface ReadOptions {\r\n deviceId: string;\r\n service: string;\r\n characteristic: string;\r\n}\r\n\r\nexport interface ReadDescriptorOptions {\r\n deviceId: string;\r\n service: string;\r\n characteristic: string;\r\n descriptor: string;\r\n}\r\n\r\nexport type Data = DataView | string;\r\n\r\nexport interface WriteOptions {\r\n deviceId: string;\r\n service: string;\r\n characteristic: string;\r\n /**\r\n * android, ios: string\r\n * web: DataView\r\n */\r\n value: Data;\r\n}\r\n\r\nexport interface WriteDescriptorOptions {\r\n deviceId: string;\r\n service: string;\r\n characteristic: string;\r\n descriptor: string;\r\n /**\r\n * android, ios: string\r\n * web: DataView\r\n */\r\n value: Data;\r\n}\r\n\r\nexport interface BooleanResult {\r\n value: boolean;\r\n}\r\n\r\nexport interface GetDevicesResult {\r\n devices: BleDevice[];\r\n}\r\n\r\nexport interface GetMtuResult {\r\n value: number;\r\n}\r\n\r\nexport interface ReadRssiResult {\r\n value: string;\r\n}\r\n\r\nexport interface ReadResult {\r\n /**\r\n * android, ios: string\r\n * web: DataView\r\n */\r\n value?: Data;\r\n}\r\n\r\nexport interface ScanResultInternal<T = Data> {\r\n device: BleDevice;\r\n localName?: string;\r\n rssi?: number;\r\n txPower?: number;\r\n manufacturerData?: { [key: string]: T };\r\n serviceData?: { [key: string]: T };\r\n uuids?: string[];\r\n rawAdvertisement?: T;\r\n}\r\n\r\nexport interface ScanResult {\r\n /**\r\n * The peripheral device that was found in the scan.\r\n * **Android** and **web**: `device.name` is always identical to `localName`.\r\n * **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.\r\n */\r\n device: BleDevice;\r\n /**\r\n * The name of the peripheral device from the advertisement data.\r\n */\r\n localName?: string;\r\n /**\r\n * Received Signal Strength Indication.\r\n */\r\n rssi?: number;\r\n /**\r\n * Transmit power in dBm. A value of 127 indicates that it is not available.\r\n */\r\n txPower?: number;\r\n /**\r\n * Manufacturer data, key is a company identifier and value is the data.\r\n */\r\n manufacturerData?: { [key: string]: DataView };\r\n /**\r\n * Service data, key is a service UUID and value is the data.\r\n */\r\n serviceData?: { [key: string]: DataView };\r\n /**\r\n * Advertised services.\r\n */\r\n uuids?: string[];\r\n /**\r\n * Raw advertisement data (**Android** only).\r\n */\r\n rawAdvertisement?: DataView;\r\n}\r\n\r\nexport interface BluetoothLePlugin {\r\n initialize(options?: InitializeOptions): Promise<void>;\r\n isEnabled(): Promise<BooleanResult>;\r\n requestEnable(): Promise<void>;\r\n enable(): Promise<void>;\r\n disable(): Promise<void>;\r\n startEnabledNotifications(): Promise<void>;\r\n stopEnabledNotifications(): Promise<void>;\r\n isLocationEnabled(): Promise<BooleanResult>;\r\n openLocationSettings(): Promise<void>;\r\n openBluetoothSettings(): Promise<void>;\r\n openAppSettings(): Promise<void>;\r\n setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;\r\n requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;\r\n requestLEScan(options?: RequestBleDeviceOptions): Promise<void>;\r\n stopLEScan(): Promise<void>;\r\n getDevices(options: GetDevicesOptions): Promise<GetDevicesResult>;\r\n getConnectedDevices(options: GetConnectedDevicesOptions): Promise<GetDevicesResult>;\r\n getBondedDevices(): Promise<GetDevicesResult>;\r\n addListener(\r\n eventName: 'onEnabledChanged',\r\n listenerFunc: (result: BooleanResult) => void,\r\n ): Promise<PluginListenerHandle>;\r\n addListener(eventName: string, listenerFunc: (event: ReadResult) => void): Promise<PluginListenerHandle>;\r\n addListener(\r\n eventName: 'onScanResult',\r\n listenerFunc: (result: ScanResultInternal) => void,\r\n ): Promise<PluginListenerHandle>;\r\n connect(options: DeviceIdOptions & TimeoutOptions): Promise<void>;\r\n createBond(options: DeviceIdOptions & TimeoutOptions): Promise<void>;\r\n isBonded(options: DeviceIdOptions): Promise<BooleanResult>;\r\n disconnect(options: DeviceIdOptions): Promise<void>;\r\n getServices(options: DeviceIdOptions): Promise<BleServices>;\r\n discoverServices(options: DeviceIdOptions): Promise<void>;\r\n getMtu(options: DeviceIdOptions): Promise<GetMtuResult>;\r\n requestConnectionPriority(options: RequestConnectionPriorityOptions): Promise<void>;\r\n readRssi(options: DeviceIdOptions): Promise<ReadRssiResult>;\r\n read(options: ReadOptions & TimeoutOptions): Promise<ReadResult>;\r\n write(options: WriteOptions & TimeoutOptions): Promise<void>;\r\n writeWithoutResponse(options: WriteOptions & TimeoutOptions): Promise<void>;\r\n readDescriptor(options: ReadDescriptorOptions & TimeoutOptions): Promise<ReadResult>;\r\n writeDescriptor(options: WriteDescriptorOptions & TimeoutOptions): Promise<void>;\r\n startNotifications(options: ReadOptions): Promise<void>;\r\n stopNotifications(options: ReadOptions): Promise<void>;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAuDA;;GAEG;AACH,MAAM,CAAN,IAAY,QAgBX;AAhBD,WAAY,QAAQ;IAClB;;;OAGG;IACH,qEAAuB,CAAA;IACvB;;;OAGG;IACH,mEAAsB,CAAA;IACtB;;;OAGG;IACH,yEAAyB,CAAA;AAC3B,CAAC,EAhBW,QAAQ,KAAR,QAAQ,QAgBnB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,kBAgBX;AAhBD,WAAY,kBAAkB;IAC5B;;;OAGG;IACH,2GAAgC,CAAA;IAChC;;;OAGG;IACH,mGAA4B,CAAA;IAC5B;;;OAGG;IACH,6GAAiC,CAAA;AACnC,CAAC,EAhBW,kBAAkB,KAAlB,kBAAkB,QAgB7B","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\r\n\r\nimport type { DisplayStrings } from './config';\r\n\r\nexport interface InitializeOptions {\r\n /**\r\n * If your app doesn't use Bluetooth scan results to derive physical\r\n * location information, you can strongly assert that your app\r\n * doesn't derive physical location. (Android only)\r\n * Requires adding 'neverForLocation' to AndroidManifest.xml\r\n * https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location\r\n * @default false\r\n */\r\n androidNeverForLocation?: boolean;\r\n}\r\n\r\nexport interface RequestBleDeviceOptions {\r\n /**\r\n * Filter devices by service UUIDs.\r\n * UUIDs have to be specified as 128 bit UUID strings,\r\n * e.g. ['0000180d-0000-1000-8000-00805f9b34fb']\r\n * There is a helper function to convert numbers to UUIDs.\r\n * e.g. [numberToUUID(0x180f)]. (see [UUID format](#uuid-format))\r\n */\r\n services?: string[];\r\n /**\r\n * Filter devices by name\r\n */\r\n name?: string;\r\n /**\r\n * Filter devices by name prefix\r\n */\r\n namePrefix?: string;\r\n /**\r\n * For **web**, all services that will be used have to be listed under services or optionalServices,\r\n * e.g. [numberToUUID(0x180f)] (see [UUID format](#uuid-format))\r\n */\r\n optionalServices?: string[];\r\n /**\r\n * Normally scans will discard the second and subsequent advertisements from a single device.\r\n * If you need to receive them, set allowDuplicates to true (only applicable in `requestLEScan`).\r\n * (default: false)\r\n */\r\n allowDuplicates?: boolean;\r\n /**\r\n * Android scan mode (default: ScanMode.SCAN_MODE_BALANCED)\r\n */\r\n scanMode?: ScanMode;\r\n /**\r\n * Allow scanning for devices with a specific manufacturer data\r\n * https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice#manufacturerdata\r\n */\r\n manufacturerData?: ManufacturerDataFilter[];\r\n}\r\n\r\n/**\r\n * Android scan mode\r\n */\r\nexport enum ScanMode {\r\n /**\r\n * Perform Bluetooth LE scan in low power mode. This mode is enforced if the scanning application is not in foreground.\r\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_POWER\r\n */\r\n SCAN_MODE_LOW_POWER = 0,\r\n /**\r\n * 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.\r\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_BALANCED\r\n */\r\n SCAN_MODE_BALANCED = 1,\r\n /**\r\n * Scan using highest duty cycle. It's recommended to only use this mode when the application is running in the foreground.\r\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_LATENCY\r\n */\r\n SCAN_MODE_LOW_LATENCY = 2,\r\n}\r\n\r\n/**\r\n * Android connection priority used in `requestConnectionPriority`\r\n */\r\nexport enum ConnectionPriority {\r\n /**\r\n * Use the connection parameters recommended by the Bluetooth SIG. This is the default value if no connection parameter update is requested.\r\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_BALANCED\r\n */\r\n CONNECTION_PRIORITY_BALANCED = 0,\r\n /**\r\n * 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.\r\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_HIGH\r\n */\r\n CONNECTION_PRIORITY_HIGH = 1,\r\n /**\r\n * Request low power, reduced data rate connection parameters.\r\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER\r\n */\r\n CONNECTION_PRIORITY_LOW_POWER = 2,\r\n}\r\n\r\nexport interface ManufacturerDataFilter {\r\n /**\r\n * Company ID (sometimes called the manufacturer ID) to search for in the manufacturer data field.\r\n */\r\n companyIdentifier: number;\r\n\r\n /**\r\n * Prefix to match in the manufacturer data field.\r\n * On **Android** this field is mandatory.\r\n */\r\n dataPrefix?: Uint8Array;\r\n\r\n /**\r\n * 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.\r\n * The `mask` must have the same length of dataPrefix.\r\n */\r\n mask?: Uint8Array;\r\n}\r\n\r\nexport interface BleDevice {\r\n /**\r\n * ID of the device, which will be needed for further calls.\r\n * On **Android** this is the BLE MAC address.\r\n * On **iOS** and **web** it is an identifier.\r\n */\r\n deviceId: string;\r\n /**\r\n * Name of the peripheral device.\r\n */\r\n name?: string;\r\n uuids?: string[];\r\n}\r\n\r\nexport interface DeviceIdOptions {\r\n deviceId: string;\r\n}\r\nexport interface TimeoutOptions {\r\n /**\r\n * Timeout in milliseconds for plugin call.\r\n * Default is 10000 for `connect` and 5000 for other plugin methods.\r\n */\r\n timeout?: number;\r\n}\r\n\r\nexport interface RequestConnectionPriorityOptions extends DeviceIdOptions {\r\n connectionPriority: ConnectionPriority;\r\n}\r\n\r\nexport interface GetDevicesOptions {\r\n deviceIds: string[];\r\n}\r\n\r\nexport interface GetConnectedDevicesOptions {\r\n services: string[];\r\n}\r\n\r\nexport interface BleService {\r\n readonly uuid: string;\r\n readonly characteristics: BleCharacteristic[];\r\n}\r\n\r\nexport interface BleDescriptor {\r\n readonly uuid: string;\r\n}\r\n\r\nexport interface BleCharacteristic {\r\n readonly uuid: string;\r\n readonly properties: BleCharacteristicProperties;\r\n readonly descriptors: BleDescriptor[];\r\n}\r\n\r\nexport interface BleCharacteristicProperties {\r\n readonly broadcast: boolean;\r\n readonly read: boolean;\r\n readonly writeWithoutResponse: boolean;\r\n readonly write: boolean;\r\n readonly notify: boolean;\r\n readonly indicate: boolean;\r\n readonly authenticatedSignedWrites: boolean;\r\n readonly reliableWrite?: boolean;\r\n readonly writableAuxiliaries?: boolean;\r\n readonly extendedProperties?: boolean;\r\n readonly notifyEncryptionRequired?: boolean;\r\n readonly indicateEncryptionRequired?: boolean;\r\n}\r\n\r\nexport interface BleServices {\r\n services: BleService[];\r\n}\r\n\r\nexport interface ReadOptions {\r\n deviceId: string;\r\n service: string;\r\n characteristic: string;\r\n}\r\n\r\nexport interface ReadDescriptorOptions {\r\n deviceId: string;\r\n service: string;\r\n characteristic: string;\r\n descriptor: string;\r\n}\r\n\r\nexport type Data = DataView | string;\r\n\r\nexport interface WriteOptions {\r\n deviceId: string;\r\n service: string;\r\n characteristic: string;\r\n /**\r\n * android, ios: string\r\n * web: DataView\r\n */\r\n value: Data;\r\n}\r\n\r\nexport interface WriteDescriptorOptions {\r\n deviceId: string;\r\n service: string;\r\n characteristic: string;\r\n descriptor: string;\r\n /**\r\n * android, ios: string\r\n * web: DataView\r\n */\r\n value: Data;\r\n}\r\n\r\nexport interface BooleanResult {\r\n value: boolean;\r\n}\r\n\r\nexport interface GetDevicesResult {\r\n devices: BleDevice[];\r\n}\r\n\r\nexport interface GetMtuResult {\r\n value: number;\r\n}\r\n\r\nexport interface ReadRssiResult {\r\n value: string;\r\n}\r\n\r\nexport interface ReadResult {\r\n /**\r\n * android, ios: string\r\n * web: DataView\r\n */\r\n value?: Data;\r\n}\r\n\r\nexport interface ScanResultInternal<T = Data> {\r\n device: BleDevice;\r\n localName?: string;\r\n rssi?: number;\r\n txPower?: number;\r\n manufacturerData?: { [key: string]: T };\r\n serviceData?: { [key: string]: T };\r\n uuids?: string[];\r\n rawAdvertisement?: T;\r\n}\r\n\r\nexport interface ScanResult {\r\n /**\r\n * The peripheral device that was found in the scan.\r\n * **Android** and **web**: `device.name` is always identical to `localName`.\r\n * **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.\r\n */\r\n device: BleDevice;\r\n /**\r\n * The name of the peripheral device from the advertisement data.\r\n */\r\n localName?: string;\r\n /**\r\n * Received Signal Strength Indication.\r\n */\r\n rssi?: number;\r\n /**\r\n * Transmit power in dBm. A value of 127 indicates that it is not available.\r\n */\r\n txPower?: number;\r\n /**\r\n * Manufacturer data, key is a company identifier and value is the data.\r\n */\r\n manufacturerData?: { [key: string]: DataView };\r\n /**\r\n * Service data, key is a service UUID and value is the data.\r\n */\r\n serviceData?: { [key: string]: DataView };\r\n /**\r\n * Advertised services.\r\n */\r\n uuids?: string[];\r\n /**\r\n * Raw advertisement data (**Android** only).\r\n */\r\n rawAdvertisement?: DataView;\r\n}\r\n\r\nexport interface BluetoothLePlugin {\r\n initialize(options?: InitializeOptions): Promise<void>;\r\n isEnabled(): Promise<BooleanResult>;\r\n requestEnable(): Promise<void>;\r\n enable(): Promise<void>;\r\n disable(): Promise<void>;\r\n startEnabledNotifications(): Promise<void>;\r\n stopEnabledNotifications(): Promise<void>;\r\n isLocationEnabled(): Promise<BooleanResult>;\r\n openLocationSettings(): Promise<void>;\r\n openBluetoothSettings(): Promise<void>;\r\n openAppSettings(): Promise<void>;\r\n setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;\r\n requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;\r\n requestLEScan(options?: RequestBleDeviceOptions): Promise<void>;\r\n stopLEScan(): Promise<void>;\r\n getDevices(options: GetDevicesOptions): Promise<GetDevicesResult>;\r\n getConnectedDevices(options: GetConnectedDevicesOptions): Promise<GetDevicesResult>;\r\n getBondedDevices(): Promise<GetDevicesResult>;\r\n addListener(\r\n eventName: 'onEnabledChanged',\r\n listenerFunc: (result: BooleanResult) => void,\r\n ): Promise<PluginListenerHandle>;\r\n addListener(eventName: string, listenerFunc: (event: ReadResult) => void): Promise<PluginListenerHandle>;\r\n addListener(\r\n eventName: 'onScanResult',\r\n listenerFunc: (result: ScanResultInternal) => void,\r\n ): Promise<PluginListenerHandle>;\r\n connect(options: DeviceIdOptions & TimeoutOptions): Promise<void>;\r\n createBond(options: DeviceIdOptions & TimeoutOptions): Promise<void>;\r\n isBonded(options: DeviceIdOptions): Promise<BooleanResult>;\r\n disconnect(options: DeviceIdOptions): Promise<void>;\r\n getServices(options: DeviceIdOptions): Promise<BleServices>;\r\n discoverServices(options: DeviceIdOptions): Promise<void>;\r\n getMtu(options: DeviceIdOptions): Promise<GetMtuResult>;\r\n requestConnectionPriority(options: RequestConnectionPriorityOptions): Promise<void>;\r\n readRssi(options: DeviceIdOptions): Promise<ReadRssiResult>;\r\n read(options: ReadOptions & TimeoutOptions): Promise<ReadResult>;\r\n write(options: WriteOptions & TimeoutOptions): Promise<void>;\r\n writeWithoutResponse(options: WriteOptions & TimeoutOptions): Promise<void>;\r\n readDescriptor(options: ReadDescriptorOptions & TimeoutOptions): Promise<ReadResult>;\r\n writeDescriptor(options: WriteDescriptorOptions & TimeoutOptions): Promise<void>;\r\n startNotifications(options: ReadOptions): Promise<void>;\r\n stopNotifications(options: ReadOptions): Promise<void>;\r\n}\r\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var core = require('@capacitor/core');
|
|
6
4
|
|
|
7
5
|
/**
|
|
@@ -209,7 +207,7 @@ class BleClientClass {
|
|
|
209
207
|
await this.queue(async () => {
|
|
210
208
|
var _a;
|
|
211
209
|
const key = `onEnabledChanged`;
|
|
212
|
-
await ((_a = this.eventListeners.get(key)) === null || _a ===
|
|
210
|
+
await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
|
|
213
211
|
const listener = await BluetoothLe.addListener(key, (result) => {
|
|
214
212
|
callback(result.value);
|
|
215
213
|
});
|
|
@@ -221,7 +219,7 @@ class BleClientClass {
|
|
|
221
219
|
await this.queue(async () => {
|
|
222
220
|
var _a;
|
|
223
221
|
const key = `onEnabledChanged`;
|
|
224
|
-
await ((_a = this.eventListeners.get(key)) === null || _a ===
|
|
222
|
+
await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
|
|
225
223
|
this.eventListeners.delete(key);
|
|
226
224
|
await BluetoothLe.stopEnabledNotifications();
|
|
227
225
|
});
|
|
@@ -265,7 +263,7 @@ class BleClientClass {
|
|
|
265
263
|
options = this.validateRequestBleDeviceOptions(options);
|
|
266
264
|
await this.queue(async () => {
|
|
267
265
|
var _a;
|
|
268
|
-
await ((_a = this.scanListener) === null || _a ===
|
|
266
|
+
await ((_a = this.scanListener) === null || _a === undefined ? undefined : _a.remove());
|
|
269
267
|
this.scanListener = await BluetoothLe.addListener('onScanResult', (resultInternal) => {
|
|
270
268
|
const result = Object.assign(Object.assign({}, resultInternal), { manufacturerData: this.convertObject(resultInternal.manufacturerData), serviceData: this.convertObject(resultInternal.serviceData), rawAdvertisement: resultInternal.rawAdvertisement
|
|
271
269
|
? this.convertValue(resultInternal.rawAdvertisement)
|
|
@@ -278,7 +276,7 @@ class BleClientClass {
|
|
|
278
276
|
async stopLEScan() {
|
|
279
277
|
await this.queue(async () => {
|
|
280
278
|
var _a;
|
|
281
|
-
await ((_a = this.scanListener) === null || _a ===
|
|
279
|
+
await ((_a = this.scanListener) === null || _a === undefined ? undefined : _a.remove());
|
|
282
280
|
this.scanListener = null;
|
|
283
281
|
await BluetoothLe.stopLEScan();
|
|
284
282
|
});
|
|
@@ -313,7 +311,7 @@ class BleClientClass {
|
|
|
313
311
|
var _a;
|
|
314
312
|
if (onDisconnect) {
|
|
315
313
|
const key = `disconnected|${deviceId}`;
|
|
316
|
-
await ((_a = this.eventListeners.get(key)) === null || _a ===
|
|
314
|
+
await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
|
|
317
315
|
const listener = await BluetoothLe.addListener(key, () => {
|
|
318
316
|
onDisconnect(deviceId);
|
|
319
317
|
});
|
|
@@ -385,7 +383,7 @@ class BleClientClass {
|
|
|
385
383
|
service = parseUUID(service);
|
|
386
384
|
characteristic = parseUUID(characteristic);
|
|
387
385
|
return this.queue(async () => {
|
|
388
|
-
if (!(value === null || value ===
|
|
386
|
+
if (!(value === null || value === undefined ? undefined : value.buffer)) {
|
|
389
387
|
throw new Error('Invalid data.');
|
|
390
388
|
}
|
|
391
389
|
let writeValue = value;
|
|
@@ -402,7 +400,7 @@ class BleClientClass {
|
|
|
402
400
|
service = parseUUID(service);
|
|
403
401
|
characteristic = parseUUID(characteristic);
|
|
404
402
|
await this.queue(async () => {
|
|
405
|
-
if (!(value === null || value ===
|
|
403
|
+
if (!(value === null || value === undefined ? undefined : value.buffer)) {
|
|
406
404
|
throw new Error('Invalid data.');
|
|
407
405
|
}
|
|
408
406
|
let writeValue = value;
|
|
@@ -433,7 +431,7 @@ class BleClientClass {
|
|
|
433
431
|
characteristic = parseUUID(characteristic);
|
|
434
432
|
descriptor = parseUUID(descriptor);
|
|
435
433
|
return this.queue(async () => {
|
|
436
|
-
if (!(value === null || value ===
|
|
434
|
+
if (!(value === null || value === undefined ? undefined : value.buffer)) {
|
|
437
435
|
throw new Error('Invalid data.');
|
|
438
436
|
}
|
|
439
437
|
let writeValue = value;
|
|
@@ -453,9 +451,9 @@ class BleClientClass {
|
|
|
453
451
|
await this.queue(async () => {
|
|
454
452
|
var _a;
|
|
455
453
|
const key = `notification|${deviceId}|${service}|${characteristic}`;
|
|
456
|
-
await ((_a = this.eventListeners.get(key)) === null || _a ===
|
|
454
|
+
await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
|
|
457
455
|
const listener = await BluetoothLe.addListener(key, (event) => {
|
|
458
|
-
callback(this.convertValue(event === null || event ===
|
|
456
|
+
callback(this.convertValue(event === null || event === undefined ? undefined : event.value));
|
|
459
457
|
});
|
|
460
458
|
this.eventListeners.set(key, listener);
|
|
461
459
|
await BluetoothLe.startNotifications({
|
|
@@ -471,7 +469,7 @@ class BleClientClass {
|
|
|
471
469
|
await this.queue(async () => {
|
|
472
470
|
var _a;
|
|
473
471
|
const key = `notification|${deviceId}|${service}|${characteristic}`;
|
|
474
|
-
await ((_a = this.eventListeners.get(key)) === null || _a ===
|
|
472
|
+
await ((_a = this.eventListeners.get(key)) === null || _a === undefined ? undefined : _a.remove());
|
|
475
473
|
this.eventListeners.delete(key);
|
|
476
474
|
await BluetoothLe.stopNotifications({
|
|
477
475
|
deviceId,
|
|
@@ -579,7 +577,7 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
579
577
|
const filters = this.getFilters(options);
|
|
580
578
|
const device = await navigator.bluetooth.requestDevice({
|
|
581
579
|
filters: filters.length ? filters : undefined,
|
|
582
|
-
optionalServices: options === null || options ===
|
|
580
|
+
optionalServices: options === null || options === undefined ? undefined : options.optionalServices,
|
|
583
581
|
acceptAllDevices: filters.length === 0,
|
|
584
582
|
});
|
|
585
583
|
this.deviceMap.set(device.id, device);
|
|
@@ -596,7 +594,7 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
596
594
|
this.scan = await navigator.bluetooth.requestLEScan({
|
|
597
595
|
filters: filters.length ? filters : undefined,
|
|
598
596
|
acceptAllAdvertisements: filters.length === 0,
|
|
599
|
-
keepRepeatedDevices: options === null || options ===
|
|
597
|
+
keepRepeatedDevices: options === null || options === undefined ? undefined : options.allowDuplicates,
|
|
600
598
|
});
|
|
601
599
|
}
|
|
602
600
|
onAdvertisementReceived(event) {
|
|
@@ -604,7 +602,7 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
604
602
|
const deviceId = event.device.id;
|
|
605
603
|
this.deviceMap.set(deviceId, event.device);
|
|
606
604
|
const isNew = !this.discoveredDevices.has(deviceId);
|
|
607
|
-
if (isNew || ((_a = this.requestBleDeviceOptions) === null || _a ===
|
|
605
|
+
if (isNew || ((_a = this.requestBleDeviceOptions) === null || _a === undefined ? undefined : _a.allowDuplicates)) {
|
|
608
606
|
this.discoveredDevices.set(deviceId, true);
|
|
609
607
|
const device = this.getBleDevice(event.device);
|
|
610
608
|
const result = {
|
|
@@ -614,14 +612,14 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
614
612
|
txPower: event.txPower,
|
|
615
613
|
manufacturerData: mapToObject(event.manufacturerData),
|
|
616
614
|
serviceData: mapToObject(event.serviceData),
|
|
617
|
-
uuids: (_b = event.uuids) === null || _b ===
|
|
615
|
+
uuids: (_b = event.uuids) === null || _b === undefined ? undefined : _b.map(webUUIDToString),
|
|
618
616
|
};
|
|
619
617
|
this.notifyListeners('onScanResult', result);
|
|
620
618
|
}
|
|
621
619
|
}
|
|
622
620
|
async stopLEScan() {
|
|
623
621
|
var _a;
|
|
624
|
-
if ((_a = this.scan) === null || _a ===
|
|
622
|
+
if ((_a = this.scan) === null || _a === undefined ? undefined : _a.active) {
|
|
625
623
|
this.scan.stop();
|
|
626
624
|
}
|
|
627
625
|
this.scan = null;
|
|
@@ -642,7 +640,7 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
642
640
|
const bleDevices = devices
|
|
643
641
|
.filter((device) => {
|
|
644
642
|
var _a;
|
|
645
|
-
return (_a = device.gatt) === null || _a ===
|
|
643
|
+
return (_a = device.gatt) === null || _a === undefined ? undefined : _a.connected;
|
|
646
644
|
})
|
|
647
645
|
.map((device) => {
|
|
648
646
|
this.deviceMap.set(device.id, device);
|
|
@@ -670,7 +668,7 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
670
668
|
catch (error) {
|
|
671
669
|
// cancel pending connect call, does not work yet in chromium because of a bug:
|
|
672
670
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=684073
|
|
673
|
-
await ((_b = device.gatt) === null || _b ===
|
|
671
|
+
await ((_b = device.gatt) === null || _b === undefined ? undefined : _b.disconnect());
|
|
674
672
|
if (error === timeoutError) {
|
|
675
673
|
throw new Error('Connection timeout');
|
|
676
674
|
}
|
|
@@ -692,11 +690,11 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
692
690
|
}
|
|
693
691
|
async disconnect(options) {
|
|
694
692
|
var _a;
|
|
695
|
-
(_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a ===
|
|
693
|
+
(_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.disconnect();
|
|
696
694
|
}
|
|
697
695
|
async getServices(options) {
|
|
698
696
|
var _a, _b;
|
|
699
|
-
const services = (_b = (await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a ===
|
|
697
|
+
const services = (_b = (await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.getPrimaryServices()))) !== null && _b !== undefined ? _b : [];
|
|
700
698
|
const bleServices = [];
|
|
701
699
|
for (const service of services) {
|
|
702
700
|
const characteristics = await service.getCharacteristics();
|
|
@@ -738,12 +736,12 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
738
736
|
}
|
|
739
737
|
async getCharacteristic(options) {
|
|
740
738
|
var _a;
|
|
741
|
-
const service = await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a ===
|
|
742
|
-
return service === null || service ===
|
|
739
|
+
const service = await ((_a = this.getDeviceFromMap(options.deviceId).gatt) === null || _a === undefined ? undefined : _a.getPrimaryService(options === null || options === undefined ? undefined : options.service));
|
|
740
|
+
return service === null || service === undefined ? undefined : service.getCharacteristic(options === null || options === undefined ? undefined : options.characteristic);
|
|
743
741
|
}
|
|
744
742
|
async getDescriptor(options) {
|
|
745
743
|
const characteristic = await this.getCharacteristic(options);
|
|
746
|
-
return characteristic === null || characteristic ===
|
|
744
|
+
return characteristic === null || characteristic === undefined ? undefined : characteristic.getDescriptor(options === null || options === undefined ? undefined : options.descriptor);
|
|
747
745
|
}
|
|
748
746
|
async discoverServices(_options) {
|
|
749
747
|
throw this.unavailable('discoverServices is not available on web.');
|
|
@@ -759,7 +757,7 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
759
757
|
}
|
|
760
758
|
async read(options) {
|
|
761
759
|
const characteristic = await this.getCharacteristic(options);
|
|
762
|
-
const value = await (characteristic === null || characteristic ===
|
|
760
|
+
const value = await (characteristic === null || characteristic === undefined ? undefined : characteristic.readValue());
|
|
763
761
|
return { value };
|
|
764
762
|
}
|
|
765
763
|
async write(options) {
|
|
@@ -771,7 +769,7 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
771
769
|
else {
|
|
772
770
|
dataView = options.value;
|
|
773
771
|
}
|
|
774
|
-
await (characteristic === null || characteristic ===
|
|
772
|
+
await (characteristic === null || characteristic === undefined ? undefined : characteristic.writeValueWithResponse(dataView));
|
|
775
773
|
}
|
|
776
774
|
async writeWithoutResponse(options) {
|
|
777
775
|
const characteristic = await this.getCharacteristic(options);
|
|
@@ -782,11 +780,11 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
782
780
|
else {
|
|
783
781
|
dataView = options.value;
|
|
784
782
|
}
|
|
785
|
-
await (characteristic === null || characteristic ===
|
|
783
|
+
await (characteristic === null || characteristic === undefined ? undefined : characteristic.writeValueWithoutResponse(dataView));
|
|
786
784
|
}
|
|
787
785
|
async readDescriptor(options) {
|
|
788
786
|
const descriptor = await this.getDescriptor(options);
|
|
789
|
-
const value = await (descriptor === null || descriptor ===
|
|
787
|
+
const value = await (descriptor === null || descriptor === undefined ? undefined : descriptor.readValue());
|
|
790
788
|
return { value };
|
|
791
789
|
}
|
|
792
790
|
async writeDescriptor(options) {
|
|
@@ -798,43 +796,43 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
798
796
|
else {
|
|
799
797
|
dataView = options.value;
|
|
800
798
|
}
|
|
801
|
-
await (descriptor === null || descriptor ===
|
|
799
|
+
await (descriptor === null || descriptor === undefined ? undefined : descriptor.writeValue(dataView));
|
|
802
800
|
}
|
|
803
801
|
async startNotifications(options) {
|
|
804
802
|
const characteristic = await this.getCharacteristic(options);
|
|
805
|
-
characteristic === null || characteristic ===
|
|
806
|
-
characteristic === null || characteristic ===
|
|
807
|
-
await (characteristic === null || characteristic ===
|
|
803
|
+
characteristic === null || characteristic === undefined ? undefined : characteristic.removeEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
|
|
804
|
+
characteristic === null || characteristic === undefined ? undefined : characteristic.addEventListener('characteristicvaluechanged', this.onCharacteristicValueChangedCallback);
|
|
805
|
+
await (characteristic === null || characteristic === undefined ? undefined : characteristic.startNotifications());
|
|
808
806
|
}
|
|
809
807
|
onCharacteristicValueChanged(event) {
|
|
810
808
|
var _a, _b;
|
|
811
809
|
const characteristic = event.target;
|
|
812
|
-
const key = `notification|${(_a = characteristic.service) === null || _a ===
|
|
810
|
+
const key = `notification|${(_a = characteristic.service) === null || _a === undefined ? undefined : _a.device.id}|${(_b = characteristic.service) === null || _b === undefined ? undefined : _b.uuid}|${characteristic.uuid}`;
|
|
813
811
|
this.notifyListeners(key, {
|
|
814
812
|
value: characteristic.value,
|
|
815
813
|
});
|
|
816
814
|
}
|
|
817
815
|
async stopNotifications(options) {
|
|
818
816
|
const characteristic = await this.getCharacteristic(options);
|
|
819
|
-
await (characteristic === null || characteristic ===
|
|
817
|
+
await (characteristic === null || characteristic === undefined ? undefined : characteristic.stopNotifications());
|
|
820
818
|
}
|
|
821
819
|
getFilters(options) {
|
|
822
820
|
var _a, _b;
|
|
823
821
|
const filters = [];
|
|
824
|
-
for (const service of (_a = options === null || options ===
|
|
822
|
+
for (const service of (_a = options === null || options === undefined ? undefined : options.services) !== null && _a !== undefined ? _a : []) {
|
|
825
823
|
filters.push({
|
|
826
824
|
services: [service],
|
|
827
|
-
name: options === null || options ===
|
|
828
|
-
namePrefix: options === null || options ===
|
|
825
|
+
name: options === null || options === undefined ? undefined : options.name,
|
|
826
|
+
namePrefix: options === null || options === undefined ? undefined : options.namePrefix,
|
|
829
827
|
});
|
|
830
828
|
}
|
|
831
|
-
if (((options === null || options ===
|
|
829
|
+
if (((options === null || options === undefined ? undefined : options.name) || (options === null || options === undefined ? undefined : options.namePrefix)) && filters.length === 0) {
|
|
832
830
|
filters.push({
|
|
833
831
|
name: options.name,
|
|
834
832
|
namePrefix: options.namePrefix,
|
|
835
833
|
});
|
|
836
834
|
}
|
|
837
|
-
for (const manufacturerData of (_b = options === null || options ===
|
|
835
|
+
for (const manufacturerData of (_b = options === null || options === undefined ? undefined : options.manufacturerData) !== null && _b !== undefined ? _b : []) {
|
|
838
836
|
filters.push({
|
|
839
837
|
manufacturerData: [manufacturerData],
|
|
840
838
|
});
|
|
@@ -853,7 +851,7 @@ class BluetoothLeWeb extends core.WebPlugin {
|
|
|
853
851
|
const bleDevice = {
|
|
854
852
|
deviceId: device.id,
|
|
855
853
|
// use undefined instead of null if name is not available
|
|
856
|
-
name: (_a = device.name) !== null && _a !==
|
|
854
|
+
name: (_a = device.name) !== null && _a !== undefined ? _a : undefined,
|
|
857
855
|
};
|
|
858
856
|
return bleDevice;
|
|
859
857
|
}
|