react-native-ble-manager 12.0.0-rc.3 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # react-native-ble-manager
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/react-native-ble-manager.svg?style=flat)](https://www.npmjs.com/package/react-native-ble-manager)
4
- [![npm downloads](https://img.shields.io/npm/dm/react-native-ble-manager.svg?style=flat)](https://www.npmjs.com/package/react-native-ble-manager)
5
- [![GitHub issues](https://img.shields.io/github/issues/innoveit/react-native-ble-manager.svg?style=flat)](https://github.com/innoveit/react-native-ble-manager/issues)
3
+ ![GitHub Release](https://img.shields.io/github/v/release/innoveit/react-native-ble-manager?style=for-the-badge)
4
+ [![npm version](https://img.shields.io/npm/v/react-native-ble-manager.svg?style=for-the-badge)](https://www.npmjs.com/package/react-native-ble-manager)
5
+ [![npm downloads](https://img.shields.io/npm/dm/react-native-ble-manager.svg?style=for-the-badge)](https://www.npmjs.com/package/react-native-ble-manager)
6
+ [![GitHub issues](https://img.shields.io/github/issues/innoveit/react-native-ble-manager.svg?style=for-the-badge)](https://github.com/innoveit/react-native-ble-manager/issues)
6
7
 
7
8
  A React Native Bluetooth Low Energy library.
8
9
 
@@ -76,7 +76,6 @@ public class Peripheral extends BluetoothGattCallback {
76
76
 
77
77
  private final Queue<Runnable> commandQueue = new ConcurrentLinkedQueue<>();
78
78
  private final Handler mainHandler = new Handler(Looper.getMainLooper());
79
- private Runnable discoverServicesRunnable;
80
79
  private boolean commandQueueBusy = false;
81
80
 
82
81
  private List<byte[]> writeQueue = new ArrayList<>();
@@ -324,21 +323,6 @@ public class Peripheral extends BluetoothGattCallback {
324
323
  if (newState == BluetoothProfile.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) {
325
324
  connected = true;
326
325
 
327
- discoverServicesRunnable = new Runnable() {
328
- @Override
329
- public void run() {
330
- try {
331
- gatt.discoverServices();
332
- } catch (NullPointerException e) {
333
- Log.d(BleManager.LOG_TAG,
334
- "onConnectionStateChange connected but gatt of Run method was null");
335
- }
336
- discoverServicesRunnable = null;
337
- }
338
- };
339
-
340
- mainHandler.post(discoverServicesRunnable);
341
-
342
326
  sendConnectionEvent(device, status);
343
327
 
344
328
  Log.d(BleManager.LOG_TAG, "Connected to: " + device.getAddress());
@@ -349,11 +333,6 @@ public class Peripheral extends BluetoothGattCallback {
349
333
 
350
334
  } else if (newState == BluetoothProfile.STATE_DISCONNECTED || status != BluetoothGatt.GATT_SUCCESS) {
351
335
 
352
- if (discoverServicesRunnable != null) {
353
- mainHandler.removeCallbacks(discoverServicesRunnable);
354
- discoverServicesRunnable = null;
355
- }
356
-
357
336
  for (Callback writeCallback : writeCallbacks) {
358
337
  writeCallback.invoke("Device disconnected");
359
338
  }
@@ -404,8 +383,6 @@ public class Peripheral extends BluetoothGattCallback {
404
383
  commandQueueBusy = false;
405
384
  connected = false;
406
385
  clearBuffers();
407
- commandQueue.clear();
408
- commandQueueBusy = false;
409
386
 
410
387
  gatt.disconnect();
411
388
  gatt.close();
package/app.plugin.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./plugin/build/withBLE')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-manager",
3
- "version": "12.0.0-rc.3",
3
+ "version": "12.0.0",
4
4
  "description": "A BLE module for react native.",
5
5
  "homepage": "https://innoveit.github.io/react-native-ble-manager/",
6
6
  "repository": {
@@ -34,6 +34,8 @@
34
34
  "/ios",
35
35
  "*.podspec",
36
36
  "react-native.config.json",
37
+ "app.plugin.js",
38
+ "plugin/build",
37
39
  "!ios/build",
38
40
  "!android/build",
39
41
  "!android/gradle",
@@ -49,11 +51,13 @@
49
51
  "version": "git add -A",
50
52
  "clean": "rimraf dist",
51
53
  "type:check": "tsc -p tsconfig.json --noEmit",
54
+ "build:plugin": "tsc --build plugin",
55
+ "clean:plugin": "expo-module clean plugin",
52
56
  "prepare": "npm run build",
53
- "prebuild": "npm run clean",
57
+ "prebuild": "npm run clean && npm run clean:plugin",
54
58
  "build:cjs": "tsc --module commonjs --outDir dist/cjs",
55
59
  "build:esm": "tsc --outDir dist/esm",
56
- "build": "npm run build:esm && npm run build:cjs",
60
+ "build": "npm run build:esm && npm run build:cjs && npm run build:plugin",
57
61
  "watch": "npm run build --watch",
58
62
  "preversion": "npm run build",
59
63
  "postversion": "git push --follow-tags"
@@ -82,7 +86,9 @@
82
86
  "react-native": "0.76.2",
83
87
  "@react-native/gradle-plugin": "^0.76.2",
84
88
  "turbo": "^2.3.0",
85
- "typescript": "^5.6.3"
89
+ "typescript": "^5.6.3",
90
+ "@expo/config-plugins": "^9.0.10",
91
+ "expo-module-scripts": "^4.0.2"
86
92
  },
87
93
  "eslintConfig": {
88
94
  "root": true,
@@ -0,0 +1,10 @@
1
+ import { ConfigPlugin } from 'expo/config-plugins';
2
+ /**
3
+ * Apply BLE native configuration.
4
+ */
5
+ declare const withBLE: ConfigPlugin<{
6
+ neverForLocation?: boolean;
7
+ bluetoothAlwaysPermission?: string | false;
8
+ companionDeviceEnabled?: boolean;
9
+ } | void>;
10
+ export default withBLE;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_plugins_1 = require("expo/config-plugins");
4
+ const withBLEAndroidManifest_1 = require("./withBLEAndroidManifest");
5
+ const withBluetoothPermissions_1 = require("./withBluetoothPermissions");
6
+ /**
7
+ * Apply BLE native configuration.
8
+ */
9
+ const withBLE = (config, props = {}) => {
10
+ const _props = props || {};
11
+ const isBackgroundEnabled = false;
12
+ const neverForLocation = _props.neverForLocation ?? false;
13
+ const companionDeviceEnabled = _props.companionDeviceEnabled ?? false;
14
+ // iOS
15
+ config = (0, withBluetoothPermissions_1.withBluetoothPermissions)(config, _props);
16
+ // Android
17
+ config = config_plugins_1.AndroidConfig.Permissions.withPermissions(config, [
18
+ 'android.permission.BLUETOOTH',
19
+ 'android.permission.BLUETOOTH_ADMIN',
20
+ 'android.permission.BLUETOOTH_CONNECT', // since Android SDK 31
21
+ ]);
22
+ config = (0, withBLEAndroidManifest_1.withBLEAndroidManifest)(config, {
23
+ isBackgroundEnabled,
24
+ neverForLocation,
25
+ companionDeviceEnabled,
26
+ });
27
+ return config;
28
+ };
29
+ exports.default = withBLE;
@@ -0,0 +1,38 @@
1
+ import { ConfigPlugin, AndroidConfig } from 'expo/config-plugins';
2
+ type InnerManifest = AndroidConfig.Manifest.AndroidManifest['manifest'];
3
+ type ManifestPermission = InnerManifest['permission'];
4
+ type ExtraTools = {
5
+ 'tools:targetApi'?: string;
6
+ };
7
+ type ManifestUsesPermissionWithExtraTools = {
8
+ $: AndroidConfig.Manifest.ManifestUsesPermission['$'] & ExtraTools;
9
+ };
10
+ type AndroidManifest = {
11
+ manifest: InnerManifest & {
12
+ permission?: ManifestPermission;
13
+ 'uses-permission'?: ManifestUsesPermissionWithExtraTools[];
14
+ 'uses-permission-sdk-23'?: ManifestUsesPermissionWithExtraTools[];
15
+ 'uses-feature'?: InnerManifest['uses-feature'];
16
+ };
17
+ };
18
+ export declare const withBLEAndroidManifest: ConfigPlugin<{
19
+ isBackgroundEnabled: boolean;
20
+ neverForLocation: boolean;
21
+ companionDeviceEnabled: boolean;
22
+ }>;
23
+ /**
24
+ * Add location permissions
25
+ * - 'android.permission.ACCESS_COARSE_LOCATION' for Android SDK 28 (Android 9) and lower
26
+ * - 'android.permission.ACCESS_FINE_LOCATION' for Android SDK 29 (Android 10) and higher.
27
+ * From Android SDK 31 (Android 12) it might not be required if BLE is not used for location.
28
+ */
29
+ export declare function addLocationPermissionToManifest(androidManifest: AndroidManifest, neverForLocationSinceSdk31: boolean): AndroidManifest;
30
+ /**
31
+ * Add 'android.permission.BLUETOOTH_SCAN'.
32
+ * Required since Android SDK 31 (Android 12).
33
+ */
34
+ export declare function addScanPermissionToManifest(androidManifest: AndroidManifest, neverForLocation: boolean): AndroidManifest;
35
+ export declare function addConnectPermissionToManifest(androidManifest: AndroidManifest, neverForLocation: boolean): AndroidManifest;
36
+ export declare function addCompanionPermissionToManifest(androidManifest: AndroidManifest): AndroidManifest;
37
+ export declare function addBLEHardwareFeatureToManifest(androidManifest: AndroidConfig.Manifest.AndroidManifest): AndroidConfig.Manifest.AndroidManifest;
38
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withBLEAndroidManifest = void 0;
4
+ exports.addLocationPermissionToManifest = addLocationPermissionToManifest;
5
+ exports.addScanPermissionToManifest = addScanPermissionToManifest;
6
+ exports.addConnectPermissionToManifest = addConnectPermissionToManifest;
7
+ exports.addCompanionPermissionToManifest = addCompanionPermissionToManifest;
8
+ exports.addBLEHardwareFeatureToManifest = addBLEHardwareFeatureToManifest;
9
+ const config_plugins_1 = require("expo/config-plugins");
10
+ const withBLEAndroidManifest = (config, { isBackgroundEnabled, neverForLocation, companionDeviceEnabled }) => {
11
+ return (0, config_plugins_1.withAndroidManifest)(config, config => {
12
+ config.modResults = addLocationPermissionToManifest(config.modResults, neverForLocation);
13
+ config.modResults = addScanPermissionToManifest(config.modResults, neverForLocation);
14
+ config.modResults = addConnectPermissionToManifest(config.modResults, neverForLocation);
15
+ if (companionDeviceEnabled) {
16
+ config.modResults = addCompanionPermissionToManifest(config.modResults);
17
+ }
18
+ if (isBackgroundEnabled) {
19
+ config.modResults = addBLEHardwareFeatureToManifest(config.modResults);
20
+ }
21
+ return config;
22
+ });
23
+ };
24
+ exports.withBLEAndroidManifest = withBLEAndroidManifest;
25
+ /**
26
+ * Add location permissions
27
+ * - 'android.permission.ACCESS_COARSE_LOCATION' for Android SDK 28 (Android 9) and lower
28
+ * - 'android.permission.ACCESS_FINE_LOCATION' for Android SDK 29 (Android 10) and higher.
29
+ * From Android SDK 31 (Android 12) it might not be required if BLE is not used for location.
30
+ */
31
+ function addLocationPermissionToManifest(androidManifest, neverForLocationSinceSdk31) {
32
+ if (!Array.isArray(androidManifest.manifest['uses-permission-sdk-23'])) {
33
+ androidManifest.manifest['uses-permission-sdk-23'] = [];
34
+ }
35
+ const optMaxSdkVersion = neverForLocationSinceSdk31
36
+ ? {
37
+ 'android:maxSdkVersion': '30',
38
+ }
39
+ : {};
40
+ if (!androidManifest.manifest['uses-permission-sdk-23'].find(item => item.$['android:name'] === 'android.permission.ACCESS_COARSE_LOCATION')) {
41
+ androidManifest.manifest['uses-permission-sdk-23'].push({
42
+ $: {
43
+ 'android:name': 'android.permission.ACCESS_COARSE_LOCATION',
44
+ ...optMaxSdkVersion,
45
+ },
46
+ });
47
+ }
48
+ if (!androidManifest.manifest['uses-permission-sdk-23'].find(item => item.$['android:name'] === 'android.permission.ACCESS_FINE_LOCATION')) {
49
+ androidManifest.manifest['uses-permission-sdk-23'].push({
50
+ $: {
51
+ 'android:name': 'android.permission.ACCESS_FINE_LOCATION',
52
+ ...optMaxSdkVersion,
53
+ },
54
+ });
55
+ }
56
+ return androidManifest;
57
+ }
58
+ /**
59
+ * Add 'android.permission.BLUETOOTH_SCAN'.
60
+ * Required since Android SDK 31 (Android 12).
61
+ */
62
+ function addScanPermissionToManifest(androidManifest, neverForLocation) {
63
+ if (!Array.isArray(androidManifest.manifest['uses-permission'])) {
64
+ androidManifest.manifest['uses-permission'] = [];
65
+ }
66
+ if (!androidManifest.manifest['uses-permission'].find(item => item.$['android:name'] === 'android.permission.BLUETOOTH_SCAN')) {
67
+ config_plugins_1.AndroidConfig.Manifest.ensureToolsAvailable(androidManifest);
68
+ androidManifest.manifest['uses-permission']?.push({
69
+ $: {
70
+ 'android:name': 'android.permission.BLUETOOTH_SCAN',
71
+ ...(neverForLocation
72
+ ? {
73
+ 'android:usesPermissionFlags': 'neverForLocation',
74
+ }
75
+ : {}),
76
+ 'tools:targetApi': '31',
77
+ },
78
+ });
79
+ }
80
+ return androidManifest;
81
+ }
82
+ function addConnectPermissionToManifest(androidManifest, neverForLocation) {
83
+ if (!Array.isArray(androidManifest.manifest['uses-permission'])) {
84
+ androidManifest.manifest['uses-permission'] = [];
85
+ }
86
+ if (!androidManifest.manifest['uses-permission'].find(item => item.$['android:name'] === 'android.permission.BLUETOOTH_CONNECT')) {
87
+ config_plugins_1.AndroidConfig.Manifest.ensureToolsAvailable(androidManifest);
88
+ androidManifest.manifest['uses-permission']?.push({
89
+ $: {
90
+ 'android:name': 'android.permission.BLUETOOTH_CONNECT',
91
+ },
92
+ });
93
+ }
94
+ return androidManifest;
95
+ }
96
+ function addCompanionPermissionToManifest(androidManifest) {
97
+ if (!Array.isArray(androidManifest.manifest['uses-feature'])) {
98
+ androidManifest.manifest['uses-feature'] = [];
99
+ }
100
+ if (!androidManifest.manifest['uses-feature'].find(item => item.$['android:name'] === 'android.software.companion_device_setup')) {
101
+ androidManifest.manifest['uses-feature']?.push({
102
+ $: {
103
+ 'android:name': 'android.software.companion_device_setup',
104
+ 'android:required': 'true',
105
+ },
106
+ });
107
+ }
108
+ return androidManifest;
109
+ }
110
+ // Add this line if your application always requires BLE. More info can be found on: https://developer.android.com/guide/topics/connectivity/bluetooth-le.html#permissions
111
+ function addBLEHardwareFeatureToManifest(androidManifest) {
112
+ // Add `<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>` to the AndroidManifest.xml
113
+ if (!Array.isArray(androidManifest.manifest['uses-feature'])) {
114
+ androidManifest.manifest['uses-feature'] = [];
115
+ }
116
+ if (!androidManifest.manifest['uses-feature'].find(item => item.$['android:name'] === 'android.hardware.bluetooth_le')) {
117
+ androidManifest.manifest['uses-feature']?.push({
118
+ $: {
119
+ 'android:name': 'android.hardware.bluetooth_le',
120
+ 'android:required': 'true',
121
+ },
122
+ });
123
+ }
124
+ return androidManifest;
125
+ }
@@ -0,0 +1,4 @@
1
+ import { ConfigPlugin } from 'expo/config-plugins';
2
+ export declare const withBluetoothPermissions: ConfigPlugin<{
3
+ bluetoothAlwaysPermission?: string | false;
4
+ }>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withBluetoothPermissions = void 0;
4
+ const config_plugins_1 = require("expo/config-plugins");
5
+ const BLUETOOTH_ALWAYS = 'Allow $(PRODUCT_NAME) to connect to bluetooth devices';
6
+ const withBluetoothPermissions = (c, { bluetoothAlwaysPermission } = {}) => {
7
+ return (0, config_plugins_1.withInfoPlist)(c, config => {
8
+ if (bluetoothAlwaysPermission !== false) {
9
+ config.modResults.NSBluetoothAlwaysUsageDescription =
10
+ bluetoothAlwaysPermission ||
11
+ config.modResults.NSBluetoothAlwaysUsageDescription ||
12
+ BLUETOOTH_ALWAYS;
13
+ }
14
+ return config;
15
+ });
16
+ };
17
+ exports.withBluetoothPermissions = withBluetoothPermissions;