feat(workbench): expand SCADA monitoring and investigation presentation
This commit is contained in:
@@ -91,13 +91,21 @@ export async function mockInvestigationPresentation(page: Page, tasks: Operation
|
||||
await page.addInitScript(() => {
|
||||
const fetch = window.fetch.bind(window);
|
||||
const streams = new Set<ReadableStreamDefaultController<Uint8Array>>();
|
||||
Object.assign(window, { emitInvestigationTestEvent: (event: unknown) => {
|
||||
let connectionAvailable = true;
|
||||
Object.assign(window, { setInvestigationTestConnection: (available: boolean) => {
|
||||
connectionAvailable = available;
|
||||
if (!available) {
|
||||
for (const stream of streams) stream.error(new TypeError("synthetic connection lost"));
|
||||
streams.clear();
|
||||
}
|
||||
}, emitInvestigationTestEvent: (event: unknown) => {
|
||||
const data = new TextEncoder().encode(`event: workbench_event\ndata: ${JSON.stringify(event)}\n\n`);
|
||||
for (const stream of streams) stream.enqueue(data);
|
||||
} });
|
||||
window.fetch = async (input, init) => {
|
||||
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
||||
if (!url.includes("/api/v1/workbench/events")) return fetch(input, init);
|
||||
if (!connectionAvailable) throw new TypeError("synthetic connection unavailable");
|
||||
let current: ReadableStreamDefaultController<Uint8Array>;
|
||||
const body = new ReadableStream<Uint8Array>({ start(controller) { current = controller; streams.add(controller); }, cancel() { streams.delete(current); } });
|
||||
init?.signal?.addEventListener("abort", () => { if (streams.delete(current)) current.close(); }, { once: true });
|
||||
|
||||
Reference in New Issue
Block a user