hopefully fix

This commit is contained in:
KingKDot
2026-06-16 17:51:41 -05:00
parent a6d6b4d31b
commit 932b7cbc33
6 changed files with 36 additions and 12 deletions
@@ -36,7 +36,7 @@ describe("pruneStaleClients", () => {
expect(deleted).toEqual([]);
});
test("closes and marks offline stale role=client entries without deleting", () => {
test("closes, marks offline, and deletes stale role=client entries", () => {
const clients = new Map<string, ClientInfo>();
const staleClient = makeClient("stale-c", Date.now() - 120_000, "client");
clients.set("stale-c", staleClient);
@@ -53,7 +53,7 @@ describe("pruneStaleClients", () => {
});
expect(offlined).toContain("stale-c");
expect(deleted).not.toContain("stale-c");
expect(deleted).toContain("stale-c");
expect((staleClient.ws as any)._calls[0]).toStartWith("close:");
});
@@ -20,6 +20,7 @@ export function pruneStaleClients(params: PruneStaleClientsParams): void {
if (info.role === "client") {
info.ws.close(4000, "stale");
params.setOnlineState(id, false);
params.deleteClient(id);
processed += 1;
continue;
}
@@ -390,6 +390,7 @@ export function handleRemoteDesktopViewerMessage(ws: ServerWebSocket<SocketData>
whepPath: `/api/webrtc/${streamPath}/whep`,
});
}
safeSendViewer(ws, { type: "status", status: "starting" });
sendDesktopCommand(target, "desktop_set_fps", { fps: clampDesktopFps(state.maxFps) });
sendDesktopCommand(target, "desktop_start", {});
state.isStreaming = true;
@@ -403,6 +404,7 @@ export function handleRemoteDesktopViewerMessage(ws: ServerWebSocket<SocketData>
logger.info(`[rd-debug] desktop_start reasserting stale stream client=${clientId} lastFrameAgeMs=${Number.isFinite(lastFrameAgeMs) ? lastFrameAgeMs : -1} state=${JSON.stringify(state)} viewers=${sessionManager.getRdSessionsForClient(clientId).length}`);
sendDesktopCommand(target, "desktop_set_fps", { fps: clampDesktopFps(state.maxFps) });
sendDesktopCommand(target, "desktop_start", {});
safeSendViewer(ws, { type: "status", status: "starting" });
state.isStreaming = true;
state.startedAt = Date.now();
rdStreamingState.set(clientId, state);
@@ -437,6 +439,7 @@ export function handleRemoteDesktopViewerMessage(ws: ServerWebSocket<SocketData>
} else {
logger.debug(`[rd] ignoring desktop_stop for client ${clientId} - ${otherViewers.length} other viewer(s) still active`);
}
safeSendViewer(ws, { type: "status", status: "stopped" });
break;
}
case "desktop_record_start": {
@@ -994,6 +997,7 @@ export function handleWebcamViewerMessage(ws: ServerWebSocket<SocketData>, raw:
whepPath: `/api/webrtc/${streamPath}/whep`,
});
}
safeSendViewer(ws, { type: "status", status: "starting" });
sendDesktopCommand(target, "webcam_start", {});
state.isStreaming = true;
webcamStreamingState.set(clientId, state);
@@ -1019,6 +1023,7 @@ export function handleWebcamViewerMessage(ws: ServerWebSocket<SocketData>, raw:
} else {
logger.debug(`[webcam] ignoring webcam_stop for client ${clientId} - ${otherWebcamViewers.length} other viewer(s) still active`);
}
safeSendViewer(ws, { type: "status", status: "stopped" });
break;
}
case "webrtc_p2p_offer": {