feat: relay engine feedback to web clients
Add a second osc.UDPPort bound to FEEDBACK_PORT_IN (default
9000, matches ~toscPort in SC) that receives engine feedback
OSC (/armed/*, /sync/beat, /sync/rms, /seq/*/state) from SC
and relays each message to all WS clients using the existing
{address,args} JSON shape. Does not update the snapshot cache
(feedback is transient). Existing data port, control-send
path, and WS logic are untouched.
node --check: SYNTAX OK.
This commit is contained in:
+27
-4
@@ -14,8 +14,9 @@
|
||||
// real.art.saillant.cc
|
||||
//
|
||||
// Variables d'environnement :
|
||||
// HTTP_PORT (defaut 4400)
|
||||
// DATA_PORT_IN (defaut 57124, ce que bridge.py envoie ici)
|
||||
// HTTP_PORT (defaut 4400)
|
||||
// DATA_PORT_IN (defaut 57124, ce que bridge.py envoie ici)
|
||||
// FEEDBACK_PORT_IN (defaut 9000, feedback SC engine -> navigateurs)
|
||||
// =====================================================================
|
||||
import express from "express";
|
||||
import { fileURLToPath } from "node:url";
|
||||
@@ -28,8 +29,9 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const HTTP_PORT = parseInt(process.env.HTTP_PORT ?? "4400", 10);
|
||||
const DATA_PORT_IN = parseInt(process.env.DATA_PORT_IN ?? "57124", 10);
|
||||
const SC_HOST = process.env.AVLIVE_SC_HOST ?? "127.0.0.1";
|
||||
const SC_PORT = parseInt(process.env.AVLIVE_SC_PORT ?? "57121", 10);
|
||||
const SC_HOST = process.env.AVLIVE_SC_HOST ?? "127.0.0.1";
|
||||
const SC_PORT = parseInt(process.env.AVLIVE_SC_PORT ?? "57121", 10);
|
||||
const FEEDBACK_PORT_IN = parseInt(process.env.FEEDBACK_PORT_IN ?? "9000", 10);
|
||||
|
||||
const app = express();
|
||||
app.use(express.static(join(__dirname, "public")));
|
||||
@@ -99,6 +101,26 @@ dataPort.on("message", (oscMsg) => {
|
||||
dataPort.on("error", (err) => console.error("[data] erreur:", err.message));
|
||||
dataPort.open();
|
||||
|
||||
// Second UDP listener: engine feedback (SC -> browser clients).
|
||||
// Relays /armed/*, /sync/beat, /sync/rms, /seq/*/state to all WS clients.
|
||||
// Does NOT update lastByAddress snapshot (feedback is transient, not snapshottable).
|
||||
const feedbackPort = new osc.UDPPort({
|
||||
localAddress: "0.0.0.0",
|
||||
localPort: FEEDBACK_PORT_IN,
|
||||
metadata: false,
|
||||
});
|
||||
|
||||
feedbackPort.on("ready", () => {
|
||||
console.log(`[feedback] ecoute :${FEEDBACK_PORT_IN} <- SC engine`);
|
||||
});
|
||||
|
||||
feedbackPort.on("message", (oscMsg) => {
|
||||
broadcast({ address: oscMsg.address, args: oscMsg.args });
|
||||
});
|
||||
|
||||
feedbackPort.on("error", (err) => console.error("[feedback] erreur:", err.message));
|
||||
feedbackPort.open();
|
||||
|
||||
const scPort = new osc.UDPPort({ localAddress: "127.0.0.1", localPort: 0, metadata: true });
|
||||
scPort.on("ready", () => console.log(`[sc] OSC out -> ${SC_HOST}:${SC_PORT}`));
|
||||
scPort.open();
|
||||
@@ -120,6 +142,7 @@ function shutdown() {
|
||||
console.log("\n[server] shutdown...");
|
||||
wss.close();
|
||||
dataPort.close();
|
||||
feedbackPort.close();
|
||||
scPort.close();
|
||||
httpServer.close(() => process.exit(0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user