react-native-ble-manager 12.5.0 → 12.5.2

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.
@@ -9,7 +9,8 @@ buildscript {
9
9
  }
10
10
 
11
11
  dependencies {
12
- classpath "com.android.tools.build:gradle:7.2.1"
12
+ classpath "com.android.tools.build:gradle:8.6.1"
13
+ classpath "com.facebook.react:react-native-gradle-plugin"
13
14
  // noinspection DifferentKotlinGradleVersion
14
15
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
15
16
  }
@@ -27,12 +28,16 @@ def isNewArchitectureEnabled() {
27
28
  }
28
29
 
29
30
  apply plugin: 'com.android.library'
30
- apply plugin: "kotlin-android"
31
-
32
- if (isNewArchitectureEnabled()) {
33
- apply plugin: 'com.facebook.react'
31
+ // AGP 9 ships built-in Kotlin support and registers the `kotlin` extension
32
+ // itself. Applying the Kotlin plugin on top of it fails configuration with
33
+ // "Cannot add extension with name 'kotlin'". Only apply it when nothing has
34
+ // registered that extension yet.
35
+ if (project.extensions.findByName('kotlin') == null) {
36
+ apply plugin: "kotlin-android"
34
37
  }
35
38
 
39
+ apply plugin: 'com.facebook.react'
40
+
36
41
  def safeExtGet(prop, fallback) {
37
42
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
38
43
  }
@@ -116,17 +121,12 @@ repositories {
116
121
  def kotlin_version = getExtOrDefault("kotlinVersion")
117
122
 
118
123
  dependencies {
119
- // For < 0.71, this will be from the local maven repo
120
- // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
121
- //noinspection GradleDynamicVersion
122
- implementation "com.facebook.react:react-native:+"
124
+ implementation "com.facebook.react:react-android:0.81.5"
123
125
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
124
126
  }
125
127
 
126
- if (isNewArchitectureEnabled()) {
127
- react {
128
- jsRootDir = file("../src/")
129
- libraryName = "BleManager"
130
- codegenJavaPackageName = "it.innove"
131
- }
128
+ react {
129
+ jsRootDir = file("../src/")
130
+ libraryName = "BleManager"
131
+ codegenJavaPackageName = "it.innove"
132
132
  }
@@ -1,5 +1,5 @@
1
- kotlinVersion=1.7.0
1
+ kotlinVersion=1.9.24
2
2
  android.useAndroidX=true
3
3
  android.enableJetifier=true
4
4
  # https://github.com/facebook/react-native/issues/35168
5
- org.gradle.jvmargs=-Xmx4096M
5
+ org.gradle.jvmargs=-Xmx4096M
@@ -1,2 +1,3 @@
1
1
  rootProject.name = 'react-native-ble-manager'
2
2
 
3
+ includeBuild('../node_modules/@react-native/gradle-plugin')
@@ -119,10 +119,25 @@ public class Peripheral extends BluetoothGattCallback {
119
119
 
120
120
  public void connect(final Callback callback, Activity activity, ReadableMap options) {
121
121
  mainHandler.post(() -> {
122
- if (!connected) {
123
- BluetoothDevice device = getDevice();
124
- this.connectCallbacks.addLast(callback);
125
- this.connecting = true;
122
+ if (connected) {
123
+ if (gatt != null) {
124
+ callback.invoke();
125
+ } else {
126
+ callback.invoke("BluetoothGatt is null");
127
+ }
128
+ return;
129
+ }
130
+
131
+ this.connectCallbacks.addLast(callback);
132
+
133
+ if (connecting) {
134
+ return;
135
+ }
136
+
137
+ BluetoothDevice device = getDevice();
138
+ this.connecting = true;
139
+
140
+ try {
126
141
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
127
142
  Log.d(BleManager.LOG_TAG, " Is Or Greater than M $mBluetoothDevice");
128
143
  boolean autoconnect = false;
@@ -150,12 +165,19 @@ public class Peripheral extends BluetoothGattCallback {
150
165
  gatt = device.connectGatt(activity, false, this);
151
166
  }
152
167
  }
153
- } else {
154
- if (gatt != null) {
155
- callback.invoke();
156
- } else {
157
- callback.invoke("BluetoothGatt is null");
168
+
169
+ // connectGatt() may return null if the adapter is not ready
170
+ if (gatt == null) {
171
+ throw new IllegalStateException("connectGatt returned null");
172
+ }
173
+ } catch (Exception e) {
174
+ Log.e(BleManager.LOG_TAG, "[ON CONNECT][NATIVE] connectGatt failed for " + device.getAddress(), e);
175
+ this.connecting = false;
176
+ this.gatt = null;
177
+ for (Callback connectCallback : connectCallbacks) {
178
+ connectCallback.invoke("Connection failed to start: " + e.getMessage());
158
179
  }
180
+ connectCallbacks.clear();
159
181
  }
160
182
  });
161
183
  }
@@ -163,6 +185,7 @@ public class Peripheral extends BluetoothGattCallback {
163
185
 
164
186
  public void disconnect(final Callback callback, final boolean force) {
165
187
  connected = false;
188
+ connecting = false;
166
189
  mainHandler.post(() -> {
167
190
  errorAndClearAllCallbacks("Disconnect called before the command completed");
168
191
  resetQueuesAndBuffers();
@@ -384,6 +407,7 @@ public class Peripheral extends BluetoothGattCallback {
384
407
  commandQueue.clear();
385
408
  commandQueueBusy = false;
386
409
  connected = false;
410
+ connecting = false;
387
411
  clearBuffers();
388
412
  }
389
413
 
@@ -1100,33 +1124,33 @@ public class Peripheral extends BluetoothGattCallback {
1100
1124
  }
1101
1125
  return enqueue(() -> {
1102
1126
  try {
1103
- if (!isConnected() || gatt == null) {
1104
- if (withResponse && callback != null) {
1105
- if (writeCallbacks.removeLastOccurrence(callback)) {
1106
- try {
1107
- callback.invoke("Device is not connected", null);
1108
- } catch (Exception callbackException) {
1109
- Log.e(BleManager.LOG_TAG, "Error invoking write callback for disconnected device", callbackException);
1110
- }
1111
- }
1112
- }
1113
- completedCommand();
1114
- return;
1115
- }
1116
- doWrite(characteristic, copyOfData);
1117
- } catch (Exception e) {
1118
- Log.e(BleManager.LOG_TAG, "Error in enqueueWrite lambda", e);
1119
- if (withResponse && callback != null) {
1120
- if (writeCallbacks.removeLastOccurrence(callback)) {
1121
- try {
1122
- callback.invoke("Write failed: " + e.getMessage(), null);
1123
- } catch (Exception callbackException) {
1124
- Log.e(BleManager.LOG_TAG, "Error invoking write callback", callbackException);
1125
- }
1126
- }
1127
- }
1128
- completedCommand();
1129
- }
1127
+ if (!isConnected() || gatt == null) {
1128
+ if (withResponse && callback != null) {
1129
+ if (writeCallbacks.removeLastOccurrence(callback)) {
1130
+ try {
1131
+ callback.invoke("Device is not connected", null);
1132
+ } catch (Exception callbackException) {
1133
+ Log.e(BleManager.LOG_TAG, "Error invoking write callback for disconnected device", callbackException);
1134
+ }
1135
+ }
1136
+ }
1137
+ completedCommand();
1138
+ return;
1139
+ }
1140
+ doWrite(characteristic, copyOfData);
1141
+ } catch (Exception e) {
1142
+ Log.e(BleManager.LOG_TAG, "Error in enqueueWrite lambda", e);
1143
+ if (withResponse && callback != null) {
1144
+ if (writeCallbacks.removeLastOccurrence(callback)) {
1145
+ try {
1146
+ callback.invoke("Write failed: " + e.getMessage(), null);
1147
+ } catch (Exception callbackException) {
1148
+ Log.e(BleManager.LOG_TAG, "Error invoking write callback", callbackException);
1149
+ }
1150
+ }
1151
+ }
1152
+ completedCommand();
1153
+ }
1130
1154
  });
1131
1155
  }
1132
1156
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-manager",
3
- "version": "12.5.0",
3
+ "version": "12.5.2",
4
4
  "description": "A BLE module for react native.",
5
5
  "homepage": "https://innoveit.github.io/react-native-ble-manager/",
6
6
  "repository": {