diff --git a/backend/src/plugins/websocket.ts b/backend/src/plugins/websocket.ts index ed89102..8a13ebb 100644 --- a/backend/src/plugins/websocket.ts +++ b/backend/src/plugins/websocket.ts @@ -13,7 +13,7 @@ interface AlertMessage { timestamp: string; } -// Connected clients (using any to avoid ws type issues) +// Connected clients (storing the raw WebSocket) const clients: Map = new Map(); export async function websocketPlugin(fastify: FastifyInstance) { @@ -22,9 +22,12 @@ export async function websocketPlugin(fastify: FastifyInstance) { /** * WebSocket endpoint for real-time alerts */ - fastify.get('/ws/alerts', { websocket: true }, (socket, request) => { + fastify.get('/ws/alerts', { websocket: true }, (connection, request) => { const clientId = `${Date.now()}-${Math.random().toString(36).slice(2)}`; + // Get the raw WebSocket from the SocketStream + const socket = connection.socket; + clients.set(clientId, socket); fastify.log.info(`WebSocket client connected: ${clientId}`);