From cb16588f466a0e3ce7ae2a44932f25ebbccc08b5 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 27 Oct 2021 18:34:51 +0200 Subject: [PATCH] refactor: use `EventEmitter.once` where appropriate --- src/use/fastify-websocket.ts | 4 ++-- src/use/ws.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/use/fastify-websocket.ts b/src/use/fastify-websocket.ts index e3fcd990..d028bd95 100644 --- a/src/use/fastify-websocket.ts +++ b/src/use/fastify-websocket.ts @@ -67,8 +67,8 @@ export function makeHandler< // fastify-websocket uses the WebSocket.createWebSocketStream, // therefore errors get emitted on both the connection and the socket - connection.on('error', handleEmittedError); - socket.on('error', handleEmittedError); + connection.once('error', handleEmittedError); + socket.once('error', handleEmittedError); // keep alive through ping-pong messages let pongWait: NodeJS.Timeout | null = null; diff --git a/src/use/ws.ts b/src/use/ws.ts index e41a11fb..37e521bb 100644 --- a/src/use/ws.ts +++ b/src/use/ws.ts @@ -51,7 +51,7 @@ export function useServer< const isProd = process.env.NODE_ENV === 'production'; const server = makeServer(options); - ws.on('error', (err) => { + ws.once('error', (err) => { console.error( 'Internal error emitted on the WebSocket server. ' + 'Please check your implementation.', @@ -80,7 +80,7 @@ export function useServer< }); ws.on('connection', (socket, request) => { - socket.on('error', (err) => { + socket.once('error', (err) => { console.error( 'Internal error emitted on a WebSocket socket. ' + 'Please check your implementation.',