@capacitor-community/bluetooth-le 7.1.1 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/BluetoothLe.kt +4 -2
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/Device.kt +47 -0
- package/dist/docs.json +52 -42
- package/dist/esm/bleClient.d.ts +3 -2
- package/dist/esm/bleClient.js +3 -5
- package/dist/esm/bleClient.js.map +1 -1
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/conversion.js.map +1 -1
- package/dist/esm/definitions.d.ts +1 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/queue.js.map +1 -1
- package/dist/esm/timeout.js.map +1 -1
- package/dist/esm/validators.js.map +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +3 -5
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +3 -5
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -868,7 +868,7 @@ Write a value to a descriptor.
|
|
|
868
868
|
### startNotifications(...)
|
|
869
869
|
|
|
870
870
|
```typescript
|
|
871
|
-
startNotifications(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void) => Promise<void>
|
|
871
|
+
startNotifications(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void, options?: TimeoutOptions | undefined) => Promise<void>
|
|
872
872
|
```
|
|
873
873
|
|
|
874
874
|
Start listening to changes of the value of a characteristic.
|
|
@@ -882,6 +882,7 @@ For an example, see [usage](#usage).
|
|
|
882
882
|
| **`service`** | <code>string</code> | UUID of the service (see [UUID format](#uuid-format)) |
|
|
883
883
|
| **`characteristic`** | <code>string</code> | UUID of the characteristic (see [UUID format](#uuid-format)) |
|
|
884
884
|
| **`callback`** | <code>(value: <a href="#dataview">DataView</a>) => void</code> | Callback function to use when the value of the characteristic changes |
|
|
885
|
+
| **`options`** | <code><a href="#timeoutoptions">TimeoutOptions</a></code> | Options for plugin call. Timeout not supported on **web**. |
|
|
885
886
|
|
|
886
887
|
---
|
|
887
888
|
|
|
@@ -757,6 +757,7 @@ class BluetoothLe : Plugin() {
|
|
|
757
757
|
fun startNotifications(call: PluginCall) {
|
|
758
758
|
val device = getDevice(call) ?: return
|
|
759
759
|
val characteristic = getCharacteristic(call) ?: return
|
|
760
|
+
val timeout = call.getFloat("timeout", DEFAULT_TIMEOUT)!!.toLong()
|
|
760
761
|
device.setNotifications(characteristic.first, characteristic.second, true, { response ->
|
|
761
762
|
run {
|
|
762
763
|
val key =
|
|
@@ -769,7 +770,7 @@ class BluetoothLe : Plugin() {
|
|
|
769
770
|
Logger.error(TAG, "Error in notifyListeners: ${e.localizedMessage}", e)
|
|
770
771
|
}
|
|
771
772
|
}
|
|
772
|
-
}, { response ->
|
|
773
|
+
}, timeout, { response ->
|
|
773
774
|
run {
|
|
774
775
|
if (response.success) {
|
|
775
776
|
call.resolve()
|
|
@@ -784,8 +785,9 @@ class BluetoothLe : Plugin() {
|
|
|
784
785
|
fun stopNotifications(call: PluginCall) {
|
|
785
786
|
val device = getDevice(call) ?: return
|
|
786
787
|
val characteristic = getCharacteristic(call) ?: return
|
|
788
|
+
val timeout = call.getFloat("timeout", DEFAULT_TIMEOUT)!!.toLong()
|
|
787
789
|
device.setNotifications(
|
|
788
|
-
characteristic.first, characteristic.second, false, null
|
|
790
|
+
characteristic.first, characteristic.second, false, null, timeout
|
|
789
791
|
) { response ->
|
|
790
792
|
run {
|
|
791
793
|
if (response.success) {
|
|
@@ -68,6 +68,7 @@ class Device(
|
|
|
68
68
|
private var device: BluetoothDevice = bluetoothAdapter.getRemoteDevice(address)
|
|
69
69
|
private var bluetoothGatt: BluetoothGatt? = null
|
|
70
70
|
private var callbackMap = HashMap<String, ((CallbackResponse) -> Unit)>()
|
|
71
|
+
private val bondReceiverMap = HashMap<String, BroadcastReceiver>()
|
|
71
72
|
private val timeoutQueue = ConcurrentLinkedQueue<TimeoutHandler>()
|
|
72
73
|
private var bondStateReceiver: BroadcastReceiver? = null
|
|
73
74
|
private var currentMtu = -1
|
|
@@ -280,6 +281,9 @@ class Device(
|
|
|
280
281
|
super.onDescriptorWrite(gatt, descriptor, status)
|
|
281
282
|
val key =
|
|
282
283
|
"writeDescriptor|${descriptor.characteristic.service.uuid}|${descriptor.characteristic.uuid}|${descriptor.uuid}"
|
|
284
|
+
bondReceiverMap.remove(key)?.let {
|
|
285
|
+
context.unregisterReceiver(it)
|
|
286
|
+
}
|
|
283
287
|
if (status == BluetoothGatt.GATT_SUCCESS) {
|
|
284
288
|
resolve(key, "Descriptor successfully written.")
|
|
285
289
|
} else {
|
|
@@ -546,6 +550,7 @@ class Device(
|
|
|
546
550
|
characteristicUUID: UUID,
|
|
547
551
|
enable: Boolean,
|
|
548
552
|
notifyCallback: ((CallbackResponse) -> Unit)?,
|
|
553
|
+
timeout: Long,
|
|
549
554
|
callback: (CallbackResponse) -> Unit,
|
|
550
555
|
) {
|
|
551
556
|
val key = "writeDescriptor|$serviceUUID|$characteristicUUID|$CLIENT_CHARACTERISTIC_CONFIG"
|
|
@@ -585,9 +590,47 @@ class Device(
|
|
|
585
590
|
BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE
|
|
586
591
|
}
|
|
587
592
|
|
|
593
|
+
val bondReceiver = object : BroadcastReceiver() {
|
|
594
|
+
override fun onReceive(ctx: Context, intent: Intent) {
|
|
595
|
+
if (intent.action == BluetoothDevice.ACTION_BOND_STATE_CHANGED) {
|
|
596
|
+
val updatedDevice =
|
|
597
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
598
|
+
intent.getParcelableExtra(
|
|
599
|
+
BluetoothDevice.EXTRA_DEVICE,
|
|
600
|
+
BluetoothDevice::class.java
|
|
601
|
+
)
|
|
602
|
+
} else {
|
|
603
|
+
intent.getParcelableExtra<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// BroadcastReceiver receives bond state updates from all devices, need to filter by device
|
|
607
|
+
if (device.address == updatedDevice?.address) {
|
|
608
|
+
val prev = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, -1)
|
|
609
|
+
val state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1)
|
|
610
|
+
if (state == BluetoothDevice.BOND_BONDED) {
|
|
611
|
+
ctx.unregisterReceiver(this)
|
|
612
|
+
} else if (prev == BluetoothDevice.BOND_BONDING && state == BluetoothDevice.BOND_NONE) {
|
|
613
|
+
ctx.unregisterReceiver(this)
|
|
614
|
+
reject(key, "Pairing request was cancelled by the user.")
|
|
615
|
+
} else if (state == -1) {
|
|
616
|
+
ctx.unregisterReceiver(this)
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
bondReceiverMap[key] = bondReceiver
|
|
623
|
+
context.registerReceiver(
|
|
624
|
+
bondReceiver,
|
|
625
|
+
IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED)
|
|
626
|
+
)
|
|
627
|
+
|
|
588
628
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
589
629
|
val statusCode = bluetoothGatt?.writeDescriptor(descriptor, value)
|
|
590
630
|
if (statusCode != BluetoothStatusCodes.SUCCESS) {
|
|
631
|
+
bondReceiverMap.remove(key)?.let {
|
|
632
|
+
context.unregisterReceiver(it)
|
|
633
|
+
}
|
|
591
634
|
reject(key, "Setting notification failed with status code $statusCode.")
|
|
592
635
|
return
|
|
593
636
|
}
|
|
@@ -595,11 +638,15 @@ class Device(
|
|
|
595
638
|
descriptor.value = value
|
|
596
639
|
val resultDesc = bluetoothGatt?.writeDescriptor(descriptor)
|
|
597
640
|
if (resultDesc != true) {
|
|
641
|
+
bondReceiverMap.remove(key)?.let {
|
|
642
|
+
context.unregisterReceiver(it)
|
|
643
|
+
}
|
|
598
644
|
reject(key, "Setting notification failed.")
|
|
599
645
|
return
|
|
600
646
|
}
|
|
601
647
|
|
|
602
648
|
}
|
|
649
|
+
setTimeout(key, "Setting notification timeout.", timeout)
|
|
603
650
|
// wait for onDescriptorWrite
|
|
604
651
|
}
|
|
605
652
|
|
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.\
|
|
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).",
|
|
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.\
|
|
32
|
+
"docs": "Reports whether Bluetooth is enabled on this device.\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\
|
|
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**.",
|
|
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.\
|
|
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()",
|
|
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.\
|
|
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()",
|
|
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.\
|
|
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).",
|
|
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.\
|
|
113
|
+
"docs": "Reports whether Location Services are enabled on this device.\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.\
|
|
123
|
+
"docs": "Open Location settings.\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.\
|
|
133
|
+
"docs": "Open Bluetooth settings.\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.\
|
|
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.",
|
|
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.\
|
|
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).",
|
|
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.\
|
|
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.",
|
|
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`.\
|
|
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.",
|
|
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.\
|
|
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",
|
|
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.\
|
|
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.",
|
|
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.\
|
|
362
|
+
"docs": "Create a bond with a peripheral BLE device.\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.\
|
|
385
|
+
"docs": "Report whether a peripheral BLE device is bonded.\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.\
|
|
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**.",
|
|
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.\
|
|
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**.",
|
|
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.\
|
|
501
|
+
"docs": "Request a connection parameter update.\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.\
|
|
524
|
+
"docs": "Read the RSSI value of a connected device.\nNot available on **web**.",
|
|
525
525
|
"complexTypes": [],
|
|
526
526
|
"slug": "readrssi"
|
|
527
527
|
},
|
|
@@ -827,7 +827,7 @@
|
|
|
827
827
|
},
|
|
828
828
|
{
|
|
829
829
|
"name": "startNotifications",
|
|
830
|
-
"signature": "(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void) => Promise<void>",
|
|
830
|
+
"signature": "(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void, options?: TimeoutOptions | undefined) => Promise<void>",
|
|
831
831
|
"parameters": [
|
|
832
832
|
{
|
|
833
833
|
"name": "deviceId",
|
|
@@ -848,6 +848,11 @@
|
|
|
848
848
|
"name": "callback",
|
|
849
849
|
"docs": "Callback function to use when the value of the characteristic changes",
|
|
850
850
|
"type": "(value: DataView) => void"
|
|
851
|
+
},
|
|
852
|
+
{
|
|
853
|
+
"name": "options",
|
|
854
|
+
"docs": "Options for plugin call. Timeout not supported on **web**.",
|
|
855
|
+
"type": "TimeoutOptions | undefined"
|
|
851
856
|
}
|
|
852
857
|
],
|
|
853
858
|
"returns": "Promise<void>",
|
|
@@ -867,11 +872,16 @@
|
|
|
867
872
|
{
|
|
868
873
|
"name": "param",
|
|
869
874
|
"text": "callback Callback function to use when the value of the characteristic changes"
|
|
875
|
+
},
|
|
876
|
+
{
|
|
877
|
+
"name": "param",
|
|
878
|
+
"text": "options Options for plugin call. Timeout not supported on **web**."
|
|
870
879
|
}
|
|
871
880
|
],
|
|
872
|
-
"docs": "Start listening to changes of the value of a characteristic.\
|
|
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).",
|
|
873
882
|
"complexTypes": [
|
|
874
|
-
"DataView"
|
|
883
|
+
"DataView",
|
|
884
|
+
"TimeoutOptions"
|
|
875
885
|
],
|
|
876
886
|
"slug": "startnotifications"
|
|
877
887
|
},
|
|
@@ -933,7 +943,7 @@
|
|
|
933
943
|
"name": "default"
|
|
934
944
|
}
|
|
935
945
|
],
|
|
936
|
-
"docs": "If your app doesn't use Bluetooth scan results to derive physical\
|
|
946
|
+
"docs": "If your app doesn't use Bluetooth scan results to derive physical\nlocation information, you can strongly assert that your app\ndoesn't derive physical location. (Android only)\nRequires adding 'neverForLocation' to AndroidManifest.xml\nhttps://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location",
|
|
937
947
|
"complexTypes": [],
|
|
938
948
|
"type": "boolean | undefined"
|
|
939
949
|
}
|
|
@@ -1038,7 +1048,7 @@
|
|
|
1038
1048
|
{
|
|
1039
1049
|
"name": "deviceId",
|
|
1040
1050
|
"tags": [],
|
|
1041
|
-
"docs": "ID of the device, which will be needed for further calls.\
|
|
1051
|
+
"docs": "ID of the device, which will be needed for further calls.\nOn **Android** this is the BLE MAC address.\nOn **iOS** and **web** it is an identifier.",
|
|
1042
1052
|
"complexTypes": [],
|
|
1043
1053
|
"type": "string"
|
|
1044
1054
|
},
|
|
@@ -1068,7 +1078,7 @@
|
|
|
1068
1078
|
{
|
|
1069
1079
|
"name": "services",
|
|
1070
1080
|
"tags": [],
|
|
1071
|
-
"docs": "Filter devices by service UUIDs.\
|
|
1081
|
+
"docs": "Filter devices by service UUIDs.\nUUIDs have to be specified as 128 bit UUID strings,\ne.g. ['0000180d-0000-1000-8000-00805f9b34fb']\nThere is a helper function to convert numbers to UUIDs.\ne.g. [numberToUUID(0x180f)]. (see [UUID format](#uuid-format))",
|
|
1072
1082
|
"complexTypes": [],
|
|
1073
1083
|
"type": "string[] | undefined"
|
|
1074
1084
|
},
|
|
@@ -1089,14 +1099,14 @@
|
|
|
1089
1099
|
{
|
|
1090
1100
|
"name": "optionalServices",
|
|
1091
1101
|
"tags": [],
|
|
1092
|
-
"docs": "For **web**, all services that will be used have to be listed under services or optionalServices,\
|
|
1102
|
+
"docs": "For **web**, all services that will be used have to be listed under services or optionalServices,\ne.g. [numberToUUID(0x180f)] (see [UUID format](#uuid-format))",
|
|
1093
1103
|
"complexTypes": [],
|
|
1094
1104
|
"type": "string[] | undefined"
|
|
1095
1105
|
},
|
|
1096
1106
|
{
|
|
1097
1107
|
"name": "allowDuplicates",
|
|
1098
1108
|
"tags": [],
|
|
1099
|
-
"docs": "Normally scans will discard the second and subsequent advertisements from a single device.\
|
|
1109
|
+
"docs": "Normally scans will discard the second and subsequent advertisements from a single device.\nIf you need to receive them, set allowDuplicates to true (only applicable in `requestLEScan`).\n(default: false)",
|
|
1100
1110
|
"complexTypes": [],
|
|
1101
1111
|
"type": "boolean | undefined"
|
|
1102
1112
|
},
|
|
@@ -1112,7 +1122,7 @@
|
|
|
1112
1122
|
{
|
|
1113
1123
|
"name": "manufacturerData",
|
|
1114
1124
|
"tags": [],
|
|
1115
|
-
"docs": "Allow scanning for devices with a specific manufacturer data\
|
|
1125
|
+
"docs": "Allow scanning for devices with a specific manufacturer data\nhttps://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice#manufacturerdata",
|
|
1116
1126
|
"complexTypes": [
|
|
1117
1127
|
"ManufacturerDataFilter"
|
|
1118
1128
|
],
|
|
@@ -1137,7 +1147,7 @@
|
|
|
1137
1147
|
{
|
|
1138
1148
|
"name": "dataPrefix",
|
|
1139
1149
|
"tags": [],
|
|
1140
|
-
"docs": "Prefix to match in the manufacturer data field.\
|
|
1150
|
+
"docs": "Prefix to match in the manufacturer data field.\nOn **Android** this field is mandatory.",
|
|
1141
1151
|
"complexTypes": [
|
|
1142
1152
|
"Uint8Array"
|
|
1143
1153
|
],
|
|
@@ -1146,7 +1156,7 @@
|
|
|
1146
1156
|
{
|
|
1147
1157
|
"name": "mask",
|
|
1148
1158
|
"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.\
|
|
1159
|
+
"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.\nThe `mask` must have the same length of dataPrefix.",
|
|
1150
1160
|
"complexTypes": [
|
|
1151
1161
|
"Uint8Array"
|
|
1152
1162
|
],
|
|
@@ -1995,7 +2005,7 @@
|
|
|
1995
2005
|
{
|
|
1996
2006
|
"name": "device",
|
|
1997
2007
|
"tags": [],
|
|
1998
|
-
"docs": "The peripheral device that was found in the scan.\
|
|
2008
|
+
"docs": "The peripheral device that was found in the scan.\n**Android** and **web**: `device.name` is always identical to `localName`.\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.",
|
|
1999
2009
|
"complexTypes": [
|
|
2000
2010
|
"BleDevice"
|
|
2001
2011
|
],
|
|
@@ -2593,7 +2603,7 @@
|
|
|
2593
2603
|
{
|
|
2594
2604
|
"name": "timeout",
|
|
2595
2605
|
"tags": [],
|
|
2596
|
-
"docs": "Timeout in milliseconds for plugin call.\
|
|
2606
|
+
"docs": "Timeout in milliseconds for plugin call.\nDefault is 10000 for `connect` and 5000 for other plugin methods.",
|
|
2597
2607
|
"complexTypes": [],
|
|
2598
2608
|
"type": "number | undefined"
|
|
2599
2609
|
}
|
|
@@ -2777,19 +2787,19 @@
|
|
|
2777
2787
|
"name": "SCAN_MODE_LOW_POWER",
|
|
2778
2788
|
"value": "0",
|
|
2779
2789
|
"tags": [],
|
|
2780
|
-
"docs": "Perform Bluetooth LE scan in low power mode. This mode is enforced if the scanning application is not in foreground.\
|
|
2790
|
+
"docs": "Perform Bluetooth LE scan in low power mode. This mode is enforced if the scanning application is not in foreground.\nhttps://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_POWER"
|
|
2781
2791
|
},
|
|
2782
2792
|
{
|
|
2783
2793
|
"name": "SCAN_MODE_BALANCED",
|
|
2784
2794
|
"value": "1",
|
|
2785
2795
|
"tags": [],
|
|
2786
|
-
"docs": "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.\
|
|
2796
|
+
"docs": "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.\nhttps://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_BALANCED"
|
|
2787
2797
|
},
|
|
2788
2798
|
{
|
|
2789
2799
|
"name": "SCAN_MODE_LOW_LATENCY",
|
|
2790
2800
|
"value": "2",
|
|
2791
2801
|
"tags": [],
|
|
2792
|
-
"docs": "Scan using highest duty cycle. It's recommended to only use this mode when the application is running in the foreground.\
|
|
2802
|
+
"docs": "Scan using highest duty cycle. It's recommended to only use this mode when the application is running in the foreground.\nhttps://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_LATENCY"
|
|
2793
2803
|
}
|
|
2794
2804
|
]
|
|
2795
2805
|
},
|
|
@@ -2801,19 +2811,19 @@
|
|
|
2801
2811
|
"name": "CONNECTION_PRIORITY_BALANCED",
|
|
2802
2812
|
"value": "0",
|
|
2803
2813
|
"tags": [],
|
|
2804
|
-
"docs": "Use the connection parameters recommended by the Bluetooth SIG. This is the default value if no connection parameter update is requested.\
|
|
2814
|
+
"docs": "Use the connection parameters recommended by the Bluetooth SIG. This is the default value if no connection parameter update is requested.\nhttps://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_BALANCED"
|
|
2805
2815
|
},
|
|
2806
2816
|
{
|
|
2807
2817
|
"name": "CONNECTION_PRIORITY_HIGH",
|
|
2808
2818
|
"value": "1",
|
|
2809
2819
|
"tags": [],
|
|
2810
|
-
"docs": "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.\
|
|
2820
|
+
"docs": "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.\nhttps://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_HIGH"
|
|
2811
2821
|
},
|
|
2812
2822
|
{
|
|
2813
2823
|
"name": "CONNECTION_PRIORITY_LOW_POWER",
|
|
2814
2824
|
"value": "2",
|
|
2815
2825
|
"tags": [],
|
|
2816
|
-
"docs": "Request low power, reduced data rate connection parameters.\
|
|
2826
|
+
"docs": "Request low power, reduced data rate connection parameters.\nhttps://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER"
|
|
2817
2827
|
}
|
|
2818
2828
|
]
|
|
2819
2829
|
}
|
|
@@ -2846,11 +2856,11 @@
|
|
|
2846
2856
|
"name": "since"
|
|
2847
2857
|
},
|
|
2848
2858
|
{
|
|
2849
|
-
"text": "{\
|
|
2859
|
+
"text": "{\n\"scanning\": \"Scanning...\",\n\"cancel\": \"Cancel\",\n\"availableDevices\": \"Available devices\",\n\"noDeviceFound\": \"No device found\"\n}",
|
|
2850
2860
|
"name": "default"
|
|
2851
2861
|
},
|
|
2852
2862
|
{
|
|
2853
|
-
"text": "{\
|
|
2863
|
+
"text": "{\nscanning: \"Am Scannen...\",\ncancel: \"Abbrechen\",\navailableDevices: \"Verfügbare Geräte\",\nnoDeviceFound: \"Kein Gerät gefunden\",\n}",
|
|
2854
2864
|
"name": "example"
|
|
2855
2865
|
}
|
|
2856
2866
|
],
|
package/dist/esm/bleClient.d.ts
CHANGED
|
@@ -219,8 +219,9 @@ export interface BleClientInterface {
|
|
|
219
219
|
* @param service UUID of the service (see [UUID format](#uuid-format))
|
|
220
220
|
* @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))
|
|
221
221
|
* @param callback Callback function to use when the value of the characteristic changes
|
|
222
|
+
* @param options Options for plugin call. Timeout not supported on **web**.
|
|
222
223
|
*/
|
|
223
|
-
startNotifications(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void): Promise<void>;
|
|
224
|
+
startNotifications(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void, options?: TimeoutOptions): Promise<void>;
|
|
224
225
|
/**
|
|
225
226
|
* Stop listening to the changes of the value of a characteristic. For an example, see [usage](#usage).
|
|
226
227
|
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))
|
|
@@ -267,7 +268,7 @@ declare class BleClientClass implements BleClientInterface {
|
|
|
267
268
|
writeWithoutResponse(deviceId: string, service: string, characteristic: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
268
269
|
readDescriptor(deviceId: string, service: string, characteristic: string, descriptor: string, options?: TimeoutOptions): Promise<DataView>;
|
|
269
270
|
writeDescriptor(deviceId: string, service: string, characteristic: string, descriptor: string, value: DataView, options?: TimeoutOptions): Promise<void>;
|
|
270
|
-
startNotifications(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void): Promise<void>;
|
|
271
|
+
startNotifications(deviceId: string, service: string, characteristic: string, callback: (value: DataView) => void, options?: TimeoutOptions): Promise<void>;
|
|
271
272
|
stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void>;
|
|
272
273
|
private validateRequestBleDeviceOptions;
|
|
273
274
|
private convertValue;
|
package/dist/esm/bleClient.js
CHANGED
|
@@ -284,7 +284,7 @@ class BleClientClass {
|
|
|
284
284
|
descriptor, value: writeValue }, options));
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
|
-
async startNotifications(deviceId, service, characteristic, callback) {
|
|
287
|
+
async startNotifications(deviceId, service, characteristic, callback, options) {
|
|
288
288
|
service = parseUUID(service);
|
|
289
289
|
characteristic = parseUUID(characteristic);
|
|
290
290
|
await this.queue(async () => {
|
|
@@ -295,11 +295,9 @@ class BleClientClass {
|
|
|
295
295
|
callback(this.convertValue(event === null || event === void 0 ? void 0 : event.value));
|
|
296
296
|
});
|
|
297
297
|
this.eventListeners.set(key, listener);
|
|
298
|
-
await BluetoothLe.startNotifications({
|
|
299
|
-
deviceId,
|
|
298
|
+
await BluetoothLe.startNotifications(Object.assign({ deviceId,
|
|
300
299
|
service,
|
|
301
|
-
characteristic,
|
|
302
|
-
});
|
|
300
|
+
characteristic }, options));
|
|
303
301
|
});
|
|
304
302
|
}
|
|
305
303
|
async stopNotifications(deviceId, service, characteristic) {
|