1
0
mirror of https://github.com/fluencelabs/js-libp2p synced 2025-03-18 00:20:51 +00:00
Jacob Heun ff7a6c86a0
fix: promisified methods ()
* chore: update ws rendezvous dep

test(fix): fix tests with latest ws rendezvous server

* fix: promisification of libp2p methods

test: add tests to verify promisify support until async/await endeavor is complete

* chore: fix linting
2019-08-06 10:53:23 +02:00

42 lines
1.3 KiB
JavaScript

'use strict'
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const nextTick = require('async/nextTick')
const peerJSON = require('../fixtures/test-peer')
const multiaddr = require('multiaddr')
const promisify = require('promisify-es6')
let peerRelay = null
/**
* Creates a `PeerInfo` that can be used across testing. Once the
* relay `PeerInfo` has been requested, it will be reused for each
* additional request.
*
* This is currently being used to create a relay on test bootstrapping
* so that it can be used by browser nodes during their test suite. This
* is necessary for running a TCP node during browser tests.
* @private
* @param {function(error, PeerInfo)} callback
* @returns {void}
*/
module.exports.getPeerRelay = promisify((callback) => {
if (peerRelay) return nextTick(callback, null, peerRelay)
PeerId.createFromJSON(peerJSON, (err, peerId) => {
if (err) {
return callback(err)
}
peerRelay = new PeerInfo(peerId)
peerRelay.multiaddrs.add('/ip4/127.0.0.1/tcp/9200/ws')
peerRelay.multiaddrs.add('/ip4/127.0.0.1/tcp/9245')
callback(null, peerRelay)
})
})
module.exports.WS_RENDEZVOUS_MULTIADDR = multiaddr('/ip4/127.0.0.1/tcp/14444/ws')
module.exports.WRTC_RENDEZVOUS_MULTIADDR = multiaddr('/ip4/127.0.0.1/tcp/15555/ws')