@capgo/capacitor-bluetooth-low-energy 8.0.1 → 8.0.3
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 +35 -0
- package/android/src/main/java/ee/forgr/plugin/bluetooth_low_energy/BluetoothLowEnergyPlugin.java +19 -4
- package/dist/docs.json +19 -0
- package/dist/esm/definitions.d.ts +11 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/shim.d.ts +8 -0
- package/dist/esm/shim.js +733 -0
- package/dist/esm/shim.js.map +1 -0
- package/dist/esm/web.d.ts +1 -0
- package/dist/esm/web.js +3 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +739 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +739 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/BluetoothLowEnergyPlugin/BluetoothLowEnergy.swift +7 -0
- package/ios/Sources/BluetoothLowEnergyPlugin/BluetoothLowEnergyPlugin.swift +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ A comprehensive, **free**, and **powerful** BLE plugin:
|
|
|
19
19
|
- **Permission handling** - Built-in permission management for Android 12+ and iOS
|
|
20
20
|
- **Modern package management** - Supports both Swift Package Manager (SPM) and CocoaPods
|
|
21
21
|
- **Cross-platform** - Works on iOS, Android, and Web (Chrome Web Bluetooth API)
|
|
22
|
+
- **Capacitor Web Bluetooth shim** - Lets browser-style BLE code keep using `navigator.bluetooth` inside native Capacitor apps with one manual call
|
|
22
23
|
|
|
23
24
|
Perfect for IoT applications, wearables, health devices, smart home, and any BLE-connected peripherals.
|
|
24
25
|
|
|
@@ -77,11 +78,31 @@ await BluetoothLowEnergy.requestPermissions();
|
|
|
77
78
|
|
|
78
79
|
Works in Chrome and Chromium-based browsers using the Web Bluetooth API. Note that Web Bluetooth requires HTTPS and user interaction to scan for devices.
|
|
79
80
|
|
|
81
|
+
## Capacitor Web Bluetooth shim
|
|
82
|
+
|
|
83
|
+
In Capacitor native contexts, call `BluetoothLowEnergy.shimWebBluetooth()` before using `navigator.bluetooth`. That installs a JS shim so app code can keep using the Web Bluetooth API while the calls are forwarded to the native BLE implementation.
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
BluetoothLowEnergy.shimWebBluetooth();
|
|
87
|
+
|
|
88
|
+
const device = await navigator.bluetooth.requestDevice({
|
|
89
|
+
acceptAllDevices: true,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const server = await device.gatt.connect();
|
|
93
|
+
const service = await server.getPrimaryService('180d');
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The shim lives in the plugin JS bundle, auto-initializes the plugin in central mode, and forwards GATT reads, writes, descriptors, and notifications through the Capacitor bridge.
|
|
97
|
+
|
|
98
|
+
Current native limitation: `requestDevice()` resolves the first matching scanned device instead of opening the browser chooser UI. If you need a custom picker or peripheral-mode flows, keep using the direct plugin API.
|
|
99
|
+
|
|
80
100
|
## API
|
|
81
101
|
|
|
82
102
|
<docgen-index>
|
|
83
103
|
|
|
84
104
|
* [`initialize(...)`](#initialize)
|
|
105
|
+
* [`shimWebBluetooth()`](#shimwebbluetooth)
|
|
85
106
|
* [`isAvailable()`](#isavailable)
|
|
86
107
|
* [`isEnabled()`](#isenabled)
|
|
87
108
|
* [`isLocationEnabled()`](#islocationenabled)
|
|
@@ -146,6 +167,20 @@ Must be called before any other method.
|
|
|
146
167
|
--------------------
|
|
147
168
|
|
|
148
169
|
|
|
170
|
+
### shimWebBluetooth()
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
shimWebBluetooth() => void
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Install the Capacitor Web Bluetooth shim on `navigator.bluetooth`.
|
|
177
|
+
Call this manually before using the Web Bluetooth API from a Capacitor native app.
|
|
178
|
+
|
|
179
|
+
**Since:** 1.0.0
|
|
180
|
+
|
|
181
|
+
--------------------
|
|
182
|
+
|
|
183
|
+
|
|
149
184
|
### isAvailable()
|
|
150
185
|
|
|
151
186
|
```typescript
|
package/android/src/main/java/ee/forgr/plugin/bluetooth_low_energy/BluetoothLowEnergyPlugin.java
CHANGED
|
@@ -28,6 +28,7 @@ import android.os.Handler;
|
|
|
28
28
|
import android.os.Looper;
|
|
29
29
|
import android.os.ParcelUuid;
|
|
30
30
|
import android.provider.Settings;
|
|
31
|
+
import android.util.SparseArray;
|
|
31
32
|
import androidx.annotation.RequiresPermission;
|
|
32
33
|
import androidx.core.app.ActivityCompat;
|
|
33
34
|
import com.getcapacitor.JSArray;
|
|
@@ -38,6 +39,7 @@ import com.getcapacitor.PluginMethod;
|
|
|
38
39
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
39
40
|
import com.getcapacitor.annotation.Permission;
|
|
40
41
|
import com.getcapacitor.annotation.PermissionCallback;
|
|
42
|
+
import java.io.ByteArrayOutputStream;
|
|
41
43
|
import java.util.ArrayList;
|
|
42
44
|
import java.util.HashMap;
|
|
43
45
|
import java.util.List;
|
|
@@ -68,7 +70,7 @@ import java.util.UUID;
|
|
|
68
70
|
)
|
|
69
71
|
public class BluetoothLowEnergyPlugin extends Plugin {
|
|
70
72
|
|
|
71
|
-
private final String pluginVersion = "8.0.
|
|
73
|
+
private final String pluginVersion = "8.0.3";
|
|
72
74
|
private BluetoothManager bluetoothManager;
|
|
73
75
|
private BluetoothAdapter bluetoothAdapter;
|
|
74
76
|
private BluetoothLeScanner bluetoothLeScanner;
|
|
@@ -310,9 +312,22 @@ public class BluetoothLowEnergyPlugin extends Plugin {
|
|
|
310
312
|
deviceObj.put("rssi", result.getRssi());
|
|
311
313
|
|
|
312
314
|
if (result.getScanRecord() != null) {
|
|
313
|
-
byte[]
|
|
314
|
-
if (
|
|
315
|
-
|
|
315
|
+
SparseArray<byte[]> manufacturerDataArray = result.getScanRecord().getManufacturerSpecificData();
|
|
316
|
+
if (manufacturerDataArray != null && manufacturerDataArray.size() > 0) {
|
|
317
|
+
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
318
|
+
for (int i = 0; i < manufacturerDataArray.size(); i++) {
|
|
319
|
+
int companyId = manufacturerDataArray.keyAt(i);
|
|
320
|
+
byte[] data = manufacturerDataArray.valueAt(i);
|
|
321
|
+
|
|
322
|
+
// Append company ID in little-endian order followed by payload to match iOS format.
|
|
323
|
+
output.write(companyId & 0xFF);
|
|
324
|
+
output.write((companyId >> 8) & 0xFF);
|
|
325
|
+
if (data != null) {
|
|
326
|
+
output.write(data, 0, data.length);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
deviceObj.put("manufacturerData", bytesToHex(output.toByteArray()));
|
|
316
331
|
}
|
|
317
332
|
|
|
318
333
|
List<ParcelUuid> serviceUuids = result.getScanRecord().getServiceUuids();
|
package/dist/docs.json
CHANGED
|
@@ -49,6 +49,25 @@
|
|
|
49
49
|
],
|
|
50
50
|
"slug": "initialize"
|
|
51
51
|
},
|
|
52
|
+
{
|
|
53
|
+
"name": "shimWebBluetooth",
|
|
54
|
+
"signature": "() => void",
|
|
55
|
+
"parameters": [],
|
|
56
|
+
"returns": "void",
|
|
57
|
+
"tags": [
|
|
58
|
+
{
|
|
59
|
+
"name": "since",
|
|
60
|
+
"text": "1.0.0"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "example",
|
|
64
|
+
"text": "```typescript\nBluetoothLowEnergy.shimWebBluetooth();\n```"
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
"docs": "Install the Capacitor Web Bluetooth shim on `navigator.bluetooth`.\nCall this manually before using the Web Bluetooth API from a Capacitor native app.",
|
|
68
|
+
"complexTypes": [],
|
|
69
|
+
"slug": "shimwebbluetooth"
|
|
70
|
+
},
|
|
52
71
|
{
|
|
53
72
|
"name": "isAvailable",
|
|
54
73
|
"signature": "() => Promise<IsAvailableResult>",
|
|
@@ -19,6 +19,17 @@ export interface BluetoothLowEnergyPlugin {
|
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
initialize(options?: InitializeOptions): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Install the Capacitor Web Bluetooth shim on `navigator.bluetooth`.
|
|
24
|
+
* Call this manually before using the Web Bluetooth API from a Capacitor native app.
|
|
25
|
+
*
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* BluetoothLowEnergy.shimWebBluetooth();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
shimWebBluetooth(): void;
|
|
22
33
|
/**
|
|
23
34
|
* Check if Bluetooth is available on the device.
|
|
24
35
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA84CA;;;;GAIG;AACH,MAAM,OAAO,uBAAuB;IAClC;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,iBAAiB,CAAC,KAAe;QACtC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,iBAAiB,CAAC,GAAW;QAClC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACvC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,oBAAoB,CAAC,GAAW;QACrC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,oBAAoB,CAAC,KAAe;QACzC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;CACF"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
import { installBluetoothLowEnergyShim } from './shim';
|
|
2
3
|
const BluetoothLowEnergy = registerPlugin('BluetoothLowEnergy', {
|
|
3
|
-
web: () => import('./web').then((
|
|
4
|
+
web: () => import('./web').then((module) => new module.BluetoothLowEnergyWeb()),
|
|
4
5
|
});
|
|
6
|
+
BluetoothLowEnergy.shimWebBluetooth = () => {
|
|
7
|
+
installBluetoothLowEnergyShim(BluetoothLowEnergy);
|
|
8
|
+
};
|
|
5
9
|
export * from './definitions';
|
|
6
10
|
export { BluetoothLowEnergy };
|
|
7
11
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,EAAE,6BAA6B,EAAE,MAAM,QAAQ,CAAC;AAEvD,MAAM,kBAAkB,GAAG,cAAc,CAA2B,oBAAoB,EAAE;IACxF,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,qBAAqB,EAAE,CAAC;CAChF,CAAC,CAAC;AAEH,kBAAkB,CAAC,gBAAgB,GAAG,GAAG,EAAE;IACzC,6BAA6B,CAAC,kBAAkB,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BluetoothLowEnergyPlugin } from './definitions';
|
|
2
|
+
interface InstallBluetoothLowEnergyShimOptions {
|
|
3
|
+
root?: typeof globalThis;
|
|
4
|
+
isNativePlatform?: boolean;
|
|
5
|
+
isPluginAvailable?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function installBluetoothLowEnergyShim(plugin: BluetoothLowEnergyPlugin, options?: InstallBluetoothLowEnergyShimOptions): void;
|
|
8
|
+
export {};
|