1
0
mirror of https://github.com/fluencelabs/js-libp2p-websockets synced 2025-04-03 08:41:10 +00:00

33 lines
667 B
JavaScript
Raw Normal View History

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