mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-16 15:40:49 +00:00
feat: support websockets, even if no listener is added
This commit is contained in:
parent
e10ec13c33
commit
40fdc4147c
12
src/index.js
12
src/index.js
@ -83,13 +83,22 @@ class Node {
|
||||
if (!this.modules.transport) {
|
||||
return callback(new Error('no transports were present'))
|
||||
}
|
||||
|
||||
let ws
|
||||
let transports = this.modules.transport
|
||||
|
||||
transports = Array.isArray(transports) ? transports : [transports]
|
||||
const multiaddrs = this.peerInfo.multiaddrs
|
||||
|
||||
transports.forEach((transport) => {
|
||||
if (transport.filter(multiaddrs).length > 0) {
|
||||
this.swarm.transport.add(
|
||||
transport.tag || transport.constructor.name, transport)
|
||||
} else if (transport.constructor &&
|
||||
transport.constructor.name === 'WebSockets') {
|
||||
// TODO find a cleaner way to signal that a transport is always
|
||||
// used for dialing, even if no listener
|
||||
ws = transport
|
||||
}
|
||||
})
|
||||
|
||||
@ -97,6 +106,9 @@ class Node {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
if (ws) {
|
||||
this.swarm.transport.add(ws.tag || ws.constructor.name, ws)
|
||||
}
|
||||
|
||||
this.isOnline = true
|
||||
callback()
|
||||
|
Loading…
x
Reference in New Issue
Block a user