refactor session create methods

pull/585/head
Taner Sener 3 years ago
parent c43fed6901
commit 235af6a8c3
  1. 6
      react-native/android/src/main/java/com/arthenica/ffmpegkit/reactnative/FFmpegKitReactNativeModule.java
  2. 6
      react-native/ios/FFmpegKitReactNativeModule.m
  3. 14
      react-native/src/index.d.ts
  4. 64
      react-native/src/index.js

@ -344,7 +344,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule {
@ReactMethod @ReactMethod
public void ffmpegSession(final ReadableArray readableArray, final Promise promise) { public void ffmpegSession(final ReadableArray readableArray, final Promise promise) {
promise.resolve(toMap(new FFmpegSession(toArgumentsArray(readableArray), null, null, null, LogRedirectionStrategy.NEVER_PRINT_LOGS))); promise.resolve(toMap(FFmpegSession.create(toArgumentsArray(readableArray), null, null, null, LogRedirectionStrategy.NEVER_PRINT_LOGS)));
} }
@ReactMethod @ReactMethod
@ -395,14 +395,14 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule {
@ReactMethod @ReactMethod
public void ffprobeSession(final ReadableArray readableArray, final Promise promise) { public void ffprobeSession(final ReadableArray readableArray, final Promise promise) {
promise.resolve(toMap(new FFprobeSession(toArgumentsArray(readableArray), null, null, LogRedirectionStrategy.NEVER_PRINT_LOGS))); promise.resolve(toMap(FFprobeSession.create(toArgumentsArray(readableArray), null, null, LogRedirectionStrategy.NEVER_PRINT_LOGS)));
} }
// MediaInformationSession // MediaInformationSession
@ReactMethod @ReactMethod
public void mediaInformationSession(final ReadableArray readableArray, final Promise promise) { public void mediaInformationSession(final ReadableArray readableArray, final Promise promise) {
promise.resolve(toMap(new MediaInformationSession(toArgumentsArray(readableArray), null, null))); promise.resolve(toMap(MediaInformationSession.create(toArgumentsArray(readableArray), null, null)));
} }
// MediaInformationJsonParser // MediaInformationJsonParser

@ -244,7 +244,7 @@ RCT_EXPORT_METHOD(getArch:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRe
// FFmpegSession // FFmpegSession
RCT_EXPORT_METHOD(ffmpegSession:(NSArray*)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { RCT_EXPORT_METHOD(ffmpegSession:(NSArray*)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
FFmpegSession* session = [[FFmpegSession alloc] init:arguments withCompleteCallback:nil withLogCallback:nil withStatisticsCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs]; FFmpegSession* session = [FFmpegSession create:arguments withCompleteCallback:nil withLogCallback:nil withStatisticsCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
resolve([FFmpegKitReactNativeModule toSessionDictionary:session]); resolve([FFmpegKitReactNativeModule toSessionDictionary:session]);
} }
@ -285,14 +285,14 @@ RCT_EXPORT_METHOD(ffmpegSessionGetStatistics:(int)sessionId resolver:(RCTPromise
// FFprobeSession // FFprobeSession
RCT_EXPORT_METHOD(ffprobeSession:(NSArray*)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { RCT_EXPORT_METHOD(ffprobeSession:(NSArray*)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
FFprobeSession* session = [[FFprobeSession alloc] init:arguments withCompleteCallback:nil withLogCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs]; FFprobeSession* session = [FFprobeSession create:arguments withCompleteCallback:nil withLogCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
resolve([FFmpegKitReactNativeModule toSessionDictionary:session]); resolve([FFmpegKitReactNativeModule toSessionDictionary:session]);
} }
// MediaInformationSession // MediaInformationSession
RCT_EXPORT_METHOD(mediaInformationSession:(NSArray*)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { RCT_EXPORT_METHOD(mediaInformationSession:(NSArray*)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withCompleteCallback:nil withLogCallback:nil]; MediaInformationSession* session = [MediaInformationSession create:arguments withCompleteCallback:nil withLogCallback:nil];
resolve([FFmpegKitReactNativeModule toSessionDictionary:session]); resolve([FFmpegKitReactNativeModule toSessionDictionary:session]);
} }

@ -2,8 +2,6 @@ declare module 'ffmpeg-kit-react-native' {
export abstract class AbstractSession implements Session { export abstract class AbstractSession implements Session {
protected constructor();
static createFFmpegSession(argumentsArray: Array<string>, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFmpegSession>; static createFFmpegSession(argumentsArray: Array<string>, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFmpegSession>;
static createFFmpegSessionFromMap(sessionMap: { [key: string]: any }): FFmpegSession; static createFFmpegSessionFromMap(sessionMap: { [key: string]: any }): FFmpegSession;
@ -212,12 +210,8 @@ declare module 'ffmpeg-kit-react-native' {
export class FFmpegSession extends AbstractSession implements Session { export class FFmpegSession extends AbstractSession implements Session {
constructor();
static create(argumentsArray: Array<string>, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFmpegSession>; static create(argumentsArray: Array<string>, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFmpegSession>;
static fromMap(sessionMap: { [key: string]: any }): FFmpegSession;
getStatisticsCallback(): StatisticsCallback; getStatisticsCallback(): StatisticsCallback;
getCompleteCallback(): FFmpegSessionCompleteCallback; getCompleteCallback(): FFmpegSessionCompleteCallback;
@ -266,12 +260,8 @@ declare module 'ffmpeg-kit-react-native' {
export class FFprobeSession extends AbstractSession implements Session { export class FFprobeSession extends AbstractSession implements Session {
constructor();
static create(argumentsArray: Array<string>, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFprobeSession>; static create(argumentsArray: Array<string>, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFprobeSession>;
static fromMap(sessionMap: { [key: string]: any }): FFprobeSession;
getCompleteCallback(): FFprobeSessionCompleteCallback; getCompleteCallback(): FFprobeSessionCompleteCallback;
isFFmpeg(): boolean; isFFmpeg(): boolean;
@ -381,12 +371,8 @@ declare module 'ffmpeg-kit-react-native' {
export class MediaInformationSession extends AbstractSession implements Session { export class MediaInformationSession extends AbstractSession implements Session {
constructor();
static create(argumentsArray: Array<string>, completeCallback?: MediaInformationSessionCompleteCallback, logCallback?: LogCallback): Promise<MediaInformationSession>; static create(argumentsArray: Array<string>, completeCallback?: MediaInformationSessionCompleteCallback, logCallback?: LogCallback): Promise<MediaInformationSession>;
static fromMap(sessionMap: { [key: string]: any }): MediaInformationSession;
getMediaInformation(): MediaInformation; getMediaInformation(): MediaInformation;
setMediaInformation(mediaInformation: MediaInformation): void; setMediaInformation(mediaInformation: MediaInformation): void;

@ -296,13 +296,6 @@ export class AbstractSession extends Session {
*/ */
#logRedirectionStrategy; #logRedirectionStrategy;
/**
* Creates a new abstract session.
*/
constructor() {
super();
}
/** /**
* Creates a new FFmpeg session. * Creates a new FFmpeg session.
* *
@ -1605,12 +1598,12 @@ class FFmpegKitFactory {
if (sessionMap !== undefined) { if (sessionMap !== undefined) {
switch (sessionMap.type) { switch (sessionMap.type) {
case 2: case 2:
return FFprobeSession.fromMap(sessionMap); return AbstractSession.createFFprobeSessionFromMap(sessionMap);
case 3: case 3:
return MediaInformationSession.fromMap(sessionMap); return AbstractSession.createMediaInformationSessionFromMap(sessionMap);
case 1: case 1:
default: default:
return FFmpegSession.fromMap(sessionMap); return AbstractSession.createFFmpegSessionFromMap(sessionMap);
} }
} else { } else {
return undefined; return undefined;
@ -1935,13 +1928,6 @@ class FFmpegKitInitializer {
*/ */
export class FFmpegSession extends AbstractSession { export class FFmpegSession extends AbstractSession {
/**
* Creates an empty FFmpeg session.
*/
constructor() {
super();
}
/** /**
* Creates a new FFmpeg session. * Creates a new FFmpeg session.
* *
@ -1963,16 +1949,6 @@ export class FFmpegSession extends AbstractSession {
return session; return session;
} }
/**
* Creates a new FFmpeg session from the given map.
*
* @param sessionMap map that includes session fields as map keys
* @returns FFmpeg session created
*/
static fromMap(sessionMap) {
return AbstractSession.createFFmpegSessionFromMap(sessionMap);
}
/** /**
* Returns the session specific statistics callback. * Returns the session specific statistics callback.
* *
@ -2252,13 +2228,6 @@ export class FFprobeKit {
*/ */
export class FFprobeSession extends AbstractSession { export class FFprobeSession extends AbstractSession {
/**
* Creates an empty FFprobe session.
*/
constructor() {
super();
}
/** /**
* Creates a new FFprobe session. * Creates a new FFprobe session.
* *
@ -2278,16 +2247,6 @@ export class FFprobeSession extends AbstractSession {
return session; return session;
} }
/**
* Creates a new FFprobe session from the given map.
*
* @param sessionMap map that includes session fields as map keys
* @returns FFprobe session created
*/
static fromMap(sessionMap) {
return AbstractSession.createFFprobeSessionFromMap(sessionMap);
}
/** /**
* Returns the session specific complete callback. * Returns the session specific complete callback.
* *
@ -2722,13 +2681,6 @@ export class MediaInformationJsonParser {
export class MediaInformationSession extends AbstractSession { export class MediaInformationSession extends AbstractSession {
#mediaInformation; #mediaInformation;
/**
* Creates an empty MediaInformationSession.
*/
constructor() {
super();
}
/** /**
* Creates a new MediaInformationSession session. * Creates a new MediaInformationSession session.
* *
@ -2747,16 +2699,6 @@ export class MediaInformationSession extends AbstractSession {
return session; return session;
} }
/**
* Creates a new MediaInformationSession from the given map.
*
* @param sessionMap map that includes session fields as map keys
* @returns MediaInformationSession created
*/
static fromMap(sessionMap) {
return AbstractSession.createMediaInformationSessionFromMap(sessionMap);
}
/** /**
* Returns the media information extracted in this session. * Returns the media information extracted in this session.
* *

Loading…
Cancel
Save