Merge remote-tracking branch 'origin/demo' into feat/monitoringpage-pim

This commit is contained in:
Pim Hutting
2026-01-08 09:54:48 +01:00
parent 4356f201ab
commit a2b4847ca4
48 changed files with 3038 additions and 527 deletions

View File

@@ -23,31 +23,28 @@ export async function nextPhase(): Promise<void> {
* A hook that listens to the experiment stream and logs data to the console.
* It does not render anything.
*/
export function useExperimentLogger() {
export function useExperimentLogger(onUpdate?: (data: any) => void) {
useEffect(() => {
console.log("Starting Experiment Stream listener...");
const eventSource = new EventSource(`${API_BASE}/experiment_stream`);
eventSource.onmessage = (event) => {
try {
const parsedData = JSON.parse(event.data);
console.log(" [Experiment Update Received] ", parsedData);
if (onUpdate) {
onUpdate(parsedData);
}
} catch (err) {
console.warn("Received non-JSON experiment data:", event.data);
console.warn("Stream parse error:", err);
}
};
eventSource.onerror = (err) => {
console.error("SSE Connection Error (Experiment Stream):", err);
console.error("SSE Connection Error:", err);
eventSource.close();
};
return () => {
console.log("Closing Experiment Stream listener...");
eventSource.close();
};
}, []);
}, [onUpdate]);
}