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

Commit dc9bfa6

Browse files
authoredJun 11, 2020
fix: add error handler for incoming connections (#224)
1 parent 50dd42d commit dc9bfa6

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed
 

‎src/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,19 @@ class WebRTCStar {
145145
}
146146

147147
const done = (err) => {
148-
channel.removeListener('error', onError)
149148
channel.removeListener('timeout', onTimeout)
150149
channel.removeListener('connect', onConnect)
151150
options.signal && options.signal.removeEventListener('abort', onAbort)
152151

153152
err ? reject(err) : resolve(channel)
154153
}
155154

156-
channel.once('error', onError)
155+
channel.on('error', onError)
157156
channel.once('timeout', onTimeout)
158157
channel.once('connect', onConnect)
159-
channel.on('close', () => channel.destroy())
158+
channel.on('close', () => {
159+
channel.removeListener('error', onError)
160+
})
160161
options.signal && options.signal.addEventListener('abort', onAbort)
161162

162163
channel.on('signal', (signal) => {

‎src/listener.js

+9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ module.exports = ({ handler, upgrader }, WebRTCStar, options = {}) => {
5555

5656
const channel = new SimplePeer(spOptions)
5757

58+
const onError = (err) => {
59+
log.error('incoming connectioned errored', err)
60+
}
61+
62+
channel.on('error', onError)
63+
channel.once('close', (...args) => {
64+
channel.removeListener('error', onError)
65+
})
66+
5867
channel.once('signal', (signal) => {
5968
offer.signal = signal
6069
offer.answer = true

‎src/socket-to-conn.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const toWebrtcMultiaddr = (address, port) => {
2323
}
2424

2525
// Convert a socket into a MultiaddrConnection
26-
// https://github.com/libp2p/interface-transport#multiaddrconnection
26+
// https://github.com/libp2p/js-libp2p-interfaces/tree/master/src/transport#multiaddrconnection
2727
module.exports = (socket, options = {}) => {
2828
const { sink, source } = toIterable.duplex(socket)
2929

0 commit comments

Comments
 (0)
This repository has been archived.