Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 9076b5b

Browse files
authored
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
1 parent 64411ee commit 9076b5b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/socket-to-conn.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ export function socketToMaConn (stream: DuplexWebSocket, remoteAddr: Multiaddr,
5858
}
5959
}
6060

61-
stream.socket.once != null && stream.socket.once('close', () => { // eslint-disable-line @typescript-eslint/prefer-optional-chain
61+
stream.socket.addEventListener('close', () => {
6262
// In instances where `close` was not explicitly called,
6363
// such as an iterable stream ending, ensure we have set the close
6464
// timeline
6565
if (maConn.timeline.close == null) {
6666
maConn.timeline.close = Date.now()
6767
}
68-
})
68+
}, { once: true })
6969

7070
return maConn
7171
}

0 commit comments

Comments
 (0)