mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-20 20:46:31 +00:00
feat: Bring libp2p-websocket-star to the Transports family! 🌟 (#122)
* test: add libp2p-websocket-star tests * refactor: websocket-star-{signal => rendezvous} * misc: Apply requested changes * chore: update deps * refactor: considerable amount of refactor, clean up test structure * use right flag * test: refactor transport tests
This commit is contained in:
committed by
David Dias
parent
38a68a01b7
commit
95f029eb7a
74
test/utils/bundle.browser.js
Normal file
74
test/utils/bundle.browser.js
Normal file
@ -0,0 +1,74 @@
|
||||
'use strict'
|
||||
|
||||
const WS = require('libp2p-websockets')
|
||||
const WebRTCStar = require('libp2p-webrtc-star')
|
||||
const WebSocketStar = require('libp2p-websocket-star')
|
||||
const spdy = require('libp2p-spdy')
|
||||
const multiplex = require('libp2p-multiplex')
|
||||
const secio = require('libp2p-secio')
|
||||
const Railing = require('libp2p-railing')
|
||||
const libp2p = require('../..')
|
||||
|
||||
function mapMuxers (list) {
|
||||
return list.map((pref) => {
|
||||
if (typeof pref !== 'string') {
|
||||
return pref
|
||||
}
|
||||
switch (pref.trim().toLowerCase()) {
|
||||
case 'spdy':
|
||||
return spdy
|
||||
case 'multiplex':
|
||||
return multiplex
|
||||
default:
|
||||
throw new Error(pref + ' muxer not available')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getMuxers (options) {
|
||||
if (options) {
|
||||
return mapMuxers(options)
|
||||
} else {
|
||||
return [multiplex, spdy]
|
||||
}
|
||||
}
|
||||
|
||||
class Node extends libp2p {
|
||||
constructor (peerInfo, peerBook, options) {
|
||||
options = options || {}
|
||||
const webRTCStar = new WebRTCStar()
|
||||
const wsStar = new WebSocketStar()
|
||||
|
||||
const modules = {
|
||||
transport: [
|
||||
new WS(),
|
||||
webRTCStar,
|
||||
wsStar
|
||||
],
|
||||
connection: {
|
||||
muxer: getMuxers(options.muxer),
|
||||
crypto: [
|
||||
secio
|
||||
]
|
||||
},
|
||||
discovery: []
|
||||
}
|
||||
|
||||
if (options.webRTCStar) {
|
||||
modules.discovery.push(webRTCStar.discovery)
|
||||
}
|
||||
|
||||
if (options.wsStar) {
|
||||
modules.discovery.push(wsStar.discovery)
|
||||
}
|
||||
|
||||
if (options.bootstrap) {
|
||||
const r = new Railing(options.bootstrap)
|
||||
modules.discovery.push(r)
|
||||
}
|
||||
|
||||
super(modules, peerInfo, peerBook, options)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Node
|
Reference in New Issue
Block a user