aboutsummaryrefslogtreecommitdiffstats
path: root/gateway/src/index.js
blob: 28beec509d160be99b54f9b933d1fd5f27747165 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { loadConfig } from "./config.js";
import { createGatewayServer } from "./server.js";
import { opusBackendName } from "./opus.js";

const config = loadConfig();
const log = console;

const { server, shutdown, voiceAvailable } = createGatewayServer(config, log);

server.listen(config.web.port, config.web.host, () => {
  log.info(`[gateway] listening on http://${config.web.host}:${config.web.port} -> dashboard 127.0.0.1:${config.web.dashboardPort}`);
  if (voiceAvailable()) {
    log.info(`[gateway] web voice enabled for ${config.server.host}:${config.server.voicePort} (opus: ${opusBackendName()})`);
  } else if (!config.server.password) {
    log.warn("[gateway] web voice disabled: set TS_SERVER_PASSWORD in .env (visitors must know it to join)");
  } else if (!config.server.host) {
    log.warn("[gateway] web voice disabled: set TS_HOST");
  } else {
    log.warn("[gateway] web voice disabled in config.toml ([voice] enabled = false)");
  }
});

server.on("error", (error) => {
  log.error(`[gateway] ${error.message}`);
  process.exit(1);
});

let stopping = false;
async function stop(signal) {
  if (stopping) return;
  stopping = true;
  log.info(`[gateway] ${signal} received, disconnecting voice sessions`);
  const force = setTimeout(() => process.exit(0), 3000);
  force.unref();
  await shutdown();
  process.exit(0);
}
process.on("SIGINT", () => void stop("SIGINT"));
process.on("SIGTERM", () => void stop("SIGTERM"));
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage