22 lines
868 B
TypeScript
22 lines
868 B
TypeScript
/**
|
|
* Server entry point and barrel module for the WebSocket lockstep relay.
|
|
*/
|
|
import { pathToFileURL } from 'node:url'
|
|
import { acceptKey, decodeFrame, decodeFrames, encodeFrame, startRelay, type Relay, type RelayOptions } from '../scripts/net-relay.ts'
|
|
|
|
export { acceptKey, decodeFrame, decodeFrames, encodeFrame, startRelay, type Relay, type RelayOptions }
|
|
|
|
const isMain = process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href
|
|
|
|
if (isMain) {
|
|
const port = Number(process.argv[2] ?? '8787')
|
|
const relay = await startRelay(Number.isFinite(port) && port >= 0 && port <= 65535 ? port : 8787)
|
|
console.log(`relay listening on ${relay.url}`)
|
|
const stop = async (): Promise<void> => {
|
|
await relay.close()
|
|
process.exit(0)
|
|
}
|
|
process.on('SIGINT', () => { void stop() })
|
|
process.on('SIGTERM', () => { void stop() })
|
|
}
|