fix(discord voice): fire-and-forget autoJoin and increase playback timeout to 60s

This commit is contained in:
geekhuashan 2026-04-03 22:42:14 +08:00 committed by Peter Steinberger
parent 136f177cb3
commit db593440c4
2 changed files with 29 additions and 3 deletions

View File

@ -0,0 +1,24 @@
import { describe, expect, it, vi } from "vitest";
import { DiscordVoiceReadyListener } from "./manager.js";
describe("DiscordVoiceReadyListener", () => {
it("starts auto-join without blocking the ready listener", async () => {
let resolveJoin: (() => void) | undefined;
const autoJoin = vi.fn(
() =>
new Promise<void>((resolve) => {
resolveJoin = resolve;
}),
);
const listener = new DiscordVoiceReadyListener({
autoJoin,
} as unknown as ConstructorParameters<typeof DiscordVoiceReadyListener>[0]);
const result = listener.handle({} as never, {} as never);
await expect(result).resolves.toBeUndefined();
expect(autoJoin).toHaveBeenCalledTimes(1);
resolveJoin?.();
});
});

View File

@ -32,7 +32,7 @@ const CHANNELS = 2;
const BIT_DEPTH = 16;
const MIN_SEGMENT_SECONDS = 0.35;
const SILENCE_DURATION_MS = 1_000;
const PLAYBACK_READY_TIMEOUT_MS = 15_000;
const PLAYBACK_READY_TIMEOUT_MS = 60_000;
const SPEAKING_READY_TIMEOUT_MS = 60_000;
const DECRYPT_FAILURE_WINDOW_MS = 30_000;
const DECRYPT_FAILURE_RECONNECT_THRESHOLD = 3;
@ -939,8 +939,10 @@ export class DiscordVoiceReadyListener extends ReadyListener {
super();
}
async handle() {
await this.manager.autoJoin();
async handle(_data: unknown, _client: Client): Promise<void> {
void this.manager
.autoJoin()
.catch((err) => logger.warn(`discord voice: autoJoin failed: ${formatErrorMessage(err)}`));
}
}