refactor: thread ws parameter through handleClientEvent to voice handlers

This commit is contained in:
Jannis Braun
2026-03-23 14:23:48 +01:00
parent 80c32ae1e6
commit 357ba8b4d9
2 changed files with 9 additions and 7 deletions
+8 -6
View File
@@ -1,3 +1,4 @@
import type { WebSocket } from 'ws';
import { eq, inArray, and } from 'drizzle-orm'; import { eq, inArray, and } from 'drizzle-orm';
import { getDb, schema } from '../db/index.js'; import { getDb, schema } from '../db/index.js';
import { generateSnowflake } from '../utils/snowflake.js'; import { generateSnowflake } from '../utils/snowflake.js';
@@ -134,6 +135,7 @@ export function handleClientEvent(
event: Record<string, unknown>, event: Record<string, unknown>,
userId: string, userId: string,
username: string, username: string,
ws: WebSocket,
): void { ): void {
const type = event.type as string; const type = event.type as string;
@@ -154,7 +156,7 @@ export function handleClientEvent(
handlePresenceUpdate(event, userId); handlePresenceUpdate(event, userId);
break; break;
case 'voice_join': case 'voice_join':
handleVoiceJoin(event, userId); handleVoiceJoin(event, userId, ws);
break; break;
case 'voice_leave': case 'voice_leave':
handleVoiceLeave(userId); handleVoiceLeave(userId);
@@ -184,10 +186,10 @@ export function handleClientEvent(
handleMarkUnread(event, userId); handleMarkUnread(event, userId);
break; break;
case 'dm_call_start': case 'dm_call_start':
handleDmCallStart(event, userId, username); handleDmCallStart(event, userId, username, ws);
break; break;
case 'dm_call_accept': case 'dm_call_accept':
handleDmCallAccept(event, userId); handleDmCallAccept(event, userId, ws);
break; break;
case 'dm_call_reject': case 'dm_call_reject':
handleDmCallReject(event, userId); handleDmCallReject(event, userId);
@@ -552,7 +554,7 @@ function broadcastRoomLeave(roomId: string, room: VoiceRoom, userId: string): vo
} }
} }
function handleVoiceJoin(event: Record<string, unknown>, userId: string): void { function handleVoiceJoin(event: Record<string, unknown>, userId: string, ws: WebSocket): void {
const channelId = event.channelId as string; const channelId = event.channelId as string;
if (!channelId || typeof channelId !== 'string') { if (!channelId || typeof channelId !== 'string') {
@@ -1274,7 +1276,7 @@ function handleMarkUnread(event: Record<string, unknown>, userId: string): void
// ─── DM Call Handlers (Unified Room API) ─────────────────────────────────── // ─── DM Call Handlers (Unified Room API) ───────────────────────────────────
function handleDmCallStart(event: Record<string, unknown>, userId: string, username: string): void { function handleDmCallStart(event: Record<string, unknown>, userId: string, username: string, ws: WebSocket): void {
const dmChannelId = event.dmChannelId as string; const dmChannelId = event.dmChannelId as string;
if (!dmChannelId || typeof dmChannelId !== 'string') { if (!dmChannelId || typeof dmChannelId !== 'string') {
connectionManager.sendToUser(userId, { type: 'error', message: 'dmChannelId is required' }); connectionManager.sendToUser(userId, { type: 'error', message: 'dmChannelId is required' });
@@ -1323,7 +1325,7 @@ function handleDmCallStart(event: Record<string, unknown>, userId: string, usern
}, userId); }, userId);
} }
function handleDmCallAccept(event: Record<string, unknown>, userId: string): void { function handleDmCallAccept(event: Record<string, unknown>, userId: string, ws: WebSocket): void {
const dmChannelId = event.dmChannelId as string; const dmChannelId = event.dmChannelId as string;
if (!dmChannelId || typeof dmChannelId !== 'string') { if (!dmChannelId || typeof dmChannelId !== 'string') {
connectionManager.sendToUser(userId, { type: 'error', message: 'dmChannelId is required' }); connectionManager.sendToUser(userId, { type: 'error', message: 'dmChannelId is required' });
+1 -1
View File
@@ -1311,7 +1311,7 @@ export async function registerWebSocket(app: FastifyInstance): Promise<void> {
// Handle authenticated events // Handle authenticated events
if (userId && username) { if (userId && username) {
try { try {
handleClientEvent(parsed, userId, username); handleClientEvent(parsed, userId, username, ws);
} catch (err) { } catch (err) {
app.log.error({ err, eventType: parsed.type, userId }, 'Unhandled error in WS event handler'); app.log.error({ err, eventType: parsed.type, userId }, 'Unhandled error in WS event handler');
try { try {