@bits-innovate/react-native-vstarcam 1.0.51 → 1.0.53

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.
@@ -11,6 +11,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
11
11
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
12
12
  import com.facebook.react.bridge.ReactMethod;
13
13
  import com.facebook.react.bridge.WritableMap;
14
+ import com.facebook.react.bridge.LifecycleEventListener;
14
15
  import com.facebook.react.module.annotations.ReactModule;
15
16
  import com.facebook.react.modules.core.DeviceEventManagerModule;
16
17
 
@@ -46,7 +47,7 @@ import org.json.JSONObject;
46
47
  * - init(ClientStateListener, ClientCommandListener, ClientReleaseListener)
47
48
  */
48
49
  @ReactModule(name = VStarCamModule.MODULE_NAME)
49
- public class VStarCamModule extends ReactContextBaseJavaModule {
50
+ public class VStarCamModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
50
51
  private static final String TAG = "VStarCamModule";
51
52
  public final static String MODULE_NAME = "VStarCam";
52
53
 
@@ -60,6 +61,9 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
60
61
  private static Object commandListenerProxy;
61
62
  private static Object releaseListenerProxy;
62
63
 
64
+ // Hard reference root to completely prevent Dalvik GC of our JNI proxies
65
+ private static final java.util.ArrayList<Object> jniProxyRoots = new java.util.ArrayList<>();
66
+
63
67
  // Static context reference for reloads
64
68
  private static java.lang.ref.WeakReference<ReactApplicationContext> currentContext;
65
69
 
@@ -201,6 +205,9 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
201
205
  this.reactContext = reactContext;
202
206
  this.executor = Executors.newCachedThreadPool();
203
207
 
208
+ // Register for lifecycle events to tear down JNI on fast-refresh
209
+ reactContext.addLifecycleEventListener(this);
210
+
204
211
  // Update current context for static proxies
205
212
  currentContext = new java.lang.ref.WeakReference<>(reactContext);
206
213
 
@@ -231,6 +238,39 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
231
238
  }
232
239
  }
233
240
 
241
+ @Override
242
+ public void onHostResume() {
243
+ }
244
+
245
+ @Override
246
+ public void onHostPause() {
247
+ }
248
+
249
+ @Override
250
+ public void onHostDestroy() {
251
+ Log.d(TAG, "onHostDestroy: Tearing down all P2P connections before JNI environment goes out of scope.");
252
+ executor.execute(() -> {
253
+ try {
254
+ if (jniApiClass != null) {
255
+ Method disconnectMethod = jniApiClass.getMethod("disconnect", long.class);
256
+ Method destroyMethod = jniApiClass.getMethod("destroy", long.class);
257
+
258
+ for (Map.Entry<Integer, ClientInfo> entry : clients.entrySet()) {
259
+ long sdkPtr = entry.getValue().sdkClientPtr;
260
+ if (sdkPtr != 0) {
261
+ Log.d(TAG, "Teardown SDK client: " + sdkPtr);
262
+ try { disconnectMethod.invoke(null, sdkPtr); } catch (Exception e) {}
263
+ try { destroyMethod.invoke(null, sdkPtr); } catch (Exception e) {}
264
+ }
265
+ }
266
+ clients.clear();
267
+ }
268
+ } catch (Exception e) {
269
+ Log.e(TAG, "Failed to teardown P2P in onHostDestroy", e);
270
+ }
271
+ });
272
+ }
273
+
234
274
  private void initializeP2P() {
235
275
  if (!VStarCamModule.isNativeLibraryLoaded || VStarCamModule.jniApiClass == null) {
236
276
  Log.e(TAG, "Cannot initialize P2P: native library or JNIApi not available");
@@ -283,6 +323,7 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
283
323
  }
284
324
  }
285
325
  );
326
+ jniProxyRoots.add(stateListenerProxy);
286
327
 
287
328
  // Create dynamic proxy for ClientCommandListener
288
329
  commandListenerProxy = Proxy.newProxyInstance(
@@ -326,6 +367,7 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
326
367
  }
327
368
  }
328
369
  );
370
+ jniProxyRoots.add(commandListenerProxy);
329
371
 
330
372
  // Create dynamic proxy for ClientReleaseListener
331
373
  releaseListenerProxy = Proxy.newProxyInstance(
@@ -352,6 +394,7 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
352
394
  }
353
395
  }
354
396
  );
397
+ jniProxyRoots.add(releaseListenerProxy);
355
398
 
356
399
  // Call JNIApi.init(stateListener, commandListener, releaseListener)
357
400
  Method initMethod = VStarCamModule.jniApiClass.getMethod("init",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bits-innovate/react-native-vstarcam",
3
- "version": "1.0.51",
3
+ "version": "1.0.53",
4
4
  "description": "React Native bridge for VStarCam P2P SDK",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",