2026-03-17 12:38:30 +01:00
|
|
|
const { WebSocketServer } = require("ws");
|
2026-03-07 09:51:37 +01:00
|
|
|
|
2026-03-17 12:38:30 +01:00
|
|
|
//currently unused
|
2026-03-07 09:51:37 +01:00
|
|
|
function setupWebSocket(server) {
|
2026-03-17 12:38:30 +01:00
|
|
|
const wss = new WebSocketServer({ server, path: "/ws" });
|
2026-03-07 09:51:37 +01:00
|
|
|
|
2026-03-17 12:38:30 +01:00
|
|
|
wss.on("connection", (ws) => {
|
|
|
|
|
console.log("[ws] Client connected");
|
2026-03-07 09:51:37 +01:00
|
|
|
|
2026-03-17 12:38:30 +01:00
|
|
|
ws.on("message", (data) => {
|
2026-03-07 09:51:37 +01:00
|
|
|
// TODO: handle watch/unwatch subscriptions from client
|
|
|
|
|
const msg = JSON.parse(data);
|
2026-03-17 12:38:30 +01:00
|
|
|
console.log("[ws] Received:", msg);
|
2026-03-07 09:51:37 +01:00
|
|
|
});
|
|
|
|
|
|
2026-03-17 12:38:30 +01:00
|
|
|
ws.on("close", () => {
|
|
|
|
|
console.log("[ws] Client disconnected");
|
2026-03-07 09:51:37 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-17 12:38:30 +01:00
|
|
|
// TODO: maybe integrate chokidar file watching and broadcast changes
|
2026-03-07 09:51:37 +01:00
|
|
|
|
|
|
|
|
return wss;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = { setupWebSocket };
|