Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async joinP2PLobby(hash: string): Promise {
ga('event', { ec: 'session', ea: 'connect', el: 'p2p' })
const coordinator = new WebRTCPeerCoordinator({ host: false, hostId: hash })
this.server = new NetServer({
isHost: false,
coordinators: [coordinator]
})
const promises = [
waitEvent(this.server, 'connect', NETWORK_TIMEOUT),
waitEvent(this.server, 'error', NETWORK_TIMEOUT)
]
try {
const [result] = await Promise.race(promises)
if (result instanceof Error) throw result
} catch (e) {
promises.forEach(p => p.cancel())
if (this.server) {
this.server.close()
async createLobby(opts: ILobbyOptions): Promise {
const coordinators: PeerCoordinator[] = []
if (opts.p2p) {
coordinators.push(new WebRTCPeerCoordinator({ host: true }))
}
this.server = new NetServer({ isHost: true, coordinators })
}