Files
mumh5/server/main.ts
kibiandClaude Opus 5.5 08aa5268d0 Add a stream relay (TURN) to the proxy for browsers that cannot connect directly
Vanadium forbids direct UDP for WebRTC, and mobile and company networks often
block direct connections; the only route then is a relay reached over TCP.

- server/turn.ts: STUN and TURN on one port, over UDP and TCP, with
  short-lived credentials from /api/turn, quotas and a peer filter
- The browser build fetches credentials and offers the relay automatically
- Stats for nerds says when a stream is relayed and how the relay is reached
- Tests: a TURN client over UDP and TCP, and a browser limited to the relay
  over TCP in the web E2E

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 23:30:09 +02:00

23 lines
1.6 KiB
TypeScript

// Starts the web proxy from environment variables (see the README, "Browser version").
import path from 'node:path';
import { existsSync } from 'node:fs';
import { configFromEnv, startProxy } from './proxy.ts';
const config = configFromEnv(process.env);
// The web build sits next to this script's folder, both in the repository and when bundled
config.staticDir ??= [path.resolve(import.meta.dirname, '../dist-web')].find(d => existsSync(path.join(d, 'index.html'))) ?? null;
try {
const { port, stunPort } = await startProxy(config);
console.log(`mumh5 proxy listening on http://${config.bind}:${port}`);
console.log(config.allowAny ? `Allowed servers: any${config.allowPrivate ? ', private addresses included' : ' public address'}` : `Allowed servers: ${config.servers.map(s => `${s.host}:${s.port}`).join(', ')}`);
if (config.sendProxy) console.log('Announcing client addresses with the PROXY protocol; the allowed servers must expect it');
console.log(!stunPort ? 'STUN is off; screen sharing between browser users will only work on the same network'
: config.turn ? `Screen sharing: STUN and relay on port ${stunPort} (UDP and TCP), relayed streams on UDP ${config.turnMinPort}-${config.turnMaxPort}; all must be reachable from the internet`
: `Screen sharing: STUN on UDP port ${stunPort} (must be reachable from the internet), no relay`);
console.log(config.staticDir ? `Serving the web app from ${config.staticDir}` : 'No web build found (npm run build:web); serving the API only');
} catch (e) {
console.error((e as Error).message);
process.exit(1);
}