@bits-innovate/react-native-vstarcam 1.0.52 → 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
 
@@ -204,6 +205,9 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
204
205
  this.reactContext = reactContext;
205
206
  this.executor = Executors.newCachedThreadPool();
206
207
 
208
+ // Register for lifecycle events to tear down JNI on fast-refresh
209
+ reactContext.addLifecycleEventListener(this);
210
+
207
211
  // Update current context for static proxies
208
212
  currentContext = new java.lang.ref.WeakReference<>(reactContext);
209
213
 
@@ -234,6 +238,39 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
234
238
  }
235
239
  }
236
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
+
237
274
  private void initializeP2P() {
238
275
  if (!VStarCamModule.isNativeLibraryLoaded || VStarCamModule.jniApiClass == null) {
239
276
  Log.e(TAG, "Cannot initialize P2P: native library or JNIApi not available");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bits-innovate/react-native-vstarcam",
3
- "version": "1.0.52",
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",