fix: use connection.socket for @fastify/websocket v8
This commit is contained in:
parent
af0e6526d6
commit
215d24eb0e
1 changed files with 5 additions and 2 deletions
|
|
@ -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<string, any> = 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}`);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue