From 9076b5bade8dd453b98fc73f0dc0bddaba0fe882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Petruni=C4=87?= Date: Wed, 21 Sep 2022 09:51:38 +0200 Subject: [PATCH] fix: socket close event not working in browser (#183) I simulated that it's not working by attaching a socket to a conn object that I can manually close. Not sure how to trigger the close socket event without hacking (or without calling close on conn) resolves #179 --- src/socket-to-conn.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/socket-to-conn.ts b/src/socket-to-conn.ts index 5ab1d90..c41aeab 100644 --- a/src/socket-to-conn.ts +++ b/src/socket-to-conn.ts @@ -58,14 +58,14 @@ export function socketToMaConn (stream: DuplexWebSocket, remoteAddr: Multiaddr, } } - stream.socket.once != null && stream.socket.once('close', () => { // eslint-disable-line @typescript-eslint/prefer-optional-chain + stream.socket.addEventListener('close', () => { // In instances where `close` was not explicitly called, // such as an iterable stream ending, ensure we have set the close // timeline if (maConn.timeline.close == null) { maConn.timeline.close = Date.now() } - }) + }, { once: true }) return maConn }