Integrate LiveKit SFU and harden booking workflow

This commit is contained in:
2026-09-16 19:38:28 +02:00
parent f1cd07b3ad
commit d0864e2911
55 changed files with 1648 additions and 1234 deletions
+7 -25
View File
@@ -1,25 +1,17 @@
/**
* Custom Next.js server so we can attach a plain WebSocket server for WebRTC
* signaling (offer/answer/ICE relay) alongside the normal Next.js request
* handler. Standalone output mode can't be combined with a custom server
* (see next.config.ts), so this project deploys by running this file
* directly (`npm run start` / `npm run dev`) instead of `next start`.
*
* The WS server never touches audio/video/screen-share media — it only
* relays small JSON signaling messages between participants of the same
* meeting room (see lib/meeting/signalingServer.ts).
* Custom Next.js server. Standalone output mode can't be combined with a
* custom server (see next.config.ts), so production runs this file directly.
* LiveKit handles signaling and media separately; this process only serves
* the website and its API.
*/
import { createServer } from "node:http";
import next from "next";
import { WebSocketServer } from "ws";
import { attachSignalingServer } from "./lib/meeting/signalingServer";
const port = parseInt(process.env.PORT || "3000", 10);
const hostname = process.env.HOSTNAME || "0.0.0.0";
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev, hostname, port });
const SIGNALING_PATH = "/ws/signaling";
app.prepare().then(() => {
// Must be requested after prepare() resolves.
@@ -30,24 +22,14 @@ app.prepare().then(() => {
handle(req, res);
});
const wss = new WebSocketServer({ noServer: true });
attachSignalingServer(wss);
server.on("upgrade", (req, socket, head) => {
const url = req.url ?? "";
if (url.startsWith(SIGNALING_PATH)) {
wss.handleUpgrade(req, socket, head, (ws) => {
wss.emit("connection", ws, req);
});
} else {
// Let Next.js handle its own upgrade requests (e.g. dev-mode HMR).
upgradeHandle(req, socket, head);
}
// Let Next.js handle its own upgrade requests (e.g. dev-mode HMR).
upgradeHandle(req, socket, head);
});
server.listen(port, () => {
console.log(
`> ANOUMA server listening at http://${hostname}:${port} (${dev ? "development" : "production"}), signaling on ${SIGNALING_PATH}`,
`> ANOUMA server listening at http://${hostname}:${port} (${dev ? "development" : "production"})`,
);
});
});