@capacitor-community/bluetooth-le
Advanced tools
Comparing version 1.6.0 to 1.6.1-2-g6ad3879
@@ -10,8 +10,16 @@ { | ||
"name": "initialize", | ||
"signature": "() => Promise<void>", | ||
"parameters": [], | ||
"signature": "(options?: InitializeOptions | undefined) => Promise<void>", | ||
"parameters": [ | ||
{ | ||
"name": "options", | ||
"docs": "", | ||
"type": "InitializeOptions | undefined" | ||
} | ||
], | ||
"returns": "Promise<void>", | ||
"tags": [], | ||
"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).", | ||
"complexTypes": [], | ||
"complexTypes": [ | ||
"InitializeOptions" | ||
], | ||
"slug": "initialize" | ||
@@ -314,3 +322,3 @@ }, | ||
], | ||
"docs": "Create a bond with a peripheral BLE device.\nOnly available on Android.", | ||
"docs": "Create a bond with a peripheral BLE device.\nOnly available on **Android**. On iOS bonding is handled by the OS.", | ||
"complexTypes": [], | ||
@@ -336,3 +344,3 @@ "slug": "createbond" | ||
], | ||
"docs": "Report whether a peripheral BLE device is bonded.\nOnly available on Android.", | ||
"docs": "Report whether a peripheral BLE device is bonded.\nOnly available on **Android**. On iOS bonding is handled by the OS.", | ||
"complexTypes": [], | ||
@@ -379,3 +387,3 @@ "slug": "isbonded" | ||
], | ||
"docs": "Get services and characteristics of device.", | ||
"docs": "Get services, characteristics and descriptors of a device.", | ||
"complexTypes": [ | ||
@@ -751,2 +759,23 @@ "BleService" | ||
{ | ||
"name": "InitializeOptions", | ||
"slug": "initializeoptions", | ||
"docs": "", | ||
"tags": [], | ||
"methods": [], | ||
"properties": [ | ||
{ | ||
"name": "androidNeverForLocation", | ||
"tags": [ | ||
{ | ||
"text": "false", | ||
"name": "default" | ||
} | ||
], | ||
"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", | ||
"complexTypes": [], | ||
"type": "boolean | undefined" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "DisplayStrings", | ||
@@ -753,0 +782,0 @@ "slug": "displaystrings", |
import type { DisplayStrings } from './config'; | ||
import type { BleDevice, BleService, ConnectOptions, RequestBleDeviceOptions, ScanResult } from './definitions'; | ||
import type { BleDevice, BleService, ConnectOptions, InitializeOptions, RequestBleDeviceOptions, ScanResult } from './definitions'; | ||
export interface BleClientInterface { | ||
@@ -9,3 +9,3 @@ /** | ||
*/ | ||
initialize(): Promise<void>; | ||
initialize(options?: InitializeOptions): Promise<void>; | ||
/** | ||
@@ -107,3 +107,3 @@ * Reports whether Bluetooth is enabled on this device. | ||
* Create a bond with a peripheral BLE device. | ||
* Only available on Android. | ||
* Only available on **Android**. On iOS bonding is handled by the OS. | ||
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan)) | ||
@@ -114,3 +114,3 @@ */ | ||
* Report whether a peripheral BLE device is bonded. | ||
* Only available on Android. | ||
* Only available on **Android**. On iOS bonding is handled by the OS. | ||
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan)) | ||
@@ -125,3 +125,3 @@ */ | ||
/** | ||
* Get services and characteristics of device. | ||
* Get services, characteristics and descriptors of a device. | ||
* @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan)) | ||
@@ -198,3 +198,3 @@ */ | ||
disableQueue(): void; | ||
initialize(): Promise<void>; | ||
initialize(options?: InitializeOptions): Promise<void>; | ||
/** | ||
@@ -201,0 +201,0 @@ * Reports whether BLE is enabled on this device. |
@@ -18,5 +18,5 @@ import { Capacitor } from '@capacitor/core'; | ||
} | ||
async initialize() { | ||
async initialize(options) { | ||
await this.queue(async () => { | ||
await BluetoothLe.initialize(); | ||
await BluetoothLe.initialize(options); | ||
}); | ||
@@ -23,0 +23,0 @@ } |
@@ -31,3 +31,3 @@ /** | ||
export function numberToUUID(value) { | ||
return `0000${value.toString(16)}-0000-1000-8000-00805f9b34fb`; | ||
return `0000${value.toString(16).padStart(4, '0')}-0000-1000-8000-00805f9b34fb`; | ||
} | ||
@@ -34,0 +34,0 @@ export function hexStringToDataView(value) { |
import type { PluginListenerHandle } from '@capacitor/core'; | ||
import type { DisplayStrings } from './config'; | ||
export interface InitializeOptions { | ||
/** | ||
* If your app doesn't use Bluetooth scan results to derive physical | ||
* location information, you can strongly assert that your app | ||
* doesn't derive physical location. (Android only) | ||
* Requires adding 'neverForLocation' to AndroidManifest.xml | ||
* https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location | ||
* @default false | ||
*/ | ||
androidNeverForLocation?: boolean; | ||
} | ||
export interface RequestBleDeviceOptions { | ||
@@ -217,3 +228,3 @@ /** | ||
export interface BluetoothLePlugin { | ||
initialize(): Promise<void>; | ||
initialize(options?: InitializeOptions): Promise<void>; | ||
isEnabled(): Promise<BooleanResult>; | ||
@@ -220,0 +231,0 @@ enable(): Promise<void>; |
@@ -64,3 +64,3 @@ 'use strict'; | ||
function numberToUUID(value) { | ||
return `0000${value.toString(16)}-0000-1000-8000-00805f9b34fb`; | ||
return `0000${value.toString(16).padStart(4, '0')}-0000-1000-8000-00805f9b34fb`; | ||
} | ||
@@ -144,5 +144,5 @@ function hexStringToDataView(value) { | ||
} | ||
async initialize() { | ||
async initialize(options) { | ||
await this.queue(async () => { | ||
await BluetoothLe$1.initialize(); | ||
await BluetoothLe$1.initialize(options); | ||
}); | ||
@@ -149,0 +149,0 @@ } |
@@ -60,3 +60,3 @@ var capacitorCommunityBluetoothLe = (function (exports, core, throat) { | ||
function numberToUUID(value) { | ||
return `0000${value.toString(16)}-0000-1000-8000-00805f9b34fb`; | ||
return `0000${value.toString(16).padStart(4, '0')}-0000-1000-8000-00805f9b34fb`; | ||
} | ||
@@ -140,5 +140,5 @@ function hexStringToDataView(value) { | ||
} | ||
async initialize() { | ||
async initialize(options) { | ||
await this.queue(async () => { | ||
await BluetoothLe$1.initialize(); | ||
await BluetoothLe$1.initialize(options); | ||
}); | ||
@@ -145,0 +145,0 @@ } |
{ | ||
"name": "@capacitor-community/bluetooth-le", | ||
"version": "1.6.0", | ||
"version": "1.6.1-2-g6ad3879", | ||
"description": "Capacitor plugin for Bluetooth Low Energy ", | ||
@@ -36,25 +36,26 @@ "main": "dist/plugin.cjs.js", | ||
"dependencies": { | ||
"@types/web-bluetooth": "^0.0.11", | ||
"@types/web-bluetooth": "^0.0.12", | ||
"throat": "^6.0.1" | ||
}, | ||
"devDependencies": { | ||
"@capacitor/android": "^3.2.5", | ||
"@capacitor/cli": "^3.2.5", | ||
"@capacitor/core": "^3.2.5", | ||
"@capacitor/docgen": "^0.0.18", | ||
"@capacitor/ios": "^3.2.5", | ||
"@capacitor/android": "^3.3.3", | ||
"@capacitor/cli": "^3.3.3", | ||
"@capacitor/core": "^3.3.3", | ||
"@capacitor/docgen": "0.0.18", | ||
"@capacitor/ios": "^3.3.3", | ||
"@ionic/eslint-config": "^0.3.0", | ||
"@ionic/prettier-config": "^2.0.0", | ||
"@ionic/swiftlint-config": "^1.1.2", | ||
"@types/jest": "^27.0.2", | ||
"eslint": "^7.0.0", | ||
"jest": "^27.3.1", | ||
"prettier": "^2.4.1", | ||
"prettier-plugin-java": "^1.5.0", | ||
"@types/jest": "^27.4.0", | ||
"@typescript-eslint/eslint-plugin": "^5.8.1", | ||
"eslint": "^8.6.0", | ||
"jest": "^27.4.5", | ||
"prettier": "^2.5.1", | ||
"prettier-plugin-java": "^1.6.0", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.58.3", | ||
"rollup": "^2.62.0", | ||
"standard-version": "^9.3.2", | ||
"swiftlint": "^1.0.1", | ||
"ts-jest": "^27.0.7", | ||
"typescript": "~4.4.4" | ||
"ts-jest": "^27.1.2", | ||
"typescript": "~4.5.4" | ||
}, | ||
@@ -96,3 +97,7 @@ "peerDependencies": { | ||
"url": "https://github.com/capacitor-community/bluetooth-le/issues" | ||
}, | ||
"volta": { | ||
"node": "16.13.1", | ||
"npm": "8.3.0" | ||
} | ||
} |
@@ -9,3 +9,3 @@ <p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p> | ||
<p align="center"> | ||
<img src="https://img.shields.io/maintenance/yes/2021?style=flat-square" /> | ||
<img src="https://img.shields.io/maintenance/yes/2022?style=flat-square" /> | ||
<a href="https://github.com/capacitor-community/bluetooth-le/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/capacitor-community/bluetooth-le/CI?style=flat-square" /></a> | ||
@@ -17,3 +17,3 @@ <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> | ||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> | ||
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-6-orange?style=flat-square" /></a> | ||
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-7-orange?style=flat-square" /></a> | ||
<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
@@ -47,3 +47,3 @@ </p> | ||
- [`initialize()`](#initialize) | ||
- [`initialize(...)`](#initialize) | ||
- [`isEnabled()`](#isenabled) | ||
@@ -122,2 +122,30 @@ - [`enable()`](#enable) | ||
#### (Optional) Android 12 Bluetooth permissions | ||
If your app targets Android 12 (API level 31) or higher and your app doesn't use Bluetooth scan results to derive physical location information, you can strongly assert that your app doesn't derive physical location. This allows the app to scan for Bluetooth devices without asking for location permissions. See the [Android documentation](https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#declare-android12-or-higher). | ||
This requires `compileSdkVersion` and `targetSdkVersion` 31. | ||
To strongly assert that your app doesn't derive physical location, update your app's manifest file. | ||
`./android/app/src/main/AndroidManifest.xml`: | ||
```diff | ||
<!-- Permissions --> | ||
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" /> | ||
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" /> | ||
+ <uses-permission android:name="android.permission.BLUETOOTH_SCAN" | ||
+ android:usesPermissionFlags="neverForLocation" | ||
+ tools:targetApi="s" /> | ||
``` | ||
And set the `androidNeverForLocation` flag to `true` when initializing the `BleClient`. | ||
```ts | ||
import { BleClient } from '@capacitor-community/bluetooth-le'; | ||
await BleClient.initialize({ androidNeverForLocation: true }); | ||
``` | ||
This way the app will not ask for location permissions. | ||
## Configuration | ||
@@ -198,3 +226,4 @@ | ||
await BleClient.connect(device.deviceId); | ||
// connect to device, the onDisconnect callback is optional | ||
await BleClient.connect(device.deviceId, (deviceId) => onDisconnect(deviceId)); | ||
console.log('connected to device', device); | ||
@@ -220,2 +249,3 @@ | ||
// disconnect after 10 sec | ||
setTimeout(async () => { | ||
@@ -231,2 +261,6 @@ await BleClient.stopNotifications(device.deviceId, HEART_RATE_SERVICE, HEART_RATE_MEASUREMENT_CHARACTERISTIC); | ||
function onDisconnect(deviceId: string): void { | ||
console.log(`device ${deviceId} disconnected`); | ||
} | ||
function parseHeartRate(value: DataView): number { | ||
@@ -329,6 +363,6 @@ const flags = value.getUint8(0); | ||
### initialize() | ||
### initialize(...) | ||
```typescript | ||
initialize() => Promise<void> | ||
initialize(options?: InitializeOptions | undefined) => Promise<void> | ||
``` | ||
@@ -340,2 +374,6 @@ | ||
| Param | Type | | ||
| ------------- | --------------------------------------------------------------- | | ||
| **`options`** | <code><a href="#initializeoptions">InitializeOptions</a></code> | | ||
--- | ||
@@ -571,3 +609,3 @@ | ||
Create a bond with a peripheral BLE device. | ||
Only available on Android. | ||
Only available on **Android**. On iOS bonding is handled by the OS. | ||
@@ -587,3 +625,3 @@ | Param | Type | Description | | ||
Report whether a peripheral BLE device is bonded. | ||
Only available on Android. | ||
Only available on **Android**. On iOS bonding is handled by the OS. | ||
@@ -618,3 +656,3 @@ | Param | Type | Description | | ||
Get services and characteristics of device. | ||
Get services, characteristics and descriptors of a device. | ||
@@ -770,2 +808,8 @@ | Param | Type | Description | | ||
#### InitializeOptions | ||
| Prop | Type | Description | Default | | ||
| ----------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | | ||
| **`androidNeverForLocation`** | <code>boolean</code> | If your app doesn't use Bluetooth scan results to derive physical location information, you can strongly assert that your app doesn't derive physical location. (Android only) Requires adding 'neverForLocation' to AndroidManifest.xml https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location | <code>false</code> | | ||
#### DisplayStrings | ||
@@ -952,2 +996,3 @@ | ||
<td align="center"><a href="http://www.gnucoop.com"><img src="https://avatars.githubusercontent.com/u/1615301?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Marco Marche</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=trik" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/JFKakaJFK"><img src="https://avatars.githubusercontent.com/u/13108477?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Johannes Koch</b></sub></a><br /><a href="https://github.com/capacitor-community/bluetooth-le/commits?author=JFKakaJFK" title="Code">💻</a></td> | ||
</tr> | ||
@@ -954,0 +999,0 @@ </table> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4811
993
511084
20
57
2
+ Added@types/web-bluetooth@0.0.12(transitive)
- Removed@types/web-bluetooth@0.0.11(transitive)
Updated@types/web-bluetooth@^0.0.12