feat: added endpoint
ref:N25B-400
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const API_BASE = "http://localhost:8000/"; // Change depending on Pims interup agent/ correct endpoint
|
||||
import React, { useEffect } from 'react';
|
||||
const API_BASE = "http://localhost:8000"; // Change depending on Pims interup agent/ correct endpoint
|
||||
|
||||
|
||||
/**
|
||||
@@ -16,4 +17,37 @@ export async function nextPhase(): Promise<void> {
|
||||
if (!res.ok) {
|
||||
throw new Error("Failed to advance to next phase");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A hook that listens to the experiment stream and logs data to the console.
|
||||
* It does not render anything.
|
||||
*/
|
||||
export function useExperimentLogger() {
|
||||
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);
|
||||
|
||||
} catch (err) {
|
||||
console.warn("Received non-JSON experiment data:", event.data);
|
||||
}
|
||||
};
|
||||
|
||||
eventSource.onerror = (err) => {
|
||||
console.error("SSE Connection Error (Experiment Stream):", err);
|
||||
eventSource.close();
|
||||
};
|
||||
|
||||
return () => {
|
||||
console.log("Closing Experiment Stream listener...");
|
||||
eventSource.close();
|
||||
};
|
||||
}, []);
|
||||
}
|
||||
Reference in New Issue
Block a user