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

Commit 05dde5b

Browse files
committed
feat: use new webrtc-star, remove support it by default, support it to be pluggable
1 parent 822fb6e commit 05dde5b

File tree

3 files changed

+55
-33
lines changed

3 files changed

+55
-33
lines changed

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
"homepage": "https://github.com/ipfs/js-libp2p-ipfs-nodejs#readme",
3939
"devDependencies": {
4040
"aegir": "^11.0.2",
41-
"async": "^2.4.0",
42-
"chai": "^3.5.0",
41+
"async": "^2.5.0",
42+
"chai": "^4.0.2",
4343
"cids": "^0.5.0",
44-
"dirty-chai": "^1.2.2",
44+
"dirty-chai": "^2.0.0",
45+
"electron-webrtc": "^0.3.0",
4546
"lodash.times": "^4.3.2",
4647
"pre-commit": "^1.2.2",
4748
"pull-stream": "^3.6.0"
@@ -51,12 +52,12 @@
5152
"libp2p-kad-dht": "~0.1.0",
5253
"libp2p-mdns": "~0.7.0",
5354
"libp2p-multiplex": "~0.4.3",
54-
"libp2p-railing": "~0.5.0",
55+
"libp2p-railing": "~0.5.1",
5556
"libp2p-secio": "~0.6.8",
5657
"libp2p-spdy": "~0.10.6",
5758
"libp2p-swarm": "~0.29.1",
5859
"libp2p-tcp": "~0.10.1",
59-
"libp2p-webrtc-star": "~0.10.0",
60+
"libp2p-webrtc-star": "~0.11.0",
6061
"libp2p-websockets": "~0.10.0",
6162
"mafmt": "^2.1.8",
6263
"multiaddr": "^2.3.0",
@@ -76,4 +77,4 @@
7677
"kumavis <[email protected]>",
7778
"varunagarwal315 <[email protected]>"
7879
]
79-
}
80+
}

src/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict'
22

33
const TCP = require('libp2p-tcp')
4-
// const UTP = require('libp2p-utp')
5-
const WebRTCStar = require('libp2p-webrtc-star')
64
const MulticastDNS = require('libp2p-mdns')
75
const WS = require('libp2p-websockets')
86
const Railing = require('libp2p-railing')
@@ -40,13 +38,11 @@ function getMuxers (muxers) {
4038
class Node extends libp2p {
4139
constructor (peerInfo, peerBook, options) {
4240
options = options || {}
43-
const webRTCStar = new WebRTCStar()
4441

4542
const modules = {
4643
transport: [
4744
new TCP(),
48-
new WS(),
49-
webRTCStar
45+
new WS()
5046
],
5147
connection: {
5248
muxer: getMuxers(options.muxer),
@@ -55,10 +51,6 @@ class Node extends libp2p {
5551
discovery: []
5652
}
5753

58-
if (options.webRTCStar) {
59-
modules.discovery.push(webRTCStar.discovery)
60-
}
61-
6254
if (options.dht) {
6355
modules.DHT = KadDHT
6456
}
@@ -73,6 +65,14 @@ class Node extends libp2p {
7365
modules.discovery.push(r)
7466
}
7567

68+
if (options.modules && options.modules.transport) {
69+
options.modules.transport.forEach((t) => modules.transport.push(t))
70+
}
71+
72+
if (options.modules && options.modules.discovery) {
73+
options.modules.discovery.forEach((d) => modules.discovery.push(d))
74+
}
75+
7676
super(modules, peerInfo, peerBook, options)
7777
}
7878
}

test/tcp+websockets+webrtc-star.spec.js

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ chai.use(require('dirty-chai'))
66
const expect = chai.expect
77
const parallel = require('async/parallel')
88
const signalling = require('libp2p-webrtc-star/src/sig-server')
9+
const WStar = require('libp2p-webrtc-star')
10+
const electronWebRTC = require('electron-webrtc')
911
const utils = require('./utils')
1012
const createNode = utils.createNode
1113
const echo = utils.echo
@@ -27,16 +29,25 @@ describe('TCP + WebSockets + WebRTCStar', () => {
2729
cb()
2830
})
2931
},
30-
(cb) => createNode([
31-
'/ip4/0.0.0.0/tcp/0',
32-
'/ip4/127.0.0.1/tcp/25011/ws',
33-
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws'
34-
], (err, node) => {
35-
expect(err).to.not.exist()
36-
nodeAll = node
37-
node.handle('/echo/1.0.0', echo)
38-
node.start(cb)
39-
}),
32+
(cb) => {
33+
const wstar = new WStar({wrtc: electronWebRTC()})
34+
35+
createNode([
36+
'/ip4/0.0.0.0/tcp/0',
37+
'/ip4/127.0.0.1/tcp/25011/ws',
38+
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws'
39+
], {
40+
modules: {
41+
transport: [wstar],
42+
discovery: [wstar.discovery]
43+
}
44+
}, (err, node) => {
45+
expect(err).to.not.exist()
46+
nodeAll = node
47+
node.handle('/echo/1.0.0', echo)
48+
node.start(cb)
49+
})
50+
},
4051
(cb) => createNode([
4152
'/ip4/0.0.0.0/tcp/0'
4253
], (err, node) => {
@@ -53,14 +64,24 @@ describe('TCP + WebSockets + WebRTCStar', () => {
5364
node.handle('/echo/1.0.0', echo)
5465
node.start(cb)
5566
}),
56-
(cb) => createNode([
57-
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws'
58-
], (err, node) => {
59-
expect(err).to.not.exist()
60-
nodeWStar = node
61-
node.handle('/echo/1.0.0', echo)
62-
node.start(cb)
63-
})
67+
68+
(cb) => {
69+
const wstar = new WStar({wrtc: electronWebRTC()})
70+
71+
createNode([
72+
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws'
73+
], {
74+
modules: {
75+
transport: [wstar],
76+
discovery: [wstar.discovery]
77+
}
78+
}, (err, node) => {
79+
expect(err).to.not.exist()
80+
nodeWStar = node
81+
node.handle('/echo/1.0.0', echo)
82+
node.start(cb)
83+
})
84+
}
6485
], done)
6586
})
6687

0 commit comments

Comments
 (0)