refactor: extract recorder domain types and modules

This commit is contained in:
MythEclipse
2026-05-13 15:56:42 +07:00
parent da108c5d84
commit dbe593c6fd
5 changed files with 295 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import { EndBehaviorType, type VoiceReceiver } from "@discordjs/voice";
export interface AudioStreamHandlers {
onPacket: (chunk: Buffer) => void;
onEnd: () => void;
onError: (error: Error) => void;
}
export function subscribeToAudioStream(
receiver: VoiceReceiver,
userId: string,
handlers: AudioStreamHandlers,
): NodeJS.ReadableStream {
const audioStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 3000,
},
});
audioStream.on("data", handlers.onPacket);
audioStream.on("end", handlers.onEnd);
audioStream.on("error", handlers.onError);
return audioStream;
}