@capacitor-community/bluetooth-le 3.1.0 → 6.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
</p>
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
9
|
-
<img src="https://img.shields.io/maintenance/yes/
|
|
9
|
+
<img src="https://img.shields.io/maintenance/yes/2024?style=flat-square" />
|
|
10
10
|
<a href="https://github.com/capacitor-community/bluetooth-le/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/actions/workflow/status/capacitor-community/bluetooth-le/main.yml?branch=main&style=flat-square" /></a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/@capacitor-community/bluetooth-le"><img src="https://img.shields.io/npm/l/@capacitor-community/bluetooth-le?style=flat-square" /></a>
|
|
12
12
|
<br>
|
|
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-15-orange?style=flat-square" /></a>
|
|
17
17
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
18
18
|
</p>
|
|
19
19
|
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
|
|
28
28
|
| Plugin | Capacitor | Documentation |
|
|
29
29
|
| ------ | --------- | --------------------------------------------------------------------------------- |
|
|
30
|
-
|
|
|
30
|
+
| 6.x | 6.x | [README](https://github.com/capacitor-community/bluetooth-le/blob/main/README.md) |
|
|
31
|
+
| 3.x | 5.x | [README](https://github.com/capacitor-community/bluetooth-le/blob/3.x/README.md) |
|
|
31
32
|
| 2.x | 4.x | [README](https://github.com/capacitor-community/bluetooth-le/blob/2.x/README.md) |
|
|
32
33
|
| 1.x | 3.x | [README](https://github.com/capacitor-community/bluetooth-le/blob/1.x/README.md) |
|
|
33
34
|
| 0.x | 2.x | [README](https://github.com/capacitor-community/bluetooth-le/blob/0.x/README.md) |
|
|
@@ -38,7 +39,9 @@ This is a Capacitor plugin for Bluetooth Low Energy. It supports the web, Androi
|
|
|
38
39
|
|
|
39
40
|
The goal is to support the same features on all platforms. Therefore the [Web Bluetooth API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API) is taken as a guidline for what features to implement.
|
|
40
41
|
|
|
41
|
-
This plugin only supports
|
|
42
|
+
This plugin only supports Bluetooth **Low Energy**, not Bluetooth serial / classic.
|
|
43
|
+
|
|
44
|
+
Furthermore the plugin only supports the central role of the Bluetooth Low Energy protocol. If you need the peripheral role, take a look a these plugins:
|
|
42
45
|
|
|
43
46
|
- https://github.com/randdusing/cordova-plugin-bluetoothle
|
|
44
47
|
- https://github.com/don/cordova-plugin-ble-peripheral
|
|
@@ -127,7 +130,7 @@ If the app needs to use Bluetooth while it is in the background, you also have t
|
|
|
127
130
|
|
|
128
131
|
### Android
|
|
129
132
|
|
|
130
|
-
On Android, no further steps are required to use the plugin
|
|
133
|
+
On Android, no further steps are required to use the plugin.
|
|
131
134
|
|
|
132
135
|
#### (Optional) Android 12 Bluetooth permissions
|
|
133
136
|
|
|
@@ -136,8 +139,6 @@ If your app targets Android 12 (API level 31) or higher and your app doesn't use
|
|
|
136
139
|
The following steps are required to scan for Bluetooth devices without location permission on Android 12 devices:
|
|
137
140
|
|
|
138
141
|
- In `android/variables.gradle`, make sure `compileSdkVersion` and `targetSdkVersion` are at least 31 (changing those values can have other consequences on your app, so make sure you know what you're doing).
|
|
139
|
-
- Make sure you have JDK 11+ (it is recommended to use JDK that comes with Android Studio).
|
|
140
|
-
- In `android/app/src/main/AndroidManifest.xml`, add `android:exported="true"` to your activity if not already added (setting [`android:exported`](https://developer.android.com/guide/topics/manifest/activity-element#exported) is required in apps targeting Android 12 and higher).
|
|
141
142
|
- In `android/app/src/main/AndroidManifest.xml`, update the permissions:
|
|
142
143
|
```diff
|
|
143
144
|
<!-- Permissions -->
|
|
@@ -198,16 +199,15 @@ The display strings can also be set at run-time using [`setDisplayStrings(...)`]
|
|
|
198
199
|
|
|
199
200
|
## Usage
|
|
200
201
|
|
|
201
|
-
|
|
202
|
+
There is a plugin wrapper class `BleClient` which makes events and method arguments easier to work with.
|
|
202
203
|
|
|
203
204
|
```typescript
|
|
204
|
-
// Import the wrapper class
|
|
205
|
+
// Import the wrapper class
|
|
205
206
|
import { BleClient } from '@capacitor-community/bluetooth-le';
|
|
206
|
-
|
|
207
|
-
// DO NOT use this
|
|
208
|
-
import { BluetoothLe } from '@capacitor-community/bluetooth-le';
|
|
209
207
|
```
|
|
210
208
|
|
|
209
|
+
**Note**: It is not recommended to use the `BluetoothLe` plugin class directly.
|
|
210
|
+
|
|
211
211
|
### Heart rate monitor
|
|
212
212
|
|
|
213
213
|
Here is an example of how to use the plugin. It shows how to read the heart rate from a BLE heart rate monitor such as the Polar H10.
|
|
@@ -354,8 +354,8 @@ _Note_: web support depends on the browser, see [implementation status](https://
|
|
|
354
354
|
| [`readRssi(...)`](#readrssi) | ✅ | ✅ | ❌ |
|
|
355
355
|
| [`read(...)`](#read) | ✅ | ✅ | ✅ |
|
|
356
356
|
| [`write(...)`](#write) | ✅ | ✅ | ✅ |
|
|
357
|
-
| [`readDescriptor(...)`](#
|
|
358
|
-
| [`writeDescriptor(...)`](#
|
|
357
|
+
| [`readDescriptor(...)`](#readdescriptor) | ✅ | ✅ | ✅ |
|
|
358
|
+
| [`writeDescriptor(...)`](#writedescriptor) | ✅ | ✅ | ✅ |
|
|
359
359
|
| [`writeWithoutResponse(...)`](#writewithoutresponse) | ✅ | ✅ | ✅ |
|
|
360
360
|
| [`startNotifications(...)`](#startnotifications) | ✅ | ✅ | ✅ |
|
|
361
361
|
| [`stopNotifications(...)`](#stopnotifications) | ✅ | ✅ | ✅ |
|
|
@@ -1108,6 +1108,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
1108
1108
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/td-tomasz-joniec"><img src="https://avatars.githubusercontent.com/u/109506928?v=4?s=100" width="100px;" alt="td-tomasz-joniec"/><br /><sub><b>td-tomasz-joniec</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=td-tomasz-joniec" title="Code">💻</a></td>
|
|
1109
1109
|
<td align="center" valign="top" width="14.28%"><a href="https://fanxj.com"><img src="https://avatars.githubusercontent.com/u/10436013?v=4?s=100" width="100px;" alt="Michele Ferrari"/><br /><sub><b>Michele Ferrari</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=micheleypf" title="Code">💻</a></td>
|
|
1110
1110
|
</tr>
|
|
1111
|
+
<tr>
|
|
1112
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mchl18"><img src="https://avatars.githubusercontent.com/u/6136970?v=4?s=100" width="100px;" alt="mchl18"/><br /><sub><b>mchl18</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=mchl18" title="Documentation">📖</a></td>
|
|
1113
|
+
</tr>
|
|
1111
1114
|
</tbody>
|
|
1112
1115
|
</table>
|
|
1113
1116
|
|
package/android/build.gradle
CHANGED
|
@@ -6,7 +6,7 @@ ext {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
|
-
ext.
|
|
9
|
+
ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.10'
|
|
10
10
|
ext.coreKtx = project.hasProperty('coreKtx') ? rootProject.ext.coreKtx : '1.9.0'
|
|
11
11
|
|
|
12
12
|
repositories {
|
|
@@ -14,8 +14,8 @@ buildscript {
|
|
|
14
14
|
mavenCentral()
|
|
15
15
|
}
|
|
16
16
|
dependencies {
|
|
17
|
-
classpath 'com.android.tools.build:gradle:8.
|
|
18
|
-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$
|
|
17
|
+
classpath 'com.android.tools.build:gradle:8.2.1'
|
|
18
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -24,10 +24,10 @@ apply plugin: 'kotlin-android'
|
|
|
24
24
|
|
|
25
25
|
android {
|
|
26
26
|
namespace "com.capacitorjs.community.plugins.bluetoothle"
|
|
27
|
-
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion :
|
|
27
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
|
28
28
|
defaultConfig {
|
|
29
29
|
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
30
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
|
30
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
|
31
31
|
versionCode 1
|
|
32
32
|
versionName "1.0"
|
|
33
33
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
@@ -61,5 +61,5 @@ dependencies {
|
|
|
61
61
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
62
62
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
63
63
|
implementation "androidx.core:core-ktx:$coreKtx"
|
|
64
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$
|
|
64
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
65
65
|
}
|
|
@@ -2,6 +2,7 @@ package com.capacitorjs.community.plugins.bluetoothle
|
|
|
2
2
|
|
|
3
3
|
import android.Manifest
|
|
4
4
|
import android.annotation.SuppressLint
|
|
5
|
+
import android.app.Activity
|
|
5
6
|
import android.bluetooth.BluetoothAdapter
|
|
6
7
|
import android.bluetooth.BluetoothAdapter.ACTION_REQUEST_ENABLE
|
|
7
8
|
import android.bluetooth.BluetoothDevice
|
|
@@ -24,6 +25,7 @@ import android.os.ParcelUuid
|
|
|
24
25
|
import android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS
|
|
25
26
|
import android.provider.Settings.ACTION_BLUETOOTH_SETTINGS
|
|
26
27
|
import android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
|
|
28
|
+
import androidx.activity.result.ActivityResult
|
|
27
29
|
import androidx.core.location.LocationManagerCompat
|
|
28
30
|
import com.getcapacitor.JSArray
|
|
29
31
|
import com.getcapacitor.JSObject
|
|
@@ -32,6 +34,7 @@ import com.getcapacitor.PermissionState
|
|
|
32
34
|
import com.getcapacitor.Plugin
|
|
33
35
|
import com.getcapacitor.PluginCall
|
|
34
36
|
import com.getcapacitor.PluginMethod
|
|
37
|
+
import com.getcapacitor.annotation.ActivityCallback
|
|
35
38
|
import com.getcapacitor.annotation.CapacitorPlugin
|
|
36
39
|
import com.getcapacitor.annotation.Permission
|
|
37
40
|
import com.getcapacitor.annotation.PermissionCallback
|
|
@@ -164,9 +167,18 @@ class BluetoothLe : Plugin() {
|
|
|
164
167
|
|
|
165
168
|
@PluginMethod
|
|
166
169
|
fun requestEnable(call: PluginCall) {
|
|
170
|
+
assertBluetoothAdapter(call) ?: return
|
|
167
171
|
val intent = Intent(ACTION_REQUEST_ENABLE)
|
|
168
|
-
|
|
169
|
-
|
|
172
|
+
startActivityForResult(call, intent, "handleRequestEnableResult")
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
@ActivityCallback
|
|
176
|
+
private fun handleRequestEnableResult(call: PluginCall, result: ActivityResult) {
|
|
177
|
+
if (result.resultCode == Activity.RESULT_OK) {
|
|
178
|
+
call.resolve()
|
|
179
|
+
} else {
|
|
180
|
+
call.reject("requestEnable failed.")
|
|
181
|
+
}
|
|
170
182
|
}
|
|
171
183
|
|
|
172
184
|
@PluginMethod
|
|
@@ -269,9 +269,9 @@ export interface BluetoothLePlugin {
|
|
|
269
269
|
stopLEScan(): Promise<void>;
|
|
270
270
|
getDevices(options: GetDevicesOptions): Promise<GetDevicesResult>;
|
|
271
271
|
getConnectedDevices(options: GetConnectedDevicesOptions): Promise<GetDevicesResult>;
|
|
272
|
-
addListener(eventName: 'onEnabledChanged', listenerFunc: (result: BooleanResult) => void): PluginListenerHandle
|
|
273
|
-
addListener(eventName: string, listenerFunc: (event: ReadResult) => void): PluginListenerHandle
|
|
274
|
-
addListener(eventName: 'onScanResult', listenerFunc: (result: ScanResultInternal) => void): PluginListenerHandle
|
|
272
|
+
addListener(eventName: 'onEnabledChanged', listenerFunc: (result: BooleanResult) => void): Promise<PluginListenerHandle>;
|
|
273
|
+
addListener(eventName: string, listenerFunc: (event: ReadResult) => void): Promise<PluginListenerHandle>;
|
|
274
|
+
addListener(eventName: 'onScanResult', listenerFunc: (result: ScanResultInternal) => void): Promise<PluginListenerHandle>;
|
|
275
275
|
connect(options: DeviceIdOptions & TimeoutOptions): Promise<void>;
|
|
276
276
|
createBond(options: DeviceIdOptions & TimeoutOptions): Promise<void>;
|
|
277
277
|
isBonded(options: DeviceIdOptions): Promise<BooleanResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAkDA;;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';\n\nimport type { DisplayStrings } from './config';\n\nexport interface InitializeOptions {\n /**\n * If your app doesn't use Bluetooth scan results to derive physical\n * location information, you can strongly assert that your app\n * doesn't derive physical location. (Android only)\n * Requires adding 'neverForLocation' to AndroidManifest.xml\n * https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location\n * @default false\n */\n androidNeverForLocation?: boolean;\n}\n\nexport interface RequestBleDeviceOptions {\n /**\n * Filter devices by service UUIDs.\n * UUIDs have to be specified as 128 bit UUID strings,\n * e.g. ['0000180d-0000-1000-8000-00805f9b34fb']\n * There is a helper function to convert numbers to UUIDs.\n * e.g. [numberToUUID(0x180f)]. (see [UUID format](#uuid-format))\n */\n services?: string[];\n /**\n * Filter devices by name\n */\n name?: string;\n /**\n * Filter devices by name prefix\n */\n namePrefix?: string;\n /**\n * For **web**, all services that will be used have to be listed under services or optionalServices,\n * e.g. [numberToUUID(0x180f)] (see [UUID format](#uuid-format))\n */\n optionalServices?: string[];\n /**\n * Normally scans will discard the second and subsequent advertisements from a single device.\n * If you need to receive them, set allowDuplicates to true (only applicable in `requestLEScan`).\n * (default: false)\n */\n allowDuplicates?: boolean;\n /**\n * Android scan mode (default: ScanMode.SCAN_MODE_BALANCED)\n */\n scanMode?: ScanMode;\n}\n\n/**\n * Android scan mode\n */\nexport enum ScanMode {\n /**\n * Perform Bluetooth LE scan in low power mode. This mode is enforced if the scanning application is not in foreground.\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_POWER\n */\n SCAN_MODE_LOW_POWER = 0,\n /**\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.\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_BALANCED\n */\n SCAN_MODE_BALANCED = 1,\n /**\n * Scan using highest duty cycle. It's recommended to only use this mode when the application is running in the foreground.\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_LATENCY\n */\n SCAN_MODE_LOW_LATENCY = 2,\n}\n\n/**\n * Android connection priority used in `requestConnectionPriority`\n */\nexport enum ConnectionPriority {\n /**\n * Use the connection parameters recommended by the Bluetooth SIG. This is the default value if no connection parameter update is requested.\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_BALANCED\n */\n CONNECTION_PRIORITY_BALANCED = 0,\n /**\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.\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_HIGH\n */\n CONNECTION_PRIORITY_HIGH = 1,\n /**\n * Request low power, reduced data rate connection parameters.\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER\n */\n CONNECTION_PRIORITY_LOW_POWER = 2,\n}\n\nexport interface BleDevice {\n /**\n * ID of the device, which will be needed for further calls.\n * On **Android** this is the BLE MAC address.\n * On **iOS** and **web** it is an identifier.\n */\n deviceId: string;\n /**\n * Name of the peripheral device.\n */\n name?: string;\n uuids?: string[];\n}\n\nexport interface DeviceIdOptions {\n deviceId: string;\n}\nexport interface TimeoutOptions {\n /**\n * Timeout in milliseconds for plugin call.\n * Default is 10000 for `connect` and 5000 for other plugin methods.\n */\n timeout?: number;\n}\n\nexport interface RequestConnectionPriorityOptions extends DeviceIdOptions {\n connectionPriority: ConnectionPriority;\n}\n\nexport interface GetDevicesOptions {\n deviceIds: string[];\n}\n\nexport interface GetConnectedDevicesOptions {\n services: string[];\n}\n\nexport interface BleService {\n readonly uuid: string;\n readonly characteristics: BleCharacteristic[];\n}\n\nexport interface BleDescriptor {\n readonly uuid: string;\n}\n\nexport interface BleCharacteristic {\n readonly uuid: string;\n readonly properties: BleCharacteristicProperties;\n readonly descriptors: BleDescriptor[];\n}\n\nexport interface BleCharacteristicProperties {\n readonly broadcast: boolean;\n readonly read: boolean;\n readonly writeWithoutResponse: boolean;\n readonly write: boolean;\n readonly notify: boolean;\n readonly indicate: boolean;\n readonly authenticatedSignedWrites: boolean;\n readonly reliableWrite?: boolean;\n readonly writableAuxiliaries?: boolean;\n readonly extendedProperties?: boolean;\n readonly notifyEncryptionRequired?: boolean;\n readonly indicateEncryptionRequired?: boolean;\n}\n\nexport interface BleServices {\n services: BleService[];\n}\n\nexport interface ReadOptions {\n deviceId: string;\n service: string;\n characteristic: string;\n}\n\nexport interface ReadDescriptorOptions {\n deviceId: string;\n service: string;\n characteristic: string;\n descriptor: string;\n}\n\nexport type Data = DataView | string;\n\nexport interface WriteOptions {\n deviceId: string;\n service: string;\n characteristic: string;\n /**\n * android, ios: string\n * web: DataView\n */\n value: Data;\n}\n\nexport interface WriteDescriptorOptions {\n deviceId: string;\n service: string;\n characteristic: string;\n descriptor: string;\n /**\n * android, ios: string\n * web: DataView\n */\n value: Data;\n}\n\nexport interface BooleanResult {\n value: boolean;\n}\n\nexport interface GetDevicesResult {\n devices: BleDevice[];\n}\n\nexport interface GetMtuResult {\n value: number;\n}\n\nexport interface ReadRssiResult {\n value: string;\n}\n\nexport interface ReadResult {\n /**\n * android, ios: string\n * web: DataView\n */\n value?: Data;\n}\n\nexport interface ScanResultInternal<T = Data> {\n device: BleDevice;\n localName?: string;\n rssi?: number;\n txPower?: number;\n manufacturerData?: { [key: string]: T };\n serviceData?: { [key: string]: T };\n uuids?: string[];\n rawAdvertisement?: T;\n}\n\nexport interface ScanResult {\n /**\n * 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.\n */\n device: BleDevice;\n /**\n * The name of the peripheral device from the advertisement data.\n */\n localName?: string;\n /**\n * Received Signal Strength Indication.\n */\n rssi?: number;\n /**\n * Transmit power in dBm. A value of 127 indicates that it is not available.\n */\n txPower?: number;\n /**\n * Manufacturer data, key is a company identifier and value is the data.\n */\n manufacturerData?: { [key: string]: DataView };\n /**\n * Service data, key is a service UUID and value is the data.\n */\n serviceData?: { [key: string]: DataView };\n /**\n * Advertised services.\n */\n uuids?: string[];\n /**\n * Raw advertisement data (**Android** only).\n */\n rawAdvertisement?: DataView;\n}\n\nexport interface BluetoothLePlugin {\n initialize(options?: InitializeOptions): Promise<void>;\n isEnabled(): Promise<BooleanResult>;\n requestEnable(): Promise<void>;\n enable(): Promise<void>;\n disable(): Promise<void>;\n startEnabledNotifications(): Promise<void>;\n stopEnabledNotifications(): Promise<void>;\n isLocationEnabled(): Promise<BooleanResult>;\n openLocationSettings(): Promise<void>;\n openBluetoothSettings(): Promise<void>;\n openAppSettings(): Promise<void>;\n setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;\n requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;\n requestLEScan(options?: RequestBleDeviceOptions): Promise<void>;\n stopLEScan(): Promise<void>;\n getDevices(options: GetDevicesOptions): Promise<GetDevicesResult>;\n getConnectedDevices(options: GetConnectedDevicesOptions): Promise<GetDevicesResult>;\n addListener(eventName: 'onEnabledChanged', listenerFunc: (result: BooleanResult) => void): PluginListenerHandle;\n addListener(eventName: string, listenerFunc: (event: ReadResult) => void): PluginListenerHandle;\n addListener(eventName: 'onScanResult', listenerFunc: (result: ScanResultInternal) => void): PluginListenerHandle;\n connect(options: DeviceIdOptions & TimeoutOptions): Promise<void>;\n createBond(options: DeviceIdOptions & TimeoutOptions): Promise<void>;\n isBonded(options: DeviceIdOptions): Promise<BooleanResult>;\n disconnect(options: DeviceIdOptions): Promise<void>;\n getServices(options: DeviceIdOptions): Promise<BleServices>;\n discoverServices(options: DeviceIdOptions): Promise<void>;\n getMtu(options: DeviceIdOptions): Promise<GetMtuResult>;\n requestConnectionPriority(options: RequestConnectionPriorityOptions): Promise<void>;\n readRssi(options: DeviceIdOptions): Promise<ReadRssiResult>;\n read(options: ReadOptions & TimeoutOptions): Promise<ReadResult>;\n write(options: WriteOptions & TimeoutOptions): Promise<void>;\n writeWithoutResponse(options: WriteOptions & TimeoutOptions): Promise<void>;\n readDescriptor(options: ReadDescriptorOptions & TimeoutOptions): Promise<ReadResult>;\n writeDescriptor(options: WriteDescriptorOptions & TimeoutOptions): Promise<void>;\n startNotifications(options: ReadOptions): Promise<void>;\n stopNotifications(options: ReadOptions): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAkDA;;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';\n\nimport type { DisplayStrings } from './config';\n\nexport interface InitializeOptions {\n /**\n * If your app doesn't use Bluetooth scan results to derive physical\n * location information, you can strongly assert that your app\n * doesn't derive physical location. (Android only)\n * Requires adding 'neverForLocation' to AndroidManifest.xml\n * https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location\n * @default false\n */\n androidNeverForLocation?: boolean;\n}\n\nexport interface RequestBleDeviceOptions {\n /**\n * Filter devices by service UUIDs.\n * UUIDs have to be specified as 128 bit UUID strings,\n * e.g. ['0000180d-0000-1000-8000-00805f9b34fb']\n * There is a helper function to convert numbers to UUIDs.\n * e.g. [numberToUUID(0x180f)]. (see [UUID format](#uuid-format))\n */\n services?: string[];\n /**\n * Filter devices by name\n */\n name?: string;\n /**\n * Filter devices by name prefix\n */\n namePrefix?: string;\n /**\n * For **web**, all services that will be used have to be listed under services or optionalServices,\n * e.g. [numberToUUID(0x180f)] (see [UUID format](#uuid-format))\n */\n optionalServices?: string[];\n /**\n * Normally scans will discard the second and subsequent advertisements from a single device.\n * If you need to receive them, set allowDuplicates to true (only applicable in `requestLEScan`).\n * (default: false)\n */\n allowDuplicates?: boolean;\n /**\n * Android scan mode (default: ScanMode.SCAN_MODE_BALANCED)\n */\n scanMode?: ScanMode;\n}\n\n/**\n * Android scan mode\n */\nexport enum ScanMode {\n /**\n * Perform Bluetooth LE scan in low power mode. This mode is enforced if the scanning application is not in foreground.\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_POWER\n */\n SCAN_MODE_LOW_POWER = 0,\n /**\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.\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_BALANCED\n */\n SCAN_MODE_BALANCED = 1,\n /**\n * Scan using highest duty cycle. It's recommended to only use this mode when the application is running in the foreground.\n * https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_LATENCY\n */\n SCAN_MODE_LOW_LATENCY = 2,\n}\n\n/**\n * Android connection priority used in `requestConnectionPriority`\n */\nexport enum ConnectionPriority {\n /**\n * Use the connection parameters recommended by the Bluetooth SIG. This is the default value if no connection parameter update is requested.\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_BALANCED\n */\n CONNECTION_PRIORITY_BALANCED = 0,\n /**\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.\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_HIGH\n */\n CONNECTION_PRIORITY_HIGH = 1,\n /**\n * Request low power, reduced data rate connection parameters.\n * https://developer.android.com/reference/android/bluetooth/BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER\n */\n CONNECTION_PRIORITY_LOW_POWER = 2,\n}\n\nexport interface BleDevice {\n /**\n * ID of the device, which will be needed for further calls.\n * On **Android** this is the BLE MAC address.\n * On **iOS** and **web** it is an identifier.\n */\n deviceId: string;\n /**\n * Name of the peripheral device.\n */\n name?: string;\n uuids?: string[];\n}\n\nexport interface DeviceIdOptions {\n deviceId: string;\n}\nexport interface TimeoutOptions {\n /**\n * Timeout in milliseconds for plugin call.\n * Default is 10000 for `connect` and 5000 for other plugin methods.\n */\n timeout?: number;\n}\n\nexport interface RequestConnectionPriorityOptions extends DeviceIdOptions {\n connectionPriority: ConnectionPriority;\n}\n\nexport interface GetDevicesOptions {\n deviceIds: string[];\n}\n\nexport interface GetConnectedDevicesOptions {\n services: string[];\n}\n\nexport interface BleService {\n readonly uuid: string;\n readonly characteristics: BleCharacteristic[];\n}\n\nexport interface BleDescriptor {\n readonly uuid: string;\n}\n\nexport interface BleCharacteristic {\n readonly uuid: string;\n readonly properties: BleCharacteristicProperties;\n readonly descriptors: BleDescriptor[];\n}\n\nexport interface BleCharacteristicProperties {\n readonly broadcast: boolean;\n readonly read: boolean;\n readonly writeWithoutResponse: boolean;\n readonly write: boolean;\n readonly notify: boolean;\n readonly indicate: boolean;\n readonly authenticatedSignedWrites: boolean;\n readonly reliableWrite?: boolean;\n readonly writableAuxiliaries?: boolean;\n readonly extendedProperties?: boolean;\n readonly notifyEncryptionRequired?: boolean;\n readonly indicateEncryptionRequired?: boolean;\n}\n\nexport interface BleServices {\n services: BleService[];\n}\n\nexport interface ReadOptions {\n deviceId: string;\n service: string;\n characteristic: string;\n}\n\nexport interface ReadDescriptorOptions {\n deviceId: string;\n service: string;\n characteristic: string;\n descriptor: string;\n}\n\nexport type Data = DataView | string;\n\nexport interface WriteOptions {\n deviceId: string;\n service: string;\n characteristic: string;\n /**\n * android, ios: string\n * web: DataView\n */\n value: Data;\n}\n\nexport interface WriteDescriptorOptions {\n deviceId: string;\n service: string;\n characteristic: string;\n descriptor: string;\n /**\n * android, ios: string\n * web: DataView\n */\n value: Data;\n}\n\nexport interface BooleanResult {\n value: boolean;\n}\n\nexport interface GetDevicesResult {\n devices: BleDevice[];\n}\n\nexport interface GetMtuResult {\n value: number;\n}\n\nexport interface ReadRssiResult {\n value: string;\n}\n\nexport interface ReadResult {\n /**\n * android, ios: string\n * web: DataView\n */\n value?: Data;\n}\n\nexport interface ScanResultInternal<T = Data> {\n device: BleDevice;\n localName?: string;\n rssi?: number;\n txPower?: number;\n manufacturerData?: { [key: string]: T };\n serviceData?: { [key: string]: T };\n uuids?: string[];\n rawAdvertisement?: T;\n}\n\nexport interface ScanResult {\n /**\n * 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.\n */\n device: BleDevice;\n /**\n * The name of the peripheral device from the advertisement data.\n */\n localName?: string;\n /**\n * Received Signal Strength Indication.\n */\n rssi?: number;\n /**\n * Transmit power in dBm. A value of 127 indicates that it is not available.\n */\n txPower?: number;\n /**\n * Manufacturer data, key is a company identifier and value is the data.\n */\n manufacturerData?: { [key: string]: DataView };\n /**\n * Service data, key is a service UUID and value is the data.\n */\n serviceData?: { [key: string]: DataView };\n /**\n * Advertised services.\n */\n uuids?: string[];\n /**\n * Raw advertisement data (**Android** only).\n */\n rawAdvertisement?: DataView;\n}\n\nexport interface BluetoothLePlugin {\n initialize(options?: InitializeOptions): Promise<void>;\n isEnabled(): Promise<BooleanResult>;\n requestEnable(): Promise<void>;\n enable(): Promise<void>;\n disable(): Promise<void>;\n startEnabledNotifications(): Promise<void>;\n stopEnabledNotifications(): Promise<void>;\n isLocationEnabled(): Promise<BooleanResult>;\n openLocationSettings(): Promise<void>;\n openBluetoothSettings(): Promise<void>;\n openAppSettings(): Promise<void>;\n setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;\n requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;\n requestLEScan(options?: RequestBleDeviceOptions): Promise<void>;\n stopLEScan(): Promise<void>;\n getDevices(options: GetDevicesOptions): Promise<GetDevicesResult>;\n getConnectedDevices(options: GetConnectedDevicesOptions): Promise<GetDevicesResult>;\n addListener(\n eventName: 'onEnabledChanged',\n listenerFunc: (result: BooleanResult) => void\n ): Promise<PluginListenerHandle>;\n addListener(eventName: string, listenerFunc: (event: ReadResult) => void): Promise<PluginListenerHandle>;\n addListener(\n eventName: 'onScanResult',\n listenerFunc: (result: ScanResultInternal) => void\n ): Promise<PluginListenerHandle>;\n connect(options: DeviceIdOptions & TimeoutOptions): Promise<void>;\n createBond(options: DeviceIdOptions & TimeoutOptions): Promise<void>;\n isBonded(options: DeviceIdOptions): Promise<BooleanResult>;\n disconnect(options: DeviceIdOptions): Promise<void>;\n getServices(options: DeviceIdOptions): Promise<BleServices>;\n discoverServices(options: DeviceIdOptions): Promise<void>;\n getMtu(options: DeviceIdOptions): Promise<GetMtuResult>;\n requestConnectionPriority(options: RequestConnectionPriorityOptions): Promise<void>;\n readRssi(options: DeviceIdOptions): Promise<ReadRssiResult>;\n read(options: ReadOptions & TimeoutOptions): Promise<ReadResult>;\n write(options: WriteOptions & TimeoutOptions): Promise<void>;\n writeWithoutResponse(options: WriteOptions & TimeoutOptions): Promise<void>;\n readDescriptor(options: ReadDescriptorOptions & TimeoutOptions): Promise<ReadResult>;\n writeDescriptor(options: WriteDescriptorOptions & TimeoutOptions): Promise<void>;\n startNotifications(options: ReadOptions): Promise<void>;\n stopNotifications(options: ReadOptions): Promise<void>;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/bluetooth-le",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-0",
|
|
4
4
|
"description": "Capacitor plugin for Bluetooth Low Energy ",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"unpkg": "dist/plugin.js",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
11
|
-
"verify:ios": "set -o pipefail && cd ios && pod install && xcodebuild clean build test -workspace Plugin.xcworkspace -scheme Plugin -destination \"platform=iOS Simulator,name=iPhone
|
|
11
|
+
"verify:ios": "set -o pipefail && cd ios && pod install && xcodebuild clean build test -workspace Plugin.xcworkspace -scheme Plugin -destination \"platform=iOS Simulator,name=iPhone 15\" | xcpretty && cd ..",
|
|
12
12
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
13
13
|
"verify:web": "npm run test:coverage && npm run build",
|
|
14
14
|
"lint": "npm run eslint && npm run prettier -- --check && npm run lint:ios",
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"author": "pwespi",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@types/web-bluetooth": "^0.0.
|
|
38
|
+
"@types/web-bluetooth": "^0.0.20"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@capacitor/android": "
|
|
42
|
-
"@capacitor/cli": "
|
|
43
|
-
"@capacitor/core": "
|
|
41
|
+
"@capacitor/android": "next",
|
|
42
|
+
"@capacitor/cli": "next",
|
|
43
|
+
"@capacitor/core": "next",
|
|
44
44
|
"@capacitor/docgen": "0.2.0",
|
|
45
|
-
"@capacitor/ios": "
|
|
45
|
+
"@capacitor/ios": "next",
|
|
46
46
|
"@ionic/eslint-config": "^0.3.0",
|
|
47
47
|
"@ionic/prettier-config": "^2.0.0",
|
|
48
48
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"typescript": "~4.9.4"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@capacitor/core": "
|
|
64
|
+
"@capacitor/core": "next"
|
|
65
65
|
},
|
|
66
66
|
"files": [
|
|
67
67
|
"android/src/main/",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"url": "https://github.com/capacitor-community/bluetooth-le/issues"
|
|
98
98
|
},
|
|
99
99
|
"volta": {
|
|
100
|
-
"node": "
|
|
101
|
-
"npm": "
|
|
100
|
+
"node": "20.11.0",
|
|
101
|
+
"npm": "10.4.0"
|
|
102
102
|
}
|
|
103
103
|
}
|