forked from libp2p/js-libp2p-webrtc-direct
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.aegir.cjs
66 lines (55 loc) · 1.56 KB
/
.aegir.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict'
const wrtc = require('wrtc')
// TODO: Temporary fix per wrtc issue
// https://github.com/node-webrtc/node-webrtc/issues/636#issuecomment-774171409
process.on('beforeExit', (code) => process.exit(code))
const ECHO_PROTOCOL = '/echo/1.0.0'
async function before () {
const { webRTCDirect, WebRTCDirectNodeType } = await import('./dist/src/index.js')
const { pipe } = await import('it-pipe')
const { mockUpgrader, mockRegistrar } = await import('@libp2p/interface-mocks')
const { peerIdFromString } = await import('@libp2p/peer-id')
const { REMOTE_MULTIADDR_IP4, REMOTE_MULTIADDR_IP6 } = await import('./dist/test/constants.js')
const registrar = mockRegistrar()
void registrar.handle(ECHO_PROTOCOL, ({ stream }) => {
void pipe(
stream,
stream
).catch()
})
const upgrader = mockUpgrader({
registrar
})
const peerId = peerIdFromString('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2a')
const wd = webRTCDirect({
wrtc,
enableSignalling: true,
nodeType: WebRTCDirectNodeType.Relay
})({
peerId: peerId
})
const listeners = await Promise.all(
[REMOTE_MULTIADDR_IP4, REMOTE_MULTIADDR_IP6].map(async ma => {
const listener = wd.createListener({
upgrader
})
await listener.listen(ma)
return listener
})
)
return {
listeners
}
}
async function after (testOptions, beforeReturn) {
await Promise.all(
beforeReturn.listeners.map(listener => listener.close())
)
}
/** @type {import('aegir').PartialOptions} */
module.exports = {
test: {
before,
after
}
}