fix: use connection.socket for @fastify/websocket v8
Some checks are pending
Test / backend-test (push) Waiting to run
Test / frontend-test (push) Waiting to run

This commit is contained in:
fullsizemalt 2026-01-05 20:44:06 -08:00
parent af0e6526d6
commit 215d24eb0e

View file

@ -13,7 +13,7 @@ interface AlertMessage {
timestamp: string; timestamp: string;
} }
// Connected clients (using any to avoid ws type issues) // Connected clients (storing the raw WebSocket)
const clients: Map<string, any> = new Map(); const clients: Map<string, any> = new Map();
export async function websocketPlugin(fastify: FastifyInstance) { export async function websocketPlugin(fastify: FastifyInstance) {
@ -22,9 +22,12 @@ export async function websocketPlugin(fastify: FastifyInstance) {
/** /**
* WebSocket endpoint for real-time alerts * 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)}`; 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); clients.set(clientId, socket);
fastify.log.info(`WebSocket client connected: ${clientId}`); fastify.log.info(`WebSocket client connected: ${clientId}`);