44const multiaddr = require ( 'multiaddr' )
55const CID = require ( 'cids' )
66const delay = require ( 'delay' )
7- const { isNode , isBrowser, isElectron } = require ( 'ipfs-utils/src/env' )
7+ const { isBrowser, isWebWorker } = require ( 'ipfs-utils/src/env' )
88const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
99
1010/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
@@ -24,7 +24,7 @@ module.exports = (common, options) => {
2424
2525 before ( async ( ) => {
2626 ipfsA = ( await common . spawn ( ) ) . api
27- ipfsB = ( await common . spawn ( ) ) . api
27+ ipfsB = ( await common . spawn ( { type : isWebWorker ? 'go' : undefined } ) ) . api
2828 await ipfsA . swarm . connect ( ipfsB . peerId . addresses [ 0 ] )
2929 /* TODO: Seen if we still need this after this is fixed
3030 https://github.com/ipfs/js-ipfs/issues/2601 gets resolved */
@@ -88,7 +88,7 @@ module.exports = (common, options) => {
8888
8989 it ( 'should list peers only once' , async ( ) => {
9090 const nodeA = ( await common . spawn ( ) ) . api
91- const nodeB = ( await common . spawn ( ) ) . api
91+ const nodeB = ( await common . spawn ( { type : isWebWorker ? 'go' : undefined } ) ) . api
9292 await nodeA . swarm . connect ( nodeB . peerId . addresses [ 0 ] )
9393 await delay ( 1000 )
9494 const peersA = await nodeA . swarm . peers ( )
@@ -99,22 +99,40 @@ module.exports = (common, options) => {
9999
100100 it ( 'should list peers only once even if they have multiple addresses' , async ( ) => {
101101 // 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 ? [
106122 '/ip4/127.0.0.1/tcp/14578/ws/p2p-webrtc-star' ,
107123 '/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+ ] : [
110125 '/ip4/127.0.0.1/tcp/26545/ws' ,
111126 '/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'
115127 ] )
128+
116129 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
118136
119137 // TODO: the webrtc-star transport only keeps the last listened on address around
120138 // so the browser has to use 1 as the array index
0 commit comments