2017-10-20 04:12:35 -07:00
|
|
|
'use strict'
|
|
|
|
|
2017-10-20 11:25:14 +01:00
|
|
|
const multiaddr = require('multiaddr')
|
2019-09-30 12:14:28 +02:00
|
|
|
const pipe = require('it-pipe')
|
2017-10-20 11:25:14 +01:00
|
|
|
const WS = require('./src')
|
|
|
|
|
2019-09-30 12:14:28 +02:00
|
|
|
const mockUpgrader = {
|
|
|
|
upgradeInbound: maConn => maConn,
|
|
|
|
upgradeOutbound: maConn => maConn
|
|
|
|
}
|
2017-10-20 11:25:14 +01:00
|
|
|
let listener
|
|
|
|
|
2017-10-20 04:12:35 -07:00
|
|
|
function boot (done) {
|
2019-09-30 12:14:28 +02:00
|
|
|
const ws = new WS({ upgrader: mockUpgrader })
|
2017-10-20 04:12:35 -07:00
|
|
|
const ma = multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
|
2019-09-30 12:14:28 +02:00
|
|
|
listener = ws.createListener(conn => pipe(conn, conn))
|
|
|
|
listener.listen(ma).then(() => done()).catch(done)
|
|
|
|
listener.on('error', console.error)
|
2017-10-20 04:12:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function shutdown (done) {
|
2019-09-30 12:14:28 +02:00
|
|
|
listener.close().then(done).catch(done)
|
2017-10-20 04:12:35 -07:00
|
|
|
}
|
|
|
|
|
2017-10-20 11:25:14 +01:00
|
|
|
module.exports = {
|
|
|
|
hooks: {
|
|
|
|
browser: {
|
2017-10-20 04:12:35 -07:00
|
|
|
pre: boot,
|
|
|
|
post: shutdown
|
2017-10-20 11:25:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|