Files
Termix/plugins/remote-desktop/frontend/guacamole-session-id.ts
T
LukeGus c6bcfdb80d feat: move remote desktop (RDP/VNC/Telnet) into a first-party plugin
Relocates guacamole backend/frontend source and tests into
plugins/remote-desktop, following the ssh-terminal/docker pattern.
2026-09-21 20:25:52 -05:00

32 lines
869 B
TypeScript

import { getGuacamoleConnectionId } from "./guacamole-api";
import type { ConnectionOrigin } from "@/lib/connection-origin";
export function watchGuacamoleConnectionId(
connectId: string,
origin: ConnectionOrigin,
onReady: (id: string) => void,
): () => void {
const controller = new AbortController();
let timer: ReturnType<typeof setTimeout> | undefined;
let attempts = 0;
const poll = async () => {
try {
const id = await getGuacamoleConnectionId(
connectId,
origin,
controller.signal,
);
if (controller.signal.aborted) return;
if (id) onReady(id);
else if (++attempts < 20) timer = setTimeout(poll, 500);
} catch {
// Session sharing discovery must not interrupt the remote display.
}
};
void poll();
return () => {
controller.abort();
clearTimeout(timer);
};
}