4
4
const multiaddr = require ( 'multiaddr' )
5
5
const CID = require ( 'cids' )
6
6
const delay = require ( 'delay' )
7
- const { isNode , isBrowser, isElectron } = require ( 'ipfs-utils/src/env' )
7
+ const { isBrowser, isWebWorker } = require ( 'ipfs-utils/src/env' )
8
8
const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
9
9
10
10
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
@@ -24,7 +24,7 @@ module.exports = (common, options) => {
24
24
25
25
before ( async ( ) => {
26
26
ipfsA = ( await common . spawn ( ) ) . api
27
- ipfsB = ( await common . spawn ( ) ) . api
27
+ ipfsB = ( await common . spawn ( { type : isWebWorker ? 'go' : undefined } ) ) . api
28
28
await ipfsA . swarm . connect ( ipfsB . peerId . addresses [ 0 ] )
29
29
/* TODO: Seen if we still need this after this is fixed
30
30
https://github.com/ipfs/js-ipfs/issues/2601 gets resolved */
@@ -88,7 +88,7 @@ module.exports = (common, options) => {
88
88
89
89
it ( 'should list peers only once' , async ( ) => {
90
90
const nodeA = ( await common . spawn ( ) ) . api
91
- const nodeB = ( await common . spawn ( ) ) . api
91
+ const nodeB = ( await common . spawn ( { type : isWebWorker ? 'go' : undefined } ) ) . api
92
92
await nodeA . swarm . connect ( nodeB . peerId . addresses [ 0 ] )
93
93
await delay ( 1000 )
94
94
const peersA = await nodeA . swarm . peers ( )
@@ -99,22 +99,40 @@ module.exports = (common, options) => {
99
99
100
100
it ( 'should list peers only once even if they have multiple addresses' , async ( ) => {
101
101
// TODO: Change to port 0, needs: https://github.com/ipfs/interface-ipfs-core/issues/152
102
- const configA = getConfig ( isNode || isElectron || ( common . opts && common . opts . type === 'go' ) ? [
103
- '/ip4/127.0.0.1/tcp/16543' ,
104
- '/ip4/127.0.0.1/tcp/16544'
105
- ] : [
102
+ let addresses
103
+
104
+ if ( isBrowser ) {
105
+ addresses = [
106
+ '/ip4/127.0.0.1/tcp/14578/ws/p2p-webrtc-star' ,
107
+ '/ip4/127.0.0.1/tcp/14579/ws/p2p-webrtc-star'
108
+ ]
109
+ } else if ( isWebWorker ) {
110
+ // webworkers are not dialable (no webrtc available) until stardust is async/await
111
+ // https://github.com/libp2p/js-libp2p-stardust/pull/14
112
+ addresses = [ ]
113
+ } else {
114
+ addresses = [
115
+ '/ip4/127.0.0.1/tcp/26543/ws' ,
116
+ '/ip4/127.0.0.1/tcp/26544/ws'
117
+ ]
118
+ }
119
+
120
+ const configA = getConfig ( addresses )
121
+ const configB = getConfig ( isBrowser ? [
106
122
'/ip4/127.0.0.1/tcp/14578/ws/p2p-webrtc-star' ,
107
123
'/ip4/127.0.0.1/tcp/14579/ws/p2p-webrtc-star'
108
- ] )
109
- const configB = getConfig ( isNode || isElectron || ( common . opts && common . opts . type === 'go' ) ? [
124
+ ] : [
110
125
'/ip4/127.0.0.1/tcp/26545/ws' ,
111
126
'/ip4/127.0.0.1/tcp/26546/ws'
112
- ] : [
113
- '/ip4/127.0.0.1/tcp/14578/ws/p2p-webrtc-star' ,
114
- '/ip4/127.0.0.1/tcp/14579/ws/p2p-webrtc-star'
115
127
] )
128
+
116
129
const nodeA = ( await common . spawn ( { ipfsOptions : { config : configA } } ) ) . api
117
- const nodeB = ( await common . spawn ( { ipfsOptions : { config : configB } } ) ) . api
130
+ const nodeB = ( await common . spawn ( {
131
+ type : isWebWorker ? 'go' : undefined ,
132
+ ipfsOptions : {
133
+ config : configB
134
+ }
135
+ } ) ) . api
118
136
119
137
// TODO: the webrtc-star transport only keeps the last listened on address around
120
138
// so the browser has to use 1 as the array index
0 commit comments