UNPKG

teletype-client-modified

Version:

I have modified the library developed by Atom to make it compatible with non-browser facility. I am using it only for experimentation purposes. I will remove this package post my experiment and raise a PR at Atom to finally merge this package so that this

52 lines (43 loc) 1.28 kB
const PeerPool = require('../../lib/peer-pool') const RestGateway = require('../../lib/rest-gateway') let testEpoch = 0 const peerPools = [] exports.buildPeerPool = async function buildPeerPool (peerId, server, options = {}) { const oauthToken = peerId + '-token' const peerPool = new PeerPool({ peerId, peerIdentity: await server.identityProvider.identityForToken(oauthToken), restGateway: new RestGateway({baseURL: server.address, oauthToken}), pubSubGateway: server.pubSubGateway, connectionTimeout: options.connectionTimeout, testEpoch }) await peerPool.initialize() if (options.listen !== false) await peerPool.listen() peerPool.testDisconnectionEvents = [] peerPool.onDisconnection(({peerId}) => { peerPool.testDisconnectionEvents.push(peerId) }) peerPool.testInbox = [] peerPool.onReceive(({senderId, message}) => { peerPool.testInbox.push({ senderId, message: message.toString() }) }) peerPool.testErrors = [] peerPool.onError((error) => { peerPool.testErrors.push(error) }) peerPools.push(peerPool) return peerPool } exports.clearPeerPools = function clearPeerPools () { for (const peerPool of peerPools) { peerPool.dispose() } peerPools.length = 0 testEpoch++ }