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

Commit

Permalink
fix: socket close event not working in browser (#183)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mpetrunic authored Sep 21, 2022
1 parent 64411ee commit 9076b5b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/socket-to-conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 9076b5b

Please sign in to comment.