From 9d097b15a5fda9a1fef1c17607c9b30445306e6d Mon Sep 17 00:00:00 2001 From: gxz Date: Mon, 16 Oct 2023 11:43:19 +0800 Subject: [PATCH 1/2] chore: change default export to FakeAgoraRTCWrapper --- src/index.ts | 2 +- tsup.config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 061b936..173a2c9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,4 +24,4 @@ export const FakeAgoraRTCWrapper = { getFakeAgoraRTC: getFakeAgoraRTC, }; -export default FakeAgoraRTC; +export default FakeAgoraRTCWrapper; diff --git a/tsup.config.ts b/tsup.config.ts index acc2e76..0617040 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -36,7 +36,7 @@ export default defineConfig([ define: { "process.env.NODE_ENV": JSON.stringify("production"), }, - globalName: "AgoraRTCFake", + globalName: "FakeAgoraRTCWrapper", platform: "browser", }, ]); From 58990aea22d7e856c7358218758f5bdc4471aa0b Mon Sep 17 00:00:00 2001 From: gxz Date: Mon, 16 Oct 2023 14:08:58 +0800 Subject: [PATCH 2/2] chore: override AgoraRTC --- src/index.ts | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/index.ts b/src/index.ts index 173a2c9..272ea6c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,10 @@ +import type { + IBufferSourceAudioTrack, + ILocalAudioTrack, + ILocalVideoTrack, + ScreenVideoTrackInitConfig, +} from "agora-rtc-sdk-ng"; + import { FakeRTCClient } from "./client"; import { createFakeAgoraRTC } from "./top"; import { FakeCameraVideoTrack, FakeMicrophoneAudioTrack } from "./tracks"; @@ -11,8 +18,49 @@ const FakeAgoraRTC = createFakeAgoraRTC({ setAppType(): void { // }, + setArea(): void { + // + }, + checkSystemRequirements(): boolean { + return true; + }, + setLogLevel(): void { + // + }, + getCameras(): Promise { + //todo + return Promise.resolve([]); + }, + getDevices(): Promise { + //todo + return Promise.resolve([]); + }, createMicrophoneAudioTrack: async () => FakeMicrophoneAudioTrack.create(), createCameraVideoTrack: async () => FakeCameraVideoTrack.create(), + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + createScreenVideoTrack( + config: ScreenVideoTrackInitConfig, + withAudio?: "enable" | "disable" | "auto", + ): Promise<[ILocalVideoTrack, ILocalAudioTrack] | ILocalVideoTrack> { + // 根据参数返回视频轨 或 [视频轨,音频轨] + if (withAudio === "enable") { + return Promise.resolve([ + FakeCameraVideoTrack.create() as ILocalVideoTrack, + FakeMicrophoneAudioTrack.create() as ILocalAudioTrack, + ]); + } else if (withAudio === "disable") { + return Promise.resolve(FakeCameraVideoTrack.create() as ILocalVideoTrack); + } else { + return Promise.resolve([ + FakeCameraVideoTrack.create() as ILocalVideoTrack, + FakeMicrophoneAudioTrack.create() as ILocalAudioTrack, + ]); + } + }, + createBufferSourceAudioTrack: async () => + FakeMicrophoneAudioTrack.create() as unknown as IBufferSourceAudioTrack, + createCustomVideoTrack: () => FakeCameraVideoTrack.create(), createClient: () => FakeRTCClient.create(), });