From a85998b8f221e5c8ca6c40c1720bc909a40d2344 Mon Sep 17 00:00:00 2001 From: taoqf Date: Thu, 16 May 2019 00:01:51 +0800 Subject: [PATCH] add types: react-native-audio (#35466) * wxapp: add FileSystemManager * fix: add interface * uppercase interface name * add types react-native-audio --- types/react-native-audio/index.d.ts | 58 +++++++++++++++++++ .../react-native-audio-tests.ts | 13 +++++ types/react-native-audio/tsconfig.json | 23 ++++++++ types/react-native-audio/tslint.json | 1 + 4 files changed, 95 insertions(+) create mode 100644 types/react-native-audio/index.d.ts create mode 100644 types/react-native-audio/react-native-audio-tests.ts create mode 100644 types/react-native-audio/tsconfig.json create mode 100644 types/react-native-audio/tslint.json diff --git a/types/react-native-audio/index.d.ts b/types/react-native-audio/index.d.ts new file mode 100644 index 0000000000..3e202b6e8f --- /dev/null +++ b/types/react-native-audio/index.d.ts @@ -0,0 +1,58 @@ +// Type definitions for react-native-audio 4.3 +// Project: https://github.com/jsierles/react-native-audio#readme +// Definitions by: taoqf +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export type AudioEncodingAndroidType = 'aac_eld' | 'amr_nb' | 'amr_wb' | 'he_aac' | 'vorbis'; + +export type AudioEncodingIOSType = 'lpcm' | 'ima4' | 'MAC3' | 'MAC6' | 'ulaw' | 'alaw' | 'mp1' | 'mp2' | 'alac' | 'amr'; + +export type AudioEncodingType = 'aac' | AudioEncodingAndroidType | AudioEncodingAndroidType; + +export interface RecordingOptions { + SampleRate?: number; + Channels?: number; + AudioQuality?: 'Low' | 'Medium' | 'High'; + AudioEncoding?: AudioEncodingType; + OutputFormat?: string; + MeteringEnabled?: boolean; + MeasurementMode?: boolean; + AudioEncodingBitRate?: number; + IncludeBase64?: boolean; + AudioSource?: number; +} + +export const AudioRecorder: { + requestAuthorization(): Promise; + prepareRecordingAtPath(path: string, options: RecordingOptions): Promise; + startRecording(): Promise; + stopRecording(): Promise; + resumeRecording(): Promise; + pauseRecording(): Promise; + checkAuthorizationStatus(): Promise; + onProgress(res: { currentTime: number; }): void; + onFinished(res: { audioFileURL: string; base64: string; status: string; }): void; +}; + +export const AudioUtils: { + CachesDirectoryPath: string; + DocumentDirectoryPath: string; + DownloadsDirectoryPath: string; + LibraryDirectoryPath: string; + MainBundlePath: string; + MusicDirectoryPath: string; + PicturesDirectoryPath: string; +}; + +export const AudioSource: { + CAMCORDER: number; + DEFAULT: number; + MIC: number; + REMOTE_SUBMIX: number; + UNPROCESSED: number; + VOICE_CALL: number; + VOICE_COMMUNICATION: number; + VOICE_DOWNLINK: number; + VOICE_RECOGNITION: number; + VOICE_UPLINK: number; +}; diff --git a/types/react-native-audio/react-native-audio-tests.ts b/types/react-native-audio/react-native-audio-tests.ts new file mode 100644 index 0000000000..29f3d79a7c --- /dev/null +++ b/types/react-native-audio/react-native-audio-tests.ts @@ -0,0 +1,13 @@ +import { AudioRecorder, AudioUtils } from 'react-native-audio'; +const audioPath = AudioUtils.DocumentDirectoryPath + '/test.aac'; + +AudioRecorder.prepareRecordingAtPath(audioPath, { + SampleRate: 22050, + Channels: 1, + AudioQuality: "Low", + AudioEncoding: "aac" +}); + +AudioRecorder.onProgress = (data) => { + // todo +}; diff --git a/types/react-native-audio/tsconfig.json b/types/react-native-audio/tsconfig.json new file mode 100644 index 0000000000..548af520da --- /dev/null +++ b/types/react-native-audio/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-native-audio-tests.ts" + ] +} \ No newline at end of file diff --git a/types/react-native-audio/tslint.json b/types/react-native-audio/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-audio/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }