@bits-innovate/react-native-vstarcam 1.0.31 → 1.0.32
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.
|
@@ -59,6 +59,12 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
59
59
|
// Counter for unique internal client IDs
|
|
60
60
|
private static final java.util.concurrent.atomic.AtomicInteger nextClientPtr = new java.util.concurrent.atomic.AtomicInteger(1000);
|
|
61
61
|
|
|
62
|
+
// Static proxy references to prevent GC.
|
|
63
|
+
// If the native SDK holds these, Java must not collect them.
|
|
64
|
+
private static Object stateListenerProxy;
|
|
65
|
+
private static Object commandListenerProxy;
|
|
66
|
+
private static Object releaseListenerProxy;
|
|
67
|
+
|
|
62
68
|
// Helper for conditional debug logging
|
|
63
69
|
private static void logDebug(String message) {
|
|
64
70
|
if (DEBUG_LOGGING) {
|
|
@@ -270,14 +276,14 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
270
276
|
|
|
271
277
|
try {
|
|
272
278
|
// Create dynamic proxy for ClientStateListener
|
|
273
|
-
|
|
279
|
+
stateListenerProxy = Proxy.newProxyInstance(
|
|
274
280
|
stateListenerClass.getClassLoader(),
|
|
275
281
|
new Class<?>[] { stateListenerClass },
|
|
276
282
|
new InvocationHandler() {
|
|
277
283
|
@Override
|
|
278
284
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
|
279
285
|
try {
|
|
280
|
-
Log.d(TAG, "ClientStateListener." + method.getName() + " called
|
|
286
|
+
Log.d(TAG, "ClientStateListener." + method.getName() + " called");
|
|
281
287
|
if (method.getName().equals("stateListener")) {
|
|
282
288
|
// args: long clientPtr, int state
|
|
283
289
|
final long clientPtr = (Long) args[0];
|
|
@@ -297,32 +303,22 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
297
303
|
} catch (Exception e) {
|
|
298
304
|
Log.e(TAG, "Error in stateListener callback", e);
|
|
299
305
|
}
|
|
300
|
-
|
|
301
|
-
// Robust return type handling to prevent JNI signature mismatch crash
|
|
302
|
-
Class<?> returnType = method.getReturnType();
|
|
303
|
-
if (returnType.equals(int.class) || returnType.equals(Integer.class)) {
|
|
304
|
-
return 0;
|
|
305
|
-
} else if (returnType.equals(long.class) || returnType.equals(Long.class)) {
|
|
306
|
-
return 0L;
|
|
307
|
-
} else if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) {
|
|
308
|
-
return true; // Default to true for success indicators
|
|
309
|
-
}
|
|
310
|
-
return null;
|
|
306
|
+
return null; // void stateListener
|
|
311
307
|
}
|
|
312
308
|
}
|
|
313
309
|
);
|
|
314
310
|
|
|
315
311
|
// Create dynamic proxy for ClientCommandListener
|
|
316
|
-
|
|
312
|
+
commandListenerProxy = Proxy.newProxyInstance(
|
|
317
313
|
commandListenerClass.getClassLoader(),
|
|
318
314
|
new Class<?>[] { commandListenerClass },
|
|
319
315
|
new InvocationHandler() {
|
|
320
316
|
@Override
|
|
321
317
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
|
322
318
|
try {
|
|
323
|
-
Log.d(TAG, "ClientCommandListener." + method.getName() + " called
|
|
319
|
+
Log.d(TAG, "ClientCommandListener." + method.getName() + " called");
|
|
324
320
|
if (method.getName().equals("commandListener")) {
|
|
325
|
-
// args: long clientPtr, byte[] data, int length
|
|
321
|
+
// args: long clientPtr, byte[] data, int length
|
|
326
322
|
final long clientPtr = (Long) args[0];
|
|
327
323
|
final byte[] data = (byte[]) args[1];
|
|
328
324
|
final int length = (Integer) args[2];
|
|
@@ -340,23 +336,13 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
340
336
|
} catch (Exception e) {
|
|
341
337
|
Log.e(TAG, "Error in commandListener callback", e);
|
|
342
338
|
}
|
|
343
|
-
|
|
344
|
-
// Robust return type handling to prevent JNI signature mismatch crash
|
|
345
|
-
Class<?> returnType = method.getReturnType();
|
|
346
|
-
if (returnType.equals(int.class) || returnType.equals(Integer.class)) {
|
|
347
|
-
return 0;
|
|
348
|
-
} else if (returnType.equals(long.class) || returnType.equals(Long.class)) {
|
|
349
|
-
return 0L;
|
|
350
|
-
} else if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) {
|
|
351
|
-
return true;
|
|
352
|
-
}
|
|
353
|
-
return null;
|
|
339
|
+
return null; // void commandListener
|
|
354
340
|
}
|
|
355
341
|
}
|
|
356
342
|
);
|
|
357
343
|
|
|
358
344
|
// Create dynamic proxy for ClientReleaseListener
|
|
359
|
-
|
|
345
|
+
releaseListenerProxy = Proxy.newProxyInstance(
|
|
360
346
|
releaseListenerClass.getClassLoader(),
|
|
361
347
|
new Class<?>[] { releaseListenerClass },
|
|
362
348
|
new InvocationHandler() {
|
|
@@ -364,20 +350,14 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
364
350
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
|
365
351
|
try {
|
|
366
352
|
Log.d(TAG, "ClientReleaseListener." + method.getName() + " called");
|
|
353
|
+
if (method.getName().equals("releaseListener")) {
|
|
354
|
+
final long clientPtr = (Long) args[0];
|
|
355
|
+
Log.d(TAG, "Release callback: clientPtr=" + clientPtr);
|
|
356
|
+
}
|
|
367
357
|
} catch (Exception e) {
|
|
368
358
|
Log.e(TAG, "Error in releaseListener callback", e);
|
|
369
359
|
}
|
|
370
|
-
|
|
371
|
-
// Robust return type handling to prevent JNI signature mismatch crash
|
|
372
|
-
Class<?> returnType = method.getReturnType();
|
|
373
|
-
if (returnType.equals(int.class) || returnType.equals(Integer.class)) {
|
|
374
|
-
return 0;
|
|
375
|
-
} else if (returnType.equals(long.class) || returnType.equals(Long.class)) {
|
|
376
|
-
return 0L;
|
|
377
|
-
} else if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) {
|
|
378
|
-
return true;
|
|
379
|
-
}
|
|
380
|
-
return null;
|
|
360
|
+
return null; // void releaseListener
|
|
381
361
|
}
|
|
382
362
|
}
|
|
383
363
|
);
|
|
@@ -385,7 +365,8 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
385
365
|
// Call JNIApi.init(stateListener, commandListener, releaseListener)
|
|
386
366
|
Method initMethod = jniApiClass.getMethod("init",
|
|
387
367
|
stateListenerClass, commandListenerClass, releaseListenerClass);
|
|
388
|
-
|
|
368
|
+
Log.d(TAG, "Calling JNIApi.init with proxies...");
|
|
369
|
+
initMethod.invoke(null, stateListenerProxy, commandListenerProxy, releaseListenerProxy);
|
|
389
370
|
|
|
390
371
|
isP2PInitialized = true;
|
|
391
372
|
Log.d(TAG, "P2P system initialized successfully!");
|
|
@@ -565,8 +546,8 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
565
546
|
Log.d(TAG, "Calling JNIApi.connect(" + clientInfo.sdkClientPtr + ", 15, " + param + ", " + actualConnectType + ")");
|
|
566
547
|
|
|
567
548
|
try {
|
|
568
|
-
connectMethod.invoke(null, clientInfo.sdkClientPtr, 15, param, actualConnectType);
|
|
569
|
-
Log.d(TAG, "JNIApi.connect
|
|
549
|
+
Object result = connectMethod.invoke(null, clientInfo.sdkClientPtr, 15, param, actualConnectType);
|
|
550
|
+
Log.d(TAG, "JNIApi.connect result: " + result);
|
|
570
551
|
} catch (java.lang.reflect.InvocationTargetException ite) {
|
|
571
552
|
Log.e(TAG, "JNIApi.connect threw exception: " + ite.getCause(), ite.getCause());
|
|
572
553
|
throw ite;
|
|
@@ -621,32 +602,35 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
621
602
|
|
|
622
603
|
Log.d(TAG, "Calling JNIApi.login(" + clientInfo.sdkClientPtr + ", " + username + ", ***)");
|
|
623
604
|
|
|
624
|
-
boolean
|
|
605
|
+
boolean loginResult = false;
|
|
625
606
|
try {
|
|
626
|
-
loginMethod.invoke(null, clientInfo.sdkClientPtr, username, password);
|
|
627
|
-
Log.d(TAG, "JNIApi.login
|
|
628
|
-
|
|
607
|
+
Object result = loginMethod.invoke(null, clientInfo.sdkClientPtr, username, password);
|
|
608
|
+
Log.d(TAG, "JNIApi.login result: " + result);
|
|
609
|
+
// result is likely boolean based on signature log
|
|
610
|
+
if (result instanceof Boolean) {
|
|
611
|
+
loginResult = (Boolean) result;
|
|
612
|
+
} else if (result != null) {
|
|
613
|
+
loginResult = true; // Non-null result usually means success for some SDKs
|
|
614
|
+
}
|
|
629
615
|
} catch (java.lang.reflect.InvocationTargetException ite) {
|
|
630
616
|
Throwable cause = ite.getCause();
|
|
631
617
|
Log.e(TAG, "JNIApi.login threw exception: " + cause, cause);
|
|
632
|
-
// Don't rethrow - return false instead to prevent crash
|
|
633
618
|
promise.resolve(false);
|
|
634
619
|
return;
|
|
635
620
|
} catch (Throwable t) {
|
|
636
621
|
Log.e(TAG, "JNIApi.login crashed: " + t.getMessage(), t);
|
|
637
|
-
// Don't rethrow - return false instead to prevent crash
|
|
638
622
|
promise.resolve(false);
|
|
639
623
|
return;
|
|
640
624
|
}
|
|
641
625
|
|
|
642
|
-
if (
|
|
626
|
+
if (loginResult) {
|
|
643
627
|
clientInfo.isLoggedIn = true;
|
|
644
628
|
clientInfo.username = username;
|
|
645
629
|
clientInfo.password = password;
|
|
646
630
|
}
|
|
647
631
|
|
|
648
|
-
Log.d(TAG, "JNIApi.login completed with result: " +
|
|
649
|
-
promise.resolve(
|
|
632
|
+
Log.d(TAG, "JNIApi.login completed with result: " + loginResult);
|
|
633
|
+
promise.resolve(loginResult);
|
|
650
634
|
} catch (Exception e) {
|
|
651
635
|
Log.e(TAG, "clientLogin failed", e);
|
|
652
636
|
promise.reject("LOGIN_ERROR", e.getMessage());
|