diff --git a/services/backend/src/ws/redis-bridge.ts b/services/backend/src/ws/redis-bridge.ts index 4127bbd..651642d 100644 --- a/services/backend/src/ws/redis-bridge.ts +++ b/services/backend/src/ws/redis-bridge.ts @@ -26,11 +26,9 @@ const SUBSCRIPTIONS: ChannelMapping[] = [ eventType: "analysis_queue_status", }, { channel: "discord:voice:active_user", eventType: "voice_active_user" }, + { channel: "discord:voice:pcm", eventType: "voice_pcm_data" }, ]; -// Binary channels that need special handling (messageBuffer event) -const BINARY_CHANNELS = ["discord:voice:pcm"]; - let subscriber: Redis | null = null; function createSubscriber(): Redis { @@ -94,41 +92,6 @@ function handleSubscriptionMessage(channel: string, message: string): void { broadcastRaw(mapping.eventType, data); } -/** - * Handle binary messages from Redis (e.g. voice PCM data). - * Expected format: 4-byte userId hash + PCM buffer - */ -function handleBinaryMessage(channel: Buffer, message: Buffer): void { - const channelStr = channel.toString(); - - if (channelStr === "discord:voice:pcm") { - if (message.length < 4) { - logger.warn( - { channel: channelStr, size: message.length }, - "Received PCM message too short to contain userId", - ); - return; - } - - // First 4 bytes = userId hash, rest = PCM data - const userIdHash = message.readUInt32LE(0); - const pcmData = message.subarray(4); - - logger.debug( - { channel: channelStr, userIdHash, pcmSize: pcmData.length }, - "Broadcasting voice PCM data", - ); - - // Broadcast as binary: userId (4 bytes) + PCM data - broadcastRaw("voice_pcm", message); - } else { - logger.warn( - { channel: channelStr }, - "Received binary message for unmapped channel", - ); - } -} - export async function startRedisBridge(): Promise { if (!config.REDIS_URL && !config.REDIS_HOST) { logger.info("Redis not configured, skipping Redis bridge"); @@ -155,7 +118,6 @@ export async function startRedisBridge(): Promise { }); subscriber.on("message", handleSubscriptionMessage); - subscriber.on("messageBuffer", handleBinaryMessage); await subscriber.ping(); logger.info("Redis ping OK"); @@ -164,11 +126,6 @@ export async function startRedisBridge(): Promise { await subscriber.subscribe(...channels); logger.info({ channels }, "Subscribed to Redis channels"); - if (BINARY_CHANNELS.length > 0) { - await subscriber.subscribe(...BINARY_CHANNELS); - logger.info({ channels: BINARY_CHANNELS }, "Subscribed to binary Redis channels"); - } - logger.info("Redis bridge started"); } catch (err) { logger.error({ err }, "Failed to start Redis bridge");