@capacitor-community/bluetooth-le 2.2.2 → 2.3.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
@@ -50,6 +50,7 @@ Below is an index of all the methods available.
50
50
 
51
51
  - [`initialize(...)`](#initialize)
52
52
  - [`isEnabled()`](#isenabled)
53
+ - [`requestEnable()`](#requestenable)
53
54
  - [`enable()`](#enable)
54
55
  - [`disable()`](#disable)
55
56
  - [`startEnabledNotifications(...)`](#startenablednotifications)
@@ -320,6 +321,7 @@ _Note_: web support depends on the browser, see [implementation status](https://
320
321
  | -------------------------------------------------------------- | :-----: | :-: | :-: |
321
322
  | [`initialize()`](#initialize) | ✅ | ✅ | ✅ |
322
323
  | [`isEnabled()`](#isenabled) | ✅ | ✅ | -- |
324
+ | [`requestEnable()`](#requestEnable) | ✅ | ❌ | ❌ |
323
325
  | [`enable()`](#enable) | ✅ | ❌ | ❌ |
324
326
  | [`disable()`](#disable) | ✅ | ❌ | ❌ |
325
327
  | [`startEnabledNotifications(...)`](#startenablednotifications) | ✅ | ✅ | -- |
@@ -392,6 +394,17 @@ Always returns `true` on **web**.
392
394
 
393
395
  ---
394
396
 
397
+ ### requestEnable()
398
+
399
+ ```typescript
400
+ requestEnable() => Promise<void>
401
+ ```
402
+
403
+ 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
404
+ Only available on **Android**.
405
+
406
+ ---
407
+
395
408
  ### enable()
396
409
 
397
410
  ```typescript
@@ -400,6 +413,7 @@ enable() => Promise<void>
400
413
 
401
414
  Enable Bluetooth.
402
415
  Only available on **Android**.
416
+ **Deprecated** Will fail on Android SDK &gt;= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()
403
417
 
404
418
  ---
405
419
 
@@ -411,6 +425,7 @@ disable() => Promise<void>
411
425
 
412
426
  Disable Bluetooth.
413
427
  Only available on **Android**.
428
+ **Deprecated** Will fail on Android SDK &gt;= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()
414
429
 
415
430
  ---
416
431
 
@@ -527,7 +542,7 @@ requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) =
527
542
 
528
543
  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.
529
544
  Scanning will continue until `stopLEScan` is called. For an example, see [usage](#usage).
530
- **NOTE**: Use with care on **web** platform, the required API is still behind a flag in most browsers.
545
+ **Note**: Use with care on **web** platform, the required API is still behind a flag in most browsers.
531
546
 
532
547
  | Param | Type |
533
548
  | -------------- | --------------------------------------------------------------------------- |
@@ -1,7 +1,14 @@
1
1
  package com.capacitorjs.community.plugins.bluetoothle
2
2
 
3
3
  import android.Manifest
4
- import android.bluetooth.*
4
+ import android.app.Activity
5
+ import android.bluetooth.BluetoothAdapter
6
+ import android.bluetooth.BluetoothAdapter.ACTION_REQUEST_ENABLE
7
+ import android.bluetooth.BluetoothDevice
8
+ import android.bluetooth.BluetoothGatt
9
+ import android.bluetooth.BluetoothGattCharacteristic
10
+ import android.bluetooth.BluetoothManager
11
+ import android.bluetooth.BluetoothProfile
5
12
  import android.bluetooth.le.ScanFilter
6
13
  import android.bluetooth.le.ScanResult
7
14
  import android.bluetooth.le.ScanSettings
@@ -14,13 +21,23 @@ import android.location.LocationManager
14
21
  import android.net.Uri
15
22
  import android.os.Build
16
23
  import android.os.ParcelUuid
17
- import android.provider.Settings.*
24
+ import android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS
25
+ import android.provider.Settings.ACTION_BLUETOOTH_SETTINGS
26
+ import android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
27
+ import androidx.activity.result.ActivityResult
18
28
  import androidx.core.location.LocationManagerCompat
19
- import com.getcapacitor.*
29
+ import com.getcapacitor.JSArray
30
+ import com.getcapacitor.JSObject
31
+ import com.getcapacitor.Logger
32
+ import com.getcapacitor.PermissionState
33
+ import com.getcapacitor.Plugin
34
+ import com.getcapacitor.PluginCall
35
+ import com.getcapacitor.PluginMethod
36
+ import com.getcapacitor.annotation.ActivityCallback
20
37
  import com.getcapacitor.annotation.CapacitorPlugin
21
38
  import com.getcapacitor.annotation.Permission
22
39
  import com.getcapacitor.annotation.PermissionCallback
23
- import java.util.*
40
+ import java.util.UUID
24
41
 
25
42
 
26
43
  @CapacitorPlugin(
@@ -147,6 +164,22 @@ class BluetoothLe : Plugin() {
147
164
  call.resolve(result)
148
165
  }
149
166
 
167
+ @PluginMethod
168
+ fun requestEnable(call: PluginCall) {
169
+ assertBluetoothAdapter(call) ?: return
170
+ val intent = Intent(ACTION_REQUEST_ENABLE)
171
+ startActivityForResult(call, intent, "handleRequestEnableResult")
172
+ }
173
+
174
+ @ActivityCallback
175
+ private fun handleRequestEnableResult(call: PluginCall, result: ActivityResult) {
176
+ if (result.resultCode == Activity.RESULT_OK) {
177
+ call.resolve()
178
+ } else {
179
+ call.reject("requestEnable failed.")
180
+ }
181
+ }
182
+
150
183
  @PluginMethod
151
184
  fun enable(call: PluginCall) {
152
185
  assertBluetoothAdapter(call) ?: return
@@ -187,6 +187,12 @@ class Device(
187
187
  ) {
188
188
  val key = "connect"
189
189
  callbackMap[key] = callback
190
+ if (isConnected()) {
191
+ resolve(key, "Already connected.")
192
+ return
193
+ }
194
+ bluetoothGatt?.close()
195
+ connectionState = STATE_CONNECTING
190
196
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
191
197
  bluetoothGatt = device.connectGatt(
192
198
  context, false, gattCallback, BluetoothDevice.TRANSPORT_LE
@@ -196,7 +202,6 @@ class Device(
196
202
  context, false, gattCallback
197
203
  )
198
204
  }
199
- connectionState = STATE_CONNECTING
200
205
  setConnectionTimeout(key, "Connection timeout.", bluetoothGatt, timeout)
201
206
  }
202
207
 
@@ -205,7 +210,7 @@ class Device(
205
210
  }
206
211
 
207
212
  fun isConnected(): Boolean {
208
- return connectionState == STATE_CONNECTED
213
+ return bluetoothGatt != null && connectionState == STATE_CONNECTED
209
214
  }
210
215
 
211
216
  private fun requestMtu(mtu: Int) {
@@ -541,6 +546,7 @@ class Device(
541
546
  val handler = Handler(Looper.getMainLooper())
542
547
  timeoutMap[key] = handler
543
548
  handler.postDelayed({
549
+ connectionState = STATE_DISCONNECTED
544
550
  gatt?.disconnect()
545
551
  gatt?.close()
546
552
  reject(key, message)
package/dist/docs.json CHANGED
@@ -34,12 +34,27 @@
34
34
  "slug": "isenabled"
35
35
  },
36
36
  {
37
- "name": "enable",
37
+ "name": "requestEnable",
38
38
  "signature": "() => Promise<void>",
39
39
  "parameters": [],
40
40
  "returns": "Promise<void>",
41
41
  "tags": [],
42
- "docs": "Enable Bluetooth.\nOnly available on **Android**.",
42
+ "docs": "Request enabling Bluetooth. Show a system activity that allows the user to turn on Bluetooth. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#ACTION_REQUEST_ENABLE\nOnly available on **Android**.",
43
+ "complexTypes": [],
44
+ "slug": "requestenable"
45
+ },
46
+ {
47
+ "name": "enable",
48
+ "signature": "() => Promise<void>",
49
+ "parameters": [],
50
+ "returns": "Promise<void>",
51
+ "tags": [
52
+ {
53
+ "name": "deprecated",
54
+ "text": "Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()"
55
+ }
56
+ ],
57
+ "docs": "Enable Bluetooth.\nOnly available on **Android**.\n**Deprecated** Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()",
43
58
  "complexTypes": [],
44
59
  "slug": "enable"
45
60
  },
@@ -48,8 +63,13 @@
48
63
  "signature": "() => Promise<void>",
49
64
  "parameters": [],
50
65
  "returns": "Promise<void>",
51
- "tags": [],
52
- "docs": "Disable Bluetooth.\nOnly available on **Android**.",
66
+ "tags": [
67
+ {
68
+ "name": "deprecated",
69
+ "text": "Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()"
70
+ }
71
+ ],
72
+ "docs": "Disable Bluetooth.\nOnly available on **Android**.\n**Deprecated** Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()",
53
73
  "complexTypes": [],
54
74
  "slug": "disable"
55
75
  },
@@ -197,7 +217,7 @@
197
217
  "text": "callback"
198
218
  }
199
219
  ],
200
- "docs": "Start scanning for BLE devices to interact with according to the filters in the options. The callback will be invoked on each device that is found.\nScanning will continue until `stopLEScan` is called. For an example, see [usage](#usage).\n**NOTE**: Use with care on **web** platform, the required API is still behind a flag in most browsers.",
220
+ "docs": "Start scanning for BLE devices to interact with according to the filters in the options. The callback will be invoked on each device that is found.\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.",
201
221
  "complexTypes": [
202
222
  "RequestBleDeviceOptions",
203
223
  "ScanResult"
@@ -12,14 +12,22 @@ export interface BleClientInterface {
12
12
  * Always returns `true` on **web**.
13
13
  */
14
14
  isEnabled(): Promise<boolean>;
15
+ /**
16
+ * 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
17
+ * Only available on **Android**.*/
18
+ requestEnable(): Promise<void>;
15
19
  /**
16
20
  * Enable Bluetooth.
17
21
  * Only available on **Android**.
22
+ * **Deprecated** Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()
23
+ * @deprecated Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()
18
24
  */
19
25
  enable(): Promise<void>;
20
26
  /**
21
27
  * Disable Bluetooth.
22
28
  * Only available on **Android**.
29
+ * **Deprecated** Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()
30
+ * @deprecated Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()
23
31
  */
24
32
  disable(): Promise<void>;
25
33
  /**
@@ -69,7 +77,7 @@ export interface BleClientInterface {
69
77
  /**
70
78
  * 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.
71
79
  * Scanning will continue until `stopLEScan` is called. For an example, see [usage](#usage).
72
- * **NOTE**: Use with care on **web** platform, the required API is still behind a flag in most browsers.
80
+ * **Note**: Use with care on **web** platform, the required API is still behind a flag in most browsers.
73
81
  * @param options
74
82
  * @param callback
75
83
  */
@@ -228,6 +236,7 @@ declare class BleClientClass implements BleClientInterface {
228
236
  */
229
237
  getEnabled(): Promise<boolean>;
230
238
  isEnabled(): Promise<boolean>;
239
+ requestEnable(): Promise<void>;
231
240
  enable(): Promise<void>;
232
241
  disable(): Promise<void>;
233
242
  startEnabledNotifications(callback: (value: boolean) => void): Promise<void>;
@@ -35,6 +35,11 @@ class BleClientClass {
35
35
  });
36
36
  return enabled;
37
37
  }
38
+ async requestEnable() {
39
+ await this.queue(async () => {
40
+ await BluetoothLe.requestEnable();
41
+ });
42
+ }
38
43
  async enable() {
39
44
  await this.queue(async () => {
40
45
  await BluetoothLe.enable();
@@ -1 +1 @@
1
- {"version":3,"file":"bleClient.js","sourceRoot":"","sources":["../../src/bleClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAaxE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAsRzC,MAAM,cAAc;IAApB;QACU,iBAAY,GAAgC,IAAI,CAAC;QACjD,mBAAc,GAAG,IAAI,GAAG,EAAgC,CA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CAAC,QAAQ,EAAE;YACpB,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;SACpD;QACD,IAAI,OAAO,CAAC,gBAAgB,EAAE;YAC5B,OAAO,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;SACpE;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,YAAY,CAAC,KAAY;QAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;SACnC;aAAM,IAAI,KAAK,KAAK,SAAS,EAAE;YAC9B,OAAO,IAAI,QAAQ,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;SACzC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,aAAa,CAAC,GAA6B;QACjD,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,OAAO,SAAS,CAAC;SAClB;QACD,MAAM,MAAM,GAAgC,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAClC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;SAC3C;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,cAAc,EAAE,CAAC","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\nimport { Capacitor } from '@capacitor/core';\n\nimport type { DisplayStrings } from './config';\nimport { dataViewToHexString, hexStringToDataView } from './conversion';\nimport type {\n BleDevice,\n BleService,\n ConnectionPriority,\n Data,\n InitializeOptions,\n ReadResult,\n RequestBleDeviceOptions,\n ScanResult,\n ScanResultInternal,\n TimeoutOptions,\n} from './definitions';\nimport { BluetoothLe } from './plugin';\nimport { getQueue } from './queue';\nimport { parseUUID } from './validators';\n\nexport interface BleClientInterface {\n /**\n * Initialize Bluetooth Low Energy (BLE). If it fails, BLE might be unavailable on this device.\n * On **Android** it will ask for the location permission. On **iOS** it will ask for the Bluetooth permission.\n * For an example, see [usage](#usage).\n */\n initialize(options?: InitializeOptions): Promise<void>;\n\n /**\n * Reports whether Bluetooth is enabled on this device.\n * Always returns `true` on **web**.\n */\n isEnabled(): Promise<boolean>;\n\n /**\n * Enable Bluetooth.\n * Only available on **Android**.\n */\n enable(): Promise<void>;\n\n /**\n * Disable Bluetooth.\n * Only available on **Android**.\n */\n disable(): Promise<void>;\n\n /**\n * Register a callback function that will be invoked when Bluetooth is enabled (true) or disabled (false) on this device.\n * Not available on **web** (the callback will never be invoked).\n * @param callback Callback function to use when the Bluetooth state changes.\n */\n startEnabledNotifications(callback: (value: boolean) => void): Promise<void>;\n\n /**\n * Stop the enabled notifications registered with `startEnabledNotifications`.\n */\n stopEnabledNotifications(): Promise<void>;\n\n /**\n * Reports whether Location Services are enabled on this device.\n * Only available on **Android**.\n */\n isLocationEnabled(): Promise<boolean>;\n\n /**\n * Open Location settings.\n * Only available on **Android**.\n */\n openLocationSettings(): Promise<void>;\n\n /**\n * Open Bluetooth settings.\n * Only available on **Android**.\n */\n openBluetoothSettings(): Promise<void>;\n\n /**\n * Open App settings.\n * Not available on **web**.\n * On **iOS** when a user declines the request to use Bluetooth on the first call of `initialize`, it is not possible\n * to request for Bluetooth again from within the app. In this case Bluetooth has to be enabled in the app settings\n * for the app to be able use it.\n */\n openAppSettings(): Promise<void>;\n\n /**\n * Set the strings that are displayed in the `requestDevice` dialog.\n * @param displayStrings\n */\n setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;\n\n /**\n * Request a peripheral BLE device to interact with. This will scan for available devices according to the filters in the options and show a dialog to pick a device.\n * For an example, see [usage](#usage).\n * @param options Device filters, see [RequestBleDeviceOptions](#RequestBleDeviceOptions)\n */\n requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;\n\n /**\n * Start scanning for BLE devices to interact with according to the filters in the options. The callback will be invoked on each device that is found.\n * Scanning will continue until `stopLEScan` is called. For an example, see [usage](#usage).\n * **NOTE**: Use with care on **web** platform, the required API is still behind a flag in most browsers.\n * @param options\n * @param callback\n */\n requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void>;\n\n /**\n * Stop scanning for BLE devices. For an example, see [usage](#usage).\n */\n stopLEScan(): Promise<void>;\n\n /**\n * On iOS and web, if you want to connect to a previously connected device without scanning first, you can use `getDevice`.\n * Uses [retrievePeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1519127-retrieveperipherals) on iOS and\n * [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.\n * On Android, you can directly connect to the device with the deviceId.\n * @param deviceIds List of device IDs, e.g. saved from a previous app run.\n */\n getDevices(deviceIds: string[]): Promise<BleDevice[]>;\n\n /**\n * Get a list of currently connected devices.\n * Uses [retrieveConnectedPeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals) on iOS,\n * [getConnectedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getConnectedDevices(int)) on Android\n * and [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.\n * @param services List of services to filter the devices by. If no service is specified, no devices will be returned. Only applies to iOS.\n */\n getConnectedDevices(services: string[]): Promise<BleDevice[]>;\n\n /**\n * Connect to a peripheral BLE device. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param onDisconnect Optional disconnect callback function that will be used when the device disconnects\n * @param options Options for plugin call\n */\n connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void>;\n\n /**\n * Create a bond with a peripheral BLE device.\n * Only available on **Android**. On iOS bonding is handled by the OS.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n createBond(deviceId: string): Promise<void>;\n\n /**\n * Report whether a peripheral BLE device is bonded.\n * Only available on **Android**. On iOS bonding is handled by the OS.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n isBonded(deviceId: string): Promise<boolean>;\n\n /**\n * Disconnect from a peripheral BLE device. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n disconnect(deviceId: string): Promise<void>;\n\n /**\n * Get services, characteristics and descriptors of a device.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n getServices(deviceId: string): Promise<BleService[]>;\n\n /**\n * Discover services, characteristics and descriptors of a device.\n * You only need this method if your peripheral device changes its services and characteristics at runtime.\n * If the discovery was successful, the remote services can be retrieved using the getServices function.\n * Not available on **web**.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n discoverServices(deviceId: string): Promise<void>;\n\n /**\n * Get the MTU of a connected device. Note that the maximum write value length is 3 bytes less than the MTU.\n * Not available on **web**.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n getMtu(deviceId: string): Promise<number>;\n\n /**\n * Request a connection parameter update.\n * Only available on **Android**. https://developer.android.com/reference/android/bluetooth/BluetoothGatt#requestConnectionPriority(int)\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param connectionPriority Request a specific connection priority. See [ConnectionPriority](#connectionpriority)\n */\n requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void>;\n\n /**\n * Read the RSSI value of a connected device.\n * Not available on **web**.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n readRssi(deviceId: string): Promise<number>;\n\n /**\n * Read the value of a characteristic. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param options Options for plugin call\n */\n read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView>;\n\n /**\n * Write a value to a characteristic. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])\n * @param options Options for plugin call\n */\n write(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void>;\n\n /**\n * Write a value to a characteristic without waiting for a response.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])\n * @param options Options for plugin call\n */\n writeWithoutResponse(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void>;\n\n /**\n * Read the value of a descriptor.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))\n * @param options Options for plugin call\n */\n readDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n options?: TimeoutOptions\n ): Promise<DataView>;\n\n /**\n * Write a value to a descriptor.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))\n * @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])\n * @param options Options for plugin call\n */\n writeDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void>;\n\n /**\n * Start listening to changes of the value of a characteristic.\n * Note that you should only start the notifications once per characteristic in your app and share the data and\n * not call `startNotifications` in every component that needs the data.\n * For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param callback Callback function to use when the value of the characteristic changes\n */\n startNotifications(\n deviceId: string,\n service: string,\n characteristic: string,\n callback: (value: DataView) => void\n ): Promise<void>;\n\n /**\n * Stop listening to the changes of the value of a characteristic. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n */\n stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void>;\n}\n\nclass BleClientClass implements BleClientInterface {\n private scanListener: PluginListenerHandle | null = null;\n private eventListeners = new Map<string, PluginListenerHandle>();\n private queue = getQueue(true);\n\n enableQueue() {\n this.queue = getQueue(true);\n }\n\n disableQueue() {\n this.queue = getQueue(false);\n }\n\n async initialize(options?: InitializeOptions): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.initialize(options);\n });\n }\n\n /**\n * Reports whether BLE is enabled on this device.\n * Always returns `true` on **web**.\n * @deprecated Use `isEnabled` instead.\n */\n async getEnabled(): Promise<boolean> {\n return this.isEnabled();\n }\n\n async isEnabled(): Promise<boolean> {\n const enabled = await this.queue(async () => {\n const result = await BluetoothLe.isEnabled();\n return result.value;\n });\n return enabled;\n }\n\n async enable(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.enable();\n });\n }\n\n async disable(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.disable();\n });\n }\n\n async startEnabledNotifications(callback: (value: boolean) => void): Promise<void> {\n await this.queue(async () => {\n const key = `onEnabledChanged`;\n await this.eventListeners.get(key)?.remove();\n const listener = await BluetoothLe.addListener(key, (result) => {\n callback(result.value);\n });\n this.eventListeners.set(key, listener);\n await BluetoothLe.startEnabledNotifications();\n });\n }\n\n async stopEnabledNotifications(): Promise<void> {\n await this.queue(async () => {\n const key = `onEnabledChanged`;\n await this.eventListeners.get(key)?.remove();\n this.eventListeners.delete(key);\n await BluetoothLe.stopEnabledNotifications();\n });\n }\n\n async isLocationEnabled(): Promise<boolean> {\n const enabled = await this.queue(async () => {\n const result = await BluetoothLe.isLocationEnabled();\n return result.value;\n });\n return enabled;\n }\n\n async openLocationSettings(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.openLocationSettings();\n });\n }\n\n async openBluetoothSettings(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.openBluetoothSettings();\n });\n }\n\n async openAppSettings(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.openAppSettings();\n });\n }\n\n async setDisplayStrings(displayStrings: DisplayStrings): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.setDisplayStrings(displayStrings);\n });\n }\n\n async requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice> {\n options = options ? this.validateRequestBleDeviceOptions(options) : undefined;\n const result = await this.queue(async () => {\n const device = await BluetoothLe.requestDevice(options);\n return device;\n });\n return result;\n }\n\n async requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void> {\n options = this.validateRequestBleDeviceOptions(options);\n await this.queue(async () => {\n await this.scanListener?.remove();\n this.scanListener = await BluetoothLe.addListener('onScanResult', (resultInternal: ScanResultInternal) => {\n const result: ScanResult = {\n ...resultInternal,\n manufacturerData: this.convertObject(resultInternal.manufacturerData),\n serviceData: this.convertObject(resultInternal.serviceData),\n rawAdvertisement: resultInternal.rawAdvertisement\n ? this.convertValue(resultInternal.rawAdvertisement)\n : undefined,\n };\n callback(result);\n });\n await BluetoothLe.requestLEScan(options);\n });\n }\n\n async stopLEScan(): Promise<void> {\n await this.queue(async () => {\n await this.scanListener?.remove();\n this.scanListener = null;\n await BluetoothLe.stopLEScan();\n });\n }\n\n async getDevices(deviceIds: string[]): Promise<BleDevice[]> {\n return this.queue(async () => {\n const result = await BluetoothLe.getDevices({ deviceIds });\n return result.devices;\n });\n }\n\n async getConnectedDevices(services: string[]): Promise<BleDevice[]> {\n if (!Array.isArray(services)) {\n throw new Error('services must be an array');\n }\n services = services.map(parseUUID);\n return this.queue(async () => {\n const result = await BluetoothLe.getConnectedDevices({ services });\n return result.devices;\n });\n }\n\n async connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void> {\n await this.queue(async () => {\n if (onDisconnect) {\n const key = `disconnected|${deviceId}`;\n await this.eventListeners.get(key)?.remove();\n const listener = await BluetoothLe.addListener(key, () => {\n onDisconnect(deviceId);\n });\n this.eventListeners.set(key, listener);\n }\n await BluetoothLe.connect({ deviceId, ...options });\n });\n }\n\n async createBond(deviceId: string): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.createBond({ deviceId });\n });\n }\n\n async isBonded(deviceId: string): Promise<boolean> {\n const isBonded = await this.queue(async () => {\n const result = await BluetoothLe.isBonded({ deviceId });\n return result.value;\n });\n return isBonded;\n }\n\n async disconnect(deviceId: string): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.disconnect({ deviceId });\n });\n }\n\n async getServices(deviceId: string): Promise<BleService[]> {\n const services = await this.queue(async () => {\n const result = await BluetoothLe.getServices({ deviceId });\n return result.services;\n });\n return services;\n }\n\n async discoverServices(deviceId: string): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.discoverServices({ deviceId });\n });\n }\n\n async getMtu(deviceId: string): Promise<number> {\n const value = await this.queue(async () => {\n const result = await BluetoothLe.getMtu({ deviceId });\n return result.value;\n });\n return value;\n }\n\n async requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.requestConnectionPriority({ deviceId, connectionPriority });\n });\n }\n\n async readRssi(deviceId: string): Promise<number> {\n const value = await this.queue(async () => {\n const result = await BluetoothLe.readRssi({ deviceId });\n return parseFloat(result.value);\n });\n return value;\n }\n\n async read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n const value = await this.queue(async () => {\n const result = await BluetoothLe.read({\n deviceId,\n service,\n characteristic,\n ...options,\n });\n return this.convertValue(result.value);\n });\n return value;\n }\n\n async write(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n return this.queue(async () => {\n if (!value?.buffer) {\n throw new Error('Invalid data.');\n }\n let writeValue: DataView | string = value;\n if (Capacitor.getPlatform() !== 'web') {\n // on native we can only write strings\n writeValue = dataViewToHexString(value);\n }\n await BluetoothLe.write({\n deviceId,\n service,\n characteristic,\n value: writeValue,\n ...options,\n });\n });\n }\n\n async writeWithoutResponse(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n await this.queue(async () => {\n if (!value?.buffer) {\n throw new Error('Invalid data.');\n }\n let writeValue: DataView | string = value;\n if (Capacitor.getPlatform() !== 'web') {\n // on native we can only write strings\n writeValue = dataViewToHexString(value);\n }\n await BluetoothLe.writeWithoutResponse({\n deviceId,\n service,\n characteristic,\n value: writeValue,\n ...options,\n });\n });\n }\n\n async readDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n options?: TimeoutOptions\n ): Promise<DataView> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n descriptor = parseUUID(descriptor);\n const value = await this.queue(async () => {\n const result = await BluetoothLe.readDescriptor({\n deviceId,\n service,\n characteristic,\n descriptor,\n ...options,\n });\n return this.convertValue(result.value);\n });\n return value;\n }\n\n async writeDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n descriptor = parseUUID(descriptor);\n return this.queue(async () => {\n if (!value?.buffer) {\n throw new Error('Invalid data.');\n }\n let writeValue: DataView | string = value;\n if (Capacitor.getPlatform() !== 'web') {\n // on native we can only write strings\n writeValue = dataViewToHexString(value);\n }\n await BluetoothLe.writeDescriptor({\n deviceId,\n service,\n characteristic,\n descriptor,\n value: writeValue,\n ...options,\n });\n });\n }\n\n async startNotifications(\n deviceId: string,\n service: string,\n characteristic: string,\n callback: (value: DataView) => void\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n await this.queue(async () => {\n const key = `notification|${deviceId}|${service}|${characteristic}`;\n await this.eventListeners.get(key)?.remove();\n const listener = await BluetoothLe.addListener(key, (event: ReadResult) => {\n callback(this.convertValue(event?.value));\n });\n this.eventListeners.set(key, listener);\n await BluetoothLe.startNotifications({\n deviceId,\n service,\n characteristic,\n });\n });\n }\n\n async stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n await this.queue(async () => {\n const key = `notification|${deviceId}|${service}|${characteristic}`;\n await this.eventListeners.get(key)?.remove();\n this.eventListeners.delete(key);\n await BluetoothLe.stopNotifications({\n deviceId,\n service,\n characteristic,\n });\n });\n }\n\n private validateRequestBleDeviceOptions(options: RequestBleDeviceOptions): RequestBleDeviceOptions {\n if (options.services) {\n options.services = options.services.map(parseUUID);\n }\n if (options.optionalServices) {\n options.optionalServices = options.optionalServices.map(parseUUID);\n }\n return options;\n }\n\n private convertValue(value?: Data): DataView {\n if (typeof value === 'string') {\n return hexStringToDataView(value);\n } else if (value === undefined) {\n return new DataView(new ArrayBuffer(0));\n }\n return value;\n }\n\n private convertObject(obj?: { [key: string]: Data }): { [key: string]: DataView } | undefined {\n if (obj === undefined) {\n return undefined;\n }\n const result: { [key: string]: DataView } = {};\n for (const key of Object.keys(obj)) {\n result[key] = this.convertValue(obj[key]);\n }\n return result;\n }\n}\n\nexport const BleClient = new BleClientClass();\n"]}
1
+ {"version":3,"file":"bleClient.js","sourceRoot":"","sources":["../../src/bleClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAaxE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AA+RzC,MAAM,cAAc;IAApB;QACU,iBAAY,GAAgC,IAAI,CAAC;QACjD,mBAAc,GAAG,IAAI,GAAG,EAAgC,CAAC;QACzD,UAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAoajC,CAAC;IAlaC,WAAW;QACT,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,YAAY;QACV,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAA2B;QAC1C,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE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,GAAG,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;SACpE;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,YAAY,CAAC,KAAY;QAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;SACnC;aAAM,IAAI,KAAK,KAAK,SAAS,EAAE;YAC9B,OAAO,IAAI,QAAQ,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;SACzC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,aAAa,CAAC,GAA6B;QACjD,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,OAAO,SAAS,CAAC;SAClB;QACD,MAAM,MAAM,GAAgC,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAClC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;SAC3C;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,cAAc,EAAE,CAAC","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\nimport { Capacitor } from '@capacitor/core';\n\nimport type { DisplayStrings } from './config';\nimport { dataViewToHexString, hexStringToDataView } from './conversion';\nimport type {\n BleDevice,\n BleService,\n ConnectionPriority,\n Data,\n InitializeOptions,\n ReadResult,\n RequestBleDeviceOptions,\n ScanResult,\n ScanResultInternal,\n TimeoutOptions,\n} from './definitions';\nimport { BluetoothLe } from './plugin';\nimport { getQueue } from './queue';\nimport { parseUUID } from './validators';\n\nexport interface BleClientInterface {\n /**\n * Initialize Bluetooth Low Energy (BLE). If it fails, BLE might be unavailable on this device.\n * On **Android** it will ask for the location permission. On **iOS** it will ask for the Bluetooth permission.\n * For an example, see [usage](#usage).\n */\n initialize(options?: InitializeOptions): Promise<void>;\n\n /**\n * Reports whether Bluetooth is enabled on this device.\n * Always returns `true` on **web**.\n */\n isEnabled(): Promise<boolean>;\n\n /**\n * Request enabling Bluetooth. Show a system activity that allows the user to turn on Bluetooth. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#ACTION_REQUEST_ENABLE\n * Only available on **Android**.*/\n requestEnable(): Promise<void>;\n\n /**\n * Enable Bluetooth.\n * Only available on **Android**.\n * **Deprecated** Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()\n * @deprecated Will fail on Android SDK >= 33. Use `requestEnable` instead. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#enable()\n */\n enable(): Promise<void>;\n\n /**\n * Disable Bluetooth.\n * Only available on **Android**.\n * **Deprecated** Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()\n * @deprecated Will fail on Android SDK >= 33. See https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()\n */\n disable(): Promise<void>;\n\n /**\n * Register a callback function that will be invoked when Bluetooth is enabled (true) or disabled (false) on this device.\n * Not available on **web** (the callback will never be invoked).\n * @param callback Callback function to use when the Bluetooth state changes.\n */\n startEnabledNotifications(callback: (value: boolean) => void): Promise<void>;\n\n /**\n * Stop the enabled notifications registered with `startEnabledNotifications`.\n */\n stopEnabledNotifications(): Promise<void>;\n\n /**\n * Reports whether Location Services are enabled on this device.\n * Only available on **Android**.\n */\n isLocationEnabled(): Promise<boolean>;\n\n /**\n * Open Location settings.\n * Only available on **Android**.\n */\n openLocationSettings(): Promise<void>;\n\n /**\n * Open Bluetooth settings.\n * Only available on **Android**.\n */\n openBluetoothSettings(): Promise<void>;\n\n /**\n * Open App settings.\n * Not available on **web**.\n * On **iOS** when a user declines the request to use Bluetooth on the first call of `initialize`, it is not possible\n * to request for Bluetooth again from within the app. In this case Bluetooth has to be enabled in the app settings\n * for the app to be able use it.\n */\n openAppSettings(): Promise<void>;\n\n /**\n * Set the strings that are displayed in the `requestDevice` dialog.\n * @param displayStrings\n */\n setDisplayStrings(displayStrings: DisplayStrings): Promise<void>;\n\n /**\n * Request a peripheral BLE device to interact with. This will scan for available devices according to the filters in the options and show a dialog to pick a device.\n * For an example, see [usage](#usage).\n * @param options Device filters, see [RequestBleDeviceOptions](#RequestBleDeviceOptions)\n */\n requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice>;\n\n /**\n * Start scanning for BLE devices to interact with according to the filters in the options. The callback will be invoked on each device that is found.\n * Scanning will continue until `stopLEScan` is called. For an example, see [usage](#usage).\n * **Note**: Use with care on **web** platform, the required API is still behind a flag in most browsers.\n * @param options\n * @param callback\n */\n requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void>;\n\n /**\n * Stop scanning for BLE devices. For an example, see [usage](#usage).\n */\n stopLEScan(): Promise<void>;\n\n /**\n * On iOS and web, if you want to connect to a previously connected device without scanning first, you can use `getDevice`.\n * Uses [retrievePeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1519127-retrieveperipherals) on iOS and\n * [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.\n * On Android, you can directly connect to the device with the deviceId.\n * @param deviceIds List of device IDs, e.g. saved from a previous app run.\n */\n getDevices(deviceIds: string[]): Promise<BleDevice[]>;\n\n /**\n * Get a list of currently connected devices.\n * Uses [retrieveConnectedPeripherals](https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals) on iOS,\n * [getConnectedDevices](https://developer.android.com/reference/android/bluetooth/BluetoothManager#getConnectedDevices(int)) on Android\n * and [getDevices](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices) on web.\n * @param services List of services to filter the devices by. If no service is specified, no devices will be returned. Only applies to iOS.\n */\n getConnectedDevices(services: string[]): Promise<BleDevice[]>;\n\n /**\n * Connect to a peripheral BLE device. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param onDisconnect Optional disconnect callback function that will be used when the device disconnects\n * @param options Options for plugin call\n */\n connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void>;\n\n /**\n * Create a bond with a peripheral BLE device.\n * Only available on **Android**. On iOS bonding is handled by the OS.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n createBond(deviceId: string): Promise<void>;\n\n /**\n * Report whether a peripheral BLE device is bonded.\n * Only available on **Android**. On iOS bonding is handled by the OS.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n isBonded(deviceId: string): Promise<boolean>;\n\n /**\n * Disconnect from a peripheral BLE device. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n disconnect(deviceId: string): Promise<void>;\n\n /**\n * Get services, characteristics and descriptors of a device.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n getServices(deviceId: string): Promise<BleService[]>;\n\n /**\n * Discover services, characteristics and descriptors of a device.\n * You only need this method if your peripheral device changes its services and characteristics at runtime.\n * If the discovery was successful, the remote services can be retrieved using the getServices function.\n * Not available on **web**.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n discoverServices(deviceId: string): Promise<void>;\n\n /**\n * Get the MTU of a connected device. Note that the maximum write value length is 3 bytes less than the MTU.\n * Not available on **web**.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n getMtu(deviceId: string): Promise<number>;\n\n /**\n * Request a connection parameter update.\n * Only available on **Android**. https://developer.android.com/reference/android/bluetooth/BluetoothGatt#requestConnectionPriority(int)\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param connectionPriority Request a specific connection priority. See [ConnectionPriority](#connectionpriority)\n */\n requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void>;\n\n /**\n * Read the RSSI value of a connected device.\n * Not available on **web**.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n */\n readRssi(deviceId: string): Promise<number>;\n\n /**\n * Read the value of a characteristic. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param options Options for plugin call\n */\n read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView>;\n\n /**\n * Write a value to a characteristic. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])\n * @param options Options for plugin call\n */\n write(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void>;\n\n /**\n * Write a value to a characteristic without waiting for a response.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])\n * @param options Options for plugin call\n */\n writeWithoutResponse(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void>;\n\n /**\n * Read the value of a descriptor.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))\n * @param options Options for plugin call\n */\n readDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n options?: TimeoutOptions\n ): Promise<DataView>;\n\n /**\n * Write a value to a descriptor.\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param descriptor UUID of the descriptor (see [UUID format](#uuid-format))\n * @param value The value to write as a DataView. To create a DataView from an array of numbers, there is a helper function, e.g. numbersToDataView([1, 0])\n * @param options Options for plugin call\n */\n writeDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void>;\n\n /**\n * Start listening to changes of the value of a characteristic.\n * Note that you should only start the notifications once per characteristic in your app and share the data and\n * not call `startNotifications` in every component that needs the data.\n * For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n * @param callback Callback function to use when the value of the characteristic changes\n */\n startNotifications(\n deviceId: string,\n service: string,\n characteristic: string,\n callback: (value: DataView) => void\n ): Promise<void>;\n\n /**\n * Stop listening to the changes of the value of a characteristic. For an example, see [usage](#usage).\n * @param deviceId The ID of the device to use (obtained from [requestDevice](#requestDevice) or [requestLEScan](#requestLEScan))\n * @param service UUID of the service (see [UUID format](#uuid-format))\n * @param characteristic UUID of the characteristic (see [UUID format](#uuid-format))\n */\n stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void>;\n}\n\nclass BleClientClass implements BleClientInterface {\n private scanListener: PluginListenerHandle | null = null;\n private eventListeners = new Map<string, PluginListenerHandle>();\n private queue = getQueue(true);\n\n enableQueue() {\n this.queue = getQueue(true);\n }\n\n disableQueue() {\n this.queue = getQueue(false);\n }\n\n async initialize(options?: InitializeOptions): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.initialize(options);\n });\n }\n\n /**\n * Reports whether BLE is enabled on this device.\n * Always returns `true` on **web**.\n * @deprecated Use `isEnabled` instead.\n */\n async getEnabled(): Promise<boolean> {\n return this.isEnabled();\n }\n\n async isEnabled(): Promise<boolean> {\n const enabled = await this.queue(async () => {\n const result = await BluetoothLe.isEnabled();\n return result.value;\n });\n return enabled;\n }\n\n async requestEnable(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.requestEnable();\n });\n }\n\n async enable(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.enable();\n });\n }\n\n async disable(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.disable();\n });\n }\n\n async startEnabledNotifications(callback: (value: boolean) => void): Promise<void> {\n await this.queue(async () => {\n const key = `onEnabledChanged`;\n await this.eventListeners.get(key)?.remove();\n const listener = await BluetoothLe.addListener(key, (result) => {\n callback(result.value);\n });\n this.eventListeners.set(key, listener);\n await BluetoothLe.startEnabledNotifications();\n });\n }\n\n async stopEnabledNotifications(): Promise<void> {\n await this.queue(async () => {\n const key = `onEnabledChanged`;\n await this.eventListeners.get(key)?.remove();\n this.eventListeners.delete(key);\n await BluetoothLe.stopEnabledNotifications();\n });\n }\n\n async isLocationEnabled(): Promise<boolean> {\n const enabled = await this.queue(async () => {\n const result = await BluetoothLe.isLocationEnabled();\n return result.value;\n });\n return enabled;\n }\n\n async openLocationSettings(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.openLocationSettings();\n });\n }\n\n async openBluetoothSettings(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.openBluetoothSettings();\n });\n }\n\n async openAppSettings(): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.openAppSettings();\n });\n }\n\n async setDisplayStrings(displayStrings: DisplayStrings): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.setDisplayStrings(displayStrings);\n });\n }\n\n async requestDevice(options?: RequestBleDeviceOptions): Promise<BleDevice> {\n options = options ? this.validateRequestBleDeviceOptions(options) : undefined;\n const result = await this.queue(async () => {\n const device = await BluetoothLe.requestDevice(options);\n return device;\n });\n return result;\n }\n\n async requestLEScan(options: RequestBleDeviceOptions, callback: (result: ScanResult) => void): Promise<void> {\n options = this.validateRequestBleDeviceOptions(options);\n await this.queue(async () => {\n await this.scanListener?.remove();\n this.scanListener = await BluetoothLe.addListener('onScanResult', (resultInternal: ScanResultInternal) => {\n const result: ScanResult = {\n ...resultInternal,\n manufacturerData: this.convertObject(resultInternal.manufacturerData),\n serviceData: this.convertObject(resultInternal.serviceData),\n rawAdvertisement: resultInternal.rawAdvertisement\n ? this.convertValue(resultInternal.rawAdvertisement)\n : undefined,\n };\n callback(result);\n });\n await BluetoothLe.requestLEScan(options);\n });\n }\n\n async stopLEScan(): Promise<void> {\n await this.queue(async () => {\n await this.scanListener?.remove();\n this.scanListener = null;\n await BluetoothLe.stopLEScan();\n });\n }\n\n async getDevices(deviceIds: string[]): Promise<BleDevice[]> {\n return this.queue(async () => {\n const result = await BluetoothLe.getDevices({ deviceIds });\n return result.devices;\n });\n }\n\n async getConnectedDevices(services: string[]): Promise<BleDevice[]> {\n if (!Array.isArray(services)) {\n throw new Error('services must be an array');\n }\n services = services.map(parseUUID);\n return this.queue(async () => {\n const result = await BluetoothLe.getConnectedDevices({ services });\n return result.devices;\n });\n }\n\n async connect(deviceId: string, onDisconnect?: (deviceId: string) => void, options?: TimeoutOptions): Promise<void> {\n await this.queue(async () => {\n if (onDisconnect) {\n const key = `disconnected|${deviceId}`;\n await this.eventListeners.get(key)?.remove();\n const listener = await BluetoothLe.addListener(key, () => {\n onDisconnect(deviceId);\n });\n this.eventListeners.set(key, listener);\n }\n await BluetoothLe.connect({ deviceId, ...options });\n });\n }\n\n async createBond(deviceId: string): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.createBond({ deviceId });\n });\n }\n\n async isBonded(deviceId: string): Promise<boolean> {\n const isBonded = await this.queue(async () => {\n const result = await BluetoothLe.isBonded({ deviceId });\n return result.value;\n });\n return isBonded;\n }\n\n async disconnect(deviceId: string): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.disconnect({ deviceId });\n });\n }\n\n async getServices(deviceId: string): Promise<BleService[]> {\n const services = await this.queue(async () => {\n const result = await BluetoothLe.getServices({ deviceId });\n return result.services;\n });\n return services;\n }\n\n async discoverServices(deviceId: string): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.discoverServices({ deviceId });\n });\n }\n\n async getMtu(deviceId: string): Promise<number> {\n const value = await this.queue(async () => {\n const result = await BluetoothLe.getMtu({ deviceId });\n return result.value;\n });\n return value;\n }\n\n async requestConnectionPriority(deviceId: string, connectionPriority: ConnectionPriority): Promise<void> {\n await this.queue(async () => {\n await BluetoothLe.requestConnectionPriority({ deviceId, connectionPriority });\n });\n }\n\n async readRssi(deviceId: string): Promise<number> {\n const value = await this.queue(async () => {\n const result = await BluetoothLe.readRssi({ deviceId });\n return parseFloat(result.value);\n });\n return value;\n }\n\n async read(deviceId: string, service: string, characteristic: string, options?: TimeoutOptions): Promise<DataView> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n const value = await this.queue(async () => {\n const result = await BluetoothLe.read({\n deviceId,\n service,\n characteristic,\n ...options,\n });\n return this.convertValue(result.value);\n });\n return value;\n }\n\n async write(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n return this.queue(async () => {\n if (!value?.buffer) {\n throw new Error('Invalid data.');\n }\n let writeValue: DataView | string = value;\n if (Capacitor.getPlatform() !== 'web') {\n // on native we can only write strings\n writeValue = dataViewToHexString(value);\n }\n await BluetoothLe.write({\n deviceId,\n service,\n characteristic,\n value: writeValue,\n ...options,\n });\n });\n }\n\n async writeWithoutResponse(\n deviceId: string,\n service: string,\n characteristic: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n await this.queue(async () => {\n if (!value?.buffer) {\n throw new Error('Invalid data.');\n }\n let writeValue: DataView | string = value;\n if (Capacitor.getPlatform() !== 'web') {\n // on native we can only write strings\n writeValue = dataViewToHexString(value);\n }\n await BluetoothLe.writeWithoutResponse({\n deviceId,\n service,\n characteristic,\n value: writeValue,\n ...options,\n });\n });\n }\n\n async readDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n options?: TimeoutOptions\n ): Promise<DataView> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n descriptor = parseUUID(descriptor);\n const value = await this.queue(async () => {\n const result = await BluetoothLe.readDescriptor({\n deviceId,\n service,\n characteristic,\n descriptor,\n ...options,\n });\n return this.convertValue(result.value);\n });\n return value;\n }\n\n async writeDescriptor(\n deviceId: string,\n service: string,\n characteristic: string,\n descriptor: string,\n value: DataView,\n options?: TimeoutOptions\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n descriptor = parseUUID(descriptor);\n return this.queue(async () => {\n if (!value?.buffer) {\n throw new Error('Invalid data.');\n }\n let writeValue: DataView | string = value;\n if (Capacitor.getPlatform() !== 'web') {\n // on native we can only write strings\n writeValue = dataViewToHexString(value);\n }\n await BluetoothLe.writeDescriptor({\n deviceId,\n service,\n characteristic,\n descriptor,\n value: writeValue,\n ...options,\n });\n });\n }\n\n async startNotifications(\n deviceId: string,\n service: string,\n characteristic: string,\n callback: (value: DataView) => void\n ): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n await this.queue(async () => {\n const key = `notification|${deviceId}|${service}|${characteristic}`;\n await this.eventListeners.get(key)?.remove();\n const listener = await BluetoothLe.addListener(key, (event: ReadResult) => {\n callback(this.convertValue(event?.value));\n });\n this.eventListeners.set(key, listener);\n await BluetoothLe.startNotifications({\n deviceId,\n service,\n characteristic,\n });\n });\n }\n\n async stopNotifications(deviceId: string, service: string, characteristic: string): Promise<void> {\n service = parseUUID(service);\n characteristic = parseUUID(characteristic);\n await this.queue(async () => {\n const key = `notification|${deviceId}|${service}|${characteristic}`;\n await this.eventListeners.get(key)?.remove();\n this.eventListeners.delete(key);\n await BluetoothLe.stopNotifications({\n deviceId,\n service,\n characteristic,\n });\n });\n }\n\n private validateRequestBleDeviceOptions(options: RequestBleDeviceOptions): RequestBleDeviceOptions {\n if (options.services) {\n options.services = options.services.map(parseUUID);\n }\n if (options.optionalServices) {\n options.optionalServices = options.optionalServices.map(parseUUID);\n }\n return options;\n }\n\n private convertValue(value?: Data): DataView {\n if (typeof value === 'string') {\n return hexStringToDataView(value);\n } else if (value === undefined) {\n return new DataView(new ArrayBuffer(0));\n }\n return value;\n }\n\n private convertObject(obj?: { [key: string]: Data }): { [key: string]: DataView } | undefined {\n if (obj === undefined) {\n return undefined;\n }\n const result: { [key: string]: DataView } = {};\n for (const key of Object.keys(obj)) {\n result[key] = this.convertValue(obj[key]);\n }\n return result;\n }\n}\n\nexport const BleClient = new BleClientClass();\n"]}
@@ -254,6 +254,7 @@ export interface ScanResult {
254
254
  export interface BluetoothLePlugin {
255
255
  initialize(options?: InitializeOptions): Promise<void>;
256
256
  isEnabled(): Promise<BooleanResult>;
257
+ requestEnable(): Promise<void>;
257
258
  enable(): Promise<void>;
258
259
  disable(): Promise<void>;
259
260
  startEnabledNotifications(): Promise<void>;
@@ -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 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): 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(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): 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/dist/esm/web.d.ts CHANGED
@@ -8,6 +8,7 @@ export declare class BluetoothLeWeb extends WebPlugin implements BluetoothLePlug
8
8
  private DEFAULT_CONNECTION_TIMEOUT;
9
9
  initialize(): Promise<void>;
10
10
  isEnabled(): Promise<BooleanResult>;
11
+ requestEnable(): Promise<void>;
11
12
  enable(): Promise<void>;
12
13
  disable(): Promise<void>;
13
14
  startEnabledNotifications(): Promise<void>;
package/dist/esm/web.js CHANGED
@@ -25,6 +25,9 @@ export class BluetoothLeWeb extends WebPlugin {
25
25
  // not available on web
26
26
  return { value: true };
27
27
  }
28
+ async requestEnable() {
29
+ throw this.unavailable('requestEnable is not available on web.');
30
+ }
28
31
  async enable() {
29
32
  throw this.unavailable('enable is not available on web.');
30
33
  }