Skip to content

Commit

Permalink
do not listen ActivityEventListener methods on react native, fixes #397
Browse files Browse the repository at this point in the history
  • Loading branch information
tanersener committed May 20, 2022
1 parent fd351b7 commit 5f601fb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Taner Sener
* Copyright (c) 2021-2022 Taner Sener
*
* This file is part of FFmpegKit.
*
Expand Down Expand Up @@ -47,7 +47,6 @@
import com.arthenica.ffmpegkit.Statistics;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.BaseActivityEventListener;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
Expand Down Expand Up @@ -75,7 +74,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;

public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule {

public static final String LIBRARY_NAME = "ffmpeg-kit-react-native";
public static final String PLATFORM_NAME = "android";
Expand Down Expand Up @@ -131,7 +130,6 @@ public FFmpegKitReactNativeModule(@Nullable ReactApplicationContext reactContext
this.asyncExecutorService = Executors.newFixedThreadPool(asyncWriteToPipeConcurrencyLimit);

if (reactContext != null) {
reactContext.addLifecycleEventListener(this);
registerGlobalCallbacks(reactContext);
}
}
Expand All @@ -151,19 +149,6 @@ public String getName() {
return "FFmpegKitReactNativeModule";
}

@Override
public void onHostResume() {
}

@Override
public void onHostPause() {
}

@Override
public void onHostDestroy() {
this.asyncExecutorService.shutdown();
}

protected void registerGlobalCallbacks(final ReactApplicationContext reactContext) {
FFmpegKitConfig.enableFFmpegSessionCompleteCallback(session -> {
final DeviceEventManagerModule.RCTDeviceEventEmitter jsModule = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
Expand Down Expand Up @@ -984,6 +969,12 @@ public void getExternalLibraries(final Promise promise) {
promise.resolve(toStringArray(Packages.getExternalLibraries()));
}

@ReactMethod
public void uninit(final Promise promise) {
this.asyncExecutorService.shutdown();
promise.resolve(null);
}

protected void enableLogs() {
logsEnabled.compareAndSet(false, true);
}
Expand Down
6 changes: 5 additions & 1 deletion react-native/ios/FFmpegKitReactNativeModule.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Taner Sener
* Copyright (c) 2021-2022 Taner Sener
*
* This file is part of FFmpegKit.
*
Expand Down Expand Up @@ -695,6 +695,10 @@ - (void)registerGlobalCallbacks {
resolve([Packages getExternalLibraries]);
}

RCT_EXPORT_METHOD(uninit:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
resolve(nil);
}

- (void)enableLogs {
logsEnabled = true;
}
Expand Down
2 changes: 2 additions & 0 deletions react-native/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ declare module 'ffmpeg-kit-react-native' {

static init(): Promise<void>;

static uninit(): Promise<void>;

static enableRedirection(): Promise<void>;

static disableRedirection(): Promise<void>;
Expand Down
9 changes: 9 additions & 0 deletions react-native/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,15 @@ export class FFmpegKitConfig {
await FFmpegKitInitializer.initialize();
}

/**
* Uninitializes the library.
*
* Calling this method before application termination is recommended but not required.
*/
static async uninit() {
return FFmpegKitReactNativeModule.uninit();
}

/**
* <p>Enables log and statistics redirection.
*
Expand Down

0 comments on commit 5f601fb

Please sign in to comment.