Commit 02483457 authored by hewenhao's avatar hewenhao

refactor(types): 重构 TypeScript 类型定义

- 将模块声明改为导出抽象类和接口 - 优化类和方法的组织结构 - 删除冗余的类型声明 - 调整成员的访问修饰符 - 简化部分代码结构
parent c0ac6090
{ {
"name": "@geek-front/ffmpeg-react-native", "name": "@geek-front/ffmpeg-react-native",
"version": "6.0.5", "version": "6.0.6",
"description": "FFmpeg Kit for React Native", "description": "FFmpeg Kit for React Native",
"main": "src/index", "main": "src/index",
"types": "src/index.d.ts", "types": "src/index.d.ts",
......
declare module 'ffmpeg-kit-react-native' { export abstract class AbstractSession implements Session {
export abstract class AbstractSession implements Session {
static createFFmpegSession(argumentsArray: Array<string>, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFmpegSession>; static createFFmpegSession(argumentsArray: Array<string>, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFmpegSession>;
...@@ -58,19 +56,19 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -58,19 +56,19 @@ declare module 'ffmpeg-kit-react-native' {
cancel(): Promise<void>; cancel(): Promise<void>;
} }
export class ArchDetect { export class ArchDetect {
static getArch(): Promise<string>; static getArch(): Promise<string>;
} }
export type FFmpegSessionCompleteCallback = (session: FFmpegSession) => void; export type FFmpegSessionCompleteCallback = (session: FFmpegSession) => void;
export type FFprobeSessionCompleteCallback = (session: FFprobeSession) => void; export type FFprobeSessionCompleteCallback = (session: FFprobeSession) => void;
export type MediaInformationSessionCompleteCallback = (session: MediaInformationSession) => void; export type MediaInformationSessionCompleteCallback = (session: MediaInformationSession) => void;
export class FFmpegKit { export class FFmpegKit {
static execute(command: string): Promise<FFmpegSession>; static execute(command: string): Promise<FFmpegSession>;
...@@ -84,9 +82,9 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -84,9 +82,9 @@ declare module 'ffmpeg-kit-react-native' {
static listSessions(): Promise<FFmpegSession[]>; static listSessions(): Promise<FFmpegSession[]>;
} }
export class FFmpegKitConfig { export class FFmpegKitConfig {
static init(): Promise<void>; static init(): Promise<void>;
...@@ -206,9 +204,9 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -206,9 +204,9 @@ declare module 'ffmpeg-kit-react-native' {
static selectDocumentForWrite(title?: string, type?: string, extraTypes?: string[]): Promise<string>; static selectDocumentForWrite(title?: string, type?: string, extraTypes?: string[]): Promise<string>;
} }
export class FFmpegSession extends AbstractSession implements Session { export class FFmpegSession extends AbstractSession implements Session {
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>;
...@@ -228,9 +226,9 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -228,9 +226,9 @@ declare module 'ffmpeg-kit-react-native' {
isMediaInformation(): boolean; isMediaInformation(): boolean;
} }
export class FFprobeKit { export class FFprobeKit {
static execute(command: string): Promise<FFprobeSession>; static execute(command: string): Promise<FFprobeSession>;
...@@ -256,9 +254,9 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -256,9 +254,9 @@ declare module 'ffmpeg-kit-react-native' {
static listMediaInformationSessions(): Promise<MediaInformationSession[]>; static listMediaInformationSessions(): Promise<MediaInformationSession[]>;
} }
export class FFprobeSession extends AbstractSession implements Session { export class FFprobeSession extends AbstractSession implements Session {
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>;
...@@ -270,9 +268,9 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -270,9 +268,9 @@ declare module 'ffmpeg-kit-react-native' {
isMediaInformation(): boolean; isMediaInformation(): boolean;
} }
export class Level { export class Level {
static readonly AV_LOG_STDERR: number; static readonly AV_LOG_STDERR: number;
static readonly AV_LOG_QUIET: number; static readonly AV_LOG_QUIET: number;
static readonly AV_LOG_PANIC: number; static readonly AV_LOG_PANIC: number;
...@@ -285,9 +283,9 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -285,9 +283,9 @@ declare module 'ffmpeg-kit-react-native' {
static readonly AV_LOG_TRACE: number; static readonly AV_LOG_TRACE: number;
static levelToString(number: number): string; static levelToString(number: number): string;
} }
export class Log { export class Log {
constructor(sessionId: number, level: number, message: String); constructor(sessionId: number, level: number, message: String);
...@@ -297,19 +295,19 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -297,19 +295,19 @@ declare module 'ffmpeg-kit-react-native' {
getMessage(): String; getMessage(): String;
} }
export type LogCallback = (log: Log) => void; export type LogCallback = (log: Log) => void;
export enum LogRedirectionStrategy { export enum LogRedirectionStrategy {
ALWAYS_PRINT_LOGS = 0, ALWAYS_PRINT_LOGS = 0,
PRINT_LOGS_WHEN_NO_CALLBACKS_DEFINED = 1, PRINT_LOGS_WHEN_NO_CALLBACKS_DEFINED = 1,
PRINT_LOGS_WHEN_GLOBAL_CALLBACK_NOT_DEFINED = 2, PRINT_LOGS_WHEN_GLOBAL_CALLBACK_NOT_DEFINED = 2,
PRINT_LOGS_WHEN_SESSION_CALLBACK_NOT_DEFINED = 3, PRINT_LOGS_WHEN_SESSION_CALLBACK_NOT_DEFINED = 3,
NEVER_PRINT_LOGS = 4 NEVER_PRINT_LOGS = 4
} }
export class MediaInformation { export class MediaInformation {
static readonly KEY_FORMAT_PROPERTIES: string; static readonly KEY_FORMAT_PROPERTIES: string;
static readonly KEY_FILENAME: string; static readonly KEY_FILENAME: string;
...@@ -359,17 +357,17 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -359,17 +357,17 @@ declare module 'ffmpeg-kit-react-native' {
getAllProperties(): Record<string, any>; getAllProperties(): Record<string, any>;
} }
export class MediaInformationJsonParser { export class MediaInformationJsonParser {
static from(ffprobeJsonOutput: string): Promise<MediaInformation>; static from(ffprobeJsonOutput: string): Promise<MediaInformation>;
static fromWithError(ffprobeJsonOutput: string): Promise<MediaInformation>; static fromWithError(ffprobeJsonOutput: string): Promise<MediaInformation>;
} }
export class MediaInformationSession extends AbstractSession implements Session { export class MediaInformationSession extends AbstractSession implements Session {
static create(argumentsArray: Array<string>, completeCallback?: MediaInformationSessionCompleteCallback, logCallback?: LogCallback): Promise<MediaInformationSession>; static create(argumentsArray: Array<string>, completeCallback?: MediaInformationSessionCompleteCallback, logCallback?: LogCallback): Promise<MediaInformationSession>;
...@@ -385,17 +383,17 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -385,17 +383,17 @@ declare module 'ffmpeg-kit-react-native' {
isMediaInformation(): boolean; isMediaInformation(): boolean;
} }
export class Packages { export class Packages {
static getPackageName(): Promise<string>; static getPackageName(): Promise<string>;
static getExternalLibraries(): Promise<string[]>; static getExternalLibraries(): Promise<string[]>;
} }
export class ReturnCode { export class ReturnCode {
static readonly SUCCESS: number; static readonly SUCCESS: number;
...@@ -415,9 +413,9 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -415,9 +413,9 @@ declare module 'ffmpeg-kit-react-native' {
isValueCancel(): boolean; isValueCancel(): boolean;
} }
export interface Session { export interface Session {
getLogCallback(): LogCallback; getLogCallback(): LogCallback;
...@@ -463,24 +461,24 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -463,24 +461,24 @@ declare module 'ffmpeg-kit-react-native' {
cancel(): Promise<void>; cancel(): Promise<void>;
} }
export enum SessionState { export enum SessionState {
CREATED = 0, CREATED = 0,
RUNNING = 1, RUNNING = 1,
FAILED = 2, FAILED = 2,
COMPLETED = 3 COMPLETED = 3
} }
export enum Signal { export enum Signal {
SIGINT = 2, SIGINT = 2,
SIGQUIT = 3, SIGQUIT = 3,
SIGPIPE = 13, SIGPIPE = 13,
SIGTERM = 15, SIGTERM = 15,
SIGXCPU = 24 SIGXCPU = 24
} }
export class Statistics { export class Statistics {
constructor(sessionId: number, videoFrameNumber: number, videoFps: number, videoQuality: number, size: number, time: number, bitrate: number, speed: number); constructor(sessionId: number, videoFrameNumber: number, videoFps: number, videoQuality: number, size: number, time: number, bitrate: number, speed: number);
...@@ -516,11 +514,11 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -516,11 +514,11 @@ declare module 'ffmpeg-kit-react-native' {
setSpeed(speed: number): void; setSpeed(speed: number): void;
} }
export type StatisticsCallback = (statistics: Statistics) => void; export type StatisticsCallback = (statistics: Statistics) => void;
export class StreamInformation { export class StreamInformation {
static readonly KEY_INDEX: string; static readonly KEY_INDEX: string;
static readonly KEY_TYPE: string; static readonly KEY_TYPE: string;
...@@ -587,9 +585,9 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -587,9 +585,9 @@ declare module 'ffmpeg-kit-react-native' {
getAllProperties(): Record<string, any>; getAllProperties(): Record<string, any>;
} }
export class Chapter { export class Chapter {
static readonly KEY_ID: string; static readonly KEY_ID: string;
static readonly KEY_TIME_BASE: string; static readonly KEY_TIME_BASE: string;
...@@ -623,6 +621,4 @@ declare module 'ffmpeg-kit-react-native' { ...@@ -623,6 +621,4 @@ declare module 'ffmpeg-kit-react-native' {
getAllProperties(): Record<string, any>; getAllProperties(): Record<string, any>;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment