fix(frontend): handle voice PCM data as JSON instead of binary

- Add onVoicePcmData and onVoiceActiveUser handlers to WebSocket interface
- Add voice_pcm_data and voice_active_user event cases in socket message handler
- Update useAudioPlayback to decode base64 PCM from JSON format
- Connect onVoicePcmData to audio.handleIncomingPcm in App.tsx

Format change:
- Old: Binary (4 bytes userId + PCM buffer)
- New: JSON {userId: string, pcm: base64string}

This matches the format sent by discord-gateway via Redis.
Now PCM audio will flow correctly: Discord → Gateway → Redis → Backend → WebSocket → Browser!

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
MythEclipse
2026-06-08 21:22:00 +07:00
co-authored by Claude Opus 4.8
parent 1c7b7e6398
commit 2e9e9c1a06
3 changed files with 31 additions and 7 deletions
+12
View File
@@ -18,6 +18,8 @@ export interface WsHandlers {
onVoiceRecordingStarted?: (data: unknown) => void;
onVoiceRecordingStopped?: (data: unknown) => void;
onVoiceRecordingUploaded?: (data: unknown) => void;
onVoicePcmData?: (data: unknown) => void;
onVoiceActiveUser?: (data: unknown) => void;
}
let _wsInstance: WebSocket | null = null;
@@ -90,6 +92,12 @@ function doConnect(): WebSocket {
case "voice_recording_stopped":
h.onVoiceRecordingStopped?.(msg.data);
break;
case "voice_pcm_data":
h.onVoicePcmData?.(msg.data);
break;
case "voice_active_user":
h.onVoiceActiveUser?.(msg.data);
break;
case "attachment_created":
// attachment_created is informational — same data shape as message_created
h.onMessageCreated?.(msg.data);
@@ -149,6 +157,10 @@ export function useDashboardSocket(handlers: WsHandlers) {
handlersRef.current.onVoiceRecordingStarted?.(d),
onVoiceRecordingStopped: (d) =>
handlersRef.current.onVoiceRecordingStopped?.(d),
onVoicePcmData: (d) =>
handlersRef.current.onVoicePcmData?.(d),
onVoiceActiveUser: (d) =>
handlersRef.current.onVoiceActiveUser?.(d),
};
_listeners.add(wrapper);