From 357ba8b4d9ff5273755a30a7a283fbf950202906 Mon Sep 17 00:00:00 2001 From: Jannis Braun <151788261+TheZwiss@users.noreply.github.com> Date: Mon, 23 Mar 2026 14:23:48 +0100 Subject: [PATCH] refactor: thread ws parameter through handleClientEvent to voice handlers --- packages/server/src/ws/events.ts | 14 ++++++++------ packages/server/src/ws/handler.ts | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/server/src/ws/events.ts b/packages/server/src/ws/events.ts index f59afdfb..34e3a902 100644 --- a/packages/server/src/ws/events.ts +++ b/packages/server/src/ws/events.ts @@ -1,3 +1,4 @@ +import type { WebSocket } from 'ws'; import { eq, inArray, and } from 'drizzle-orm'; import { getDb, schema } from '../db/index.js'; import { generateSnowflake } from '../utils/snowflake.js'; @@ -134,6 +135,7 @@ export function handleClientEvent( event: Record, userId: string, username: string, + ws: WebSocket, ): void { const type = event.type as string; @@ -154,7 +156,7 @@ export function handleClientEvent( handlePresenceUpdate(event, userId); break; case 'voice_join': - handleVoiceJoin(event, userId); + handleVoiceJoin(event, userId, ws); break; case 'voice_leave': handleVoiceLeave(userId); @@ -184,10 +186,10 @@ export function handleClientEvent( handleMarkUnread(event, userId); break; case 'dm_call_start': - handleDmCallStart(event, userId, username); + handleDmCallStart(event, userId, username, ws); break; case 'dm_call_accept': - handleDmCallAccept(event, userId); + handleDmCallAccept(event, userId, ws); break; case 'dm_call_reject': handleDmCallReject(event, userId); @@ -552,7 +554,7 @@ function broadcastRoomLeave(roomId: string, room: VoiceRoom, userId: string): vo } } -function handleVoiceJoin(event: Record, userId: string): void { +function handleVoiceJoin(event: Record, userId: string, ws: WebSocket): void { const channelId = event.channelId as string; if (!channelId || typeof channelId !== 'string') { @@ -1274,7 +1276,7 @@ function handleMarkUnread(event: Record, userId: string): void // ─── DM Call Handlers (Unified Room API) ─────────────────────────────────── -function handleDmCallStart(event: Record, userId: string, username: string): void { +function handleDmCallStart(event: Record, userId: string, username: string, ws: WebSocket): void { const dmChannelId = event.dmChannelId as string; if (!dmChannelId || typeof dmChannelId !== 'string') { connectionManager.sendToUser(userId, { type: 'error', message: 'dmChannelId is required' }); @@ -1323,7 +1325,7 @@ function handleDmCallStart(event: Record, userId: string, usern }, userId); } -function handleDmCallAccept(event: Record, userId: string): void { +function handleDmCallAccept(event: Record, userId: string, ws: WebSocket): void { const dmChannelId = event.dmChannelId as string; if (!dmChannelId || typeof dmChannelId !== 'string') { connectionManager.sendToUser(userId, { type: 'error', message: 'dmChannelId is required' }); diff --git a/packages/server/src/ws/handler.ts b/packages/server/src/ws/handler.ts index c7410509..2b8b30bb 100644 --- a/packages/server/src/ws/handler.ts +++ b/packages/server/src/ws/handler.ts @@ -1311,7 +1311,7 @@ export async function registerWebSocket(app: FastifyInstance): Promise { // Handle authenticated events if (userId && username) { try { - handleClientEvent(parsed, userId, username); + handleClientEvent(parsed, userId, username, ws); } catch (err) { app.log.error({ err, eventType: parsed.type, userId }, 'Unhandled error in WS event handler'); try {