Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(remote-desktop): retain outstanding viewer heartbeat challenge
Dash5ad2e35a9275
diff --git a/apps/desktop/src/renderer/features/remote-desktop/__tests__/RemoteDesktopHost.test.tsx b/apps/desktop/src/renderer/features/remote-desktop/__tests__/RemoteDesktopHost.test.tsxindex 955d501c74..e5d3298e0d 100644--- a/apps/desktop/src/renderer/features/remote-desktop/__tests__/RemoteDesktopHost.test.tsx+++ b/apps/desktop/src/renderer/features/remote-desktop/__tests__/RemoteDesktopHost.test.tsx@@ -107,6 +107,7 @@ it('exchanges replayable candidates without recapturing, tolerates transient disvi.stubGlobal('navigator', { mediaDevices: { getDisplayMedia: capture } });let command!: (value: any) => void;const reply = vi.fn().mockResolvedValue(undefined);+ const viewHeartbeat = vi.fn().mockResolvedValue(undefined);Object.assign(window, {electronAPI: {remoteDesktop: {@@ -115,6 +116,7 @@ it('exchanges replayable candidates without recapturing, tolerates transient disreturn () => {};},reply,+ viewHeartbeat,registerHost: vi.fn().mockResolvedValue(undefined),state: vi.fn().mockResolvedValue(null),stop: vi.fn().mockResolvedValue(undefined),@@ -132,6 +134,16 @@ it('exchanges replayable candidates without recapturing, tolerates transient dis};await act(async () => command(offer));expect(reply).toHaveBeenCalledWith('offer', 'answer'); // No gather delay for new endpoints.+ const channel = { label: 'input-v1', readyState: 'open', send: vi.fn(), onmessage: (_event: any) => {} };+ peers[0].ondatachannel({ channel });+ await act(() => vi.advanceTimersByTimeAsync(8000));+ expect(channel.send).toHaveBeenCalledTimes(1);+ const firstChallenge = JSON.parse(channel.send.mock.calls[0][0]).challenge;+ channel.onmessage({ data: firstChallenge });+ expect(viewHeartbeat).toHaveBeenCalledWith('lease');+ await act(() => vi.advanceTimersByTimeAsync(2000));+ expect(channel.send).toHaveBeenCalledTimes(2);+ expect(JSON.parse(channel.send.mock.calls[1][0]).challenge).not.toBe(firstChallenge);const candidate = {candidate: 'candidate:1 1 UDP 100 192.0.2.1 5000 typ host',sdpMid: '0',@@ -166,6 +178,8 @@ it('exchanges replayable candidates without recapturing, tolerates transient disawait act(() => vi.advanceTimersByTimeAsync(2));expect(peers[0].close).not.toHaveBeenCalled();await act(async () => command({ ...offer, id: 'new', attemptId: 'b' }));+ channel.onmessage({ data: JSON.parse(channel.send.mock.calls[1][0]).challenge });+ expect(viewHeartbeat).toHaveBeenCalledTimes(1);await act(async () => command({ ...ice, id: 'old' }));expect(reply).toHaveBeenCalledWith('old', { error: 'DESKTOP_VIDEO_STOPPED' });expect(peers[1].addIceCandidate).not.toHaveBeenCalled();diff --git a/apps/desktop/src/renderer/features/remote-desktop/captureHost.ts b/apps/desktop/src/renderer/features/remote-desktop/captureHost.tsindex 17b58087c1..8d1da17b1c 100644--- a/apps/desktop/src/renderer/features/remote-desktop/captureHost.ts+++ b/apps/desktop/src/renderer/features/remote-desktop/captureHost.ts@@ -293,7 +293,9 @@ export function startDesktopCaptureHost(api: DesktopCaptureApi): () => void {let pending = 0;let challenge = '';heartbeat = setInterval(() => {- if (channel.readyState !== 'open' || current !== generation) return;+ // Keep one outstanding challenge until its reply arrives. The host+ // lease bounds silence; replacing it here rejects valid slow pongs.+ if (channel.readyState !== 'open' || current !== generation || challenge) return;challenge = crypto.randomUUID();channel.send(JSON.stringify({ type: 'viewPing', challenge }));}, 2000);