feat: implement media echo fix and YouTube screenshare design
- Introduced a new `ScreenShareController` to manage YouTube screenshare functionality. - Updated `DiscordPlayer` to track ownership of audio streams, preventing conflicts between music playback and screenshare. - Added error handling for various states including voice connection checks and media busy states. - Created unit tests for `ScreenShareController` and `DiscordPlayer` ownership rules to ensure correct functionality. - Added documentation for the new media echo fix and screenshare design.
This commit is contained in:
49
tests/recorder.test.ts
Normal file
49
tests/recorder.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { EventEmitter } from "node:events";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const speaking = new EventEmitter();
|
||||
const subscribe = vi.fn();
|
||||
const joinVoiceChannel = vi.fn(() => ({
|
||||
receiver: {
|
||||
speaking,
|
||||
subscriptions: new Map(),
|
||||
subscribe,
|
||||
},
|
||||
on: vi.fn(),
|
||||
destroy: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@discordjs/voice", async () => {
|
||||
const actual =
|
||||
await vi.importActual<typeof import("@discordjs/voice")>(
|
||||
"@discordjs/voice",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
joinVoiceChannel,
|
||||
entersState: vi.fn(async () => undefined),
|
||||
};
|
||||
});
|
||||
|
||||
describe("startRecording", () => {
|
||||
it("does not subscribe to the bot user's own audio", async () => {
|
||||
const { startRecording } = await import("../src/recorder");
|
||||
const client = {
|
||||
user: { id: "bot-user" },
|
||||
};
|
||||
const channel = {
|
||||
id: "voice-channel",
|
||||
name: "Voice",
|
||||
guild: {
|
||||
id: "guild",
|
||||
voiceAdapterCreator: {},
|
||||
},
|
||||
};
|
||||
|
||||
await startRecording(client as never, channel as never);
|
||||
speaking.emit("start", "bot-user");
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
expect(subscribe).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user