23 lines
733 B
TypeScript
23 lines
733 B
TypeScript
/**
|
|
* Run the co-op relay.
|
|
*
|
|
* This is the whole of "the server": it forwards bytes between the connected
|
|
* peers and knows nothing about the game. Everything that decides who wins a
|
|
* fight happens in the two browsers.
|
|
*
|
|
* Usage: node scripts/net-server.ts [port]
|
|
*/
|
|
import { startRelay } from './net-relay.ts'
|
|
|
|
const port = Number(process.argv[2] ?? '8787')
|
|
const relay = await startRelay(Number.isFinite(port) ? port : 8787)
|
|
console.log(`relay listening on ${relay.url}`)
|
|
console.log('open two pages with ?ws=' + relay.url + '&peer=0 and &peer=1')
|
|
|
|
const stop = async (): Promise<void> => {
|
|
await relay.close()
|
|
process.exit(0)
|
|
}
|
|
process.on('SIGINT', () => { void stop() })
|
|
process.on('SIGTERM', () => { void stop() })
|