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.
package/android/build.gradle
CHANGED
|
@@ -9,7 +9,8 @@ buildscript {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
dependencies {
|
|
12
|
-
classpath "com.android.tools.build:gradle:
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
codegenJavaPackageName = "it.innove"
|
|
131
|
-
}
|
|
128
|
+
react {
|
|
129
|
+
jsRootDir = file("../src/")
|
|
130
|
+
libraryName = "BleManager"
|
|
131
|
+
codegenJavaPackageName = "it.innove"
|
|
132
132
|
}
|
package/android/settings.gradle
CHANGED
|
@@ -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 (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
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
|
|