How to use the network.NetServer function in network

To help you get started, we’ve selected a few network examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github samuelmaddock / metastream / packages / metastream-app / src / platform / web / index.ts View on Github external
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()
github samuelmaddock / metastream / packages / metastream-app / src / platform / web / index.ts View on Github external
async createLobby(opts: ILobbyOptions): Promise {
    const coordinators: PeerCoordinator[] = []

    if (opts.p2p) {
      coordinators.push(new WebRTCPeerCoordinator({ host: true }))
    }

    this.server = new NetServer({ isHost: true, coordinators })
  }