Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(remote-desktop): 转发 offer 时补回旧版 bitrate,修复连旧被控端只能截图中转 (#5435)

Dashc4d68f0da7c3
diff --git a/apps/desktop/src/main/remote-desktop-viewer/__tests__/connection.test.ts b/apps/desktop/src/main/remote-desktop-viewer/__tests__/connection.test.ts
index f356ccda71..d07db20922 100644
--- a/apps/desktop/src/main/remote-desktop-viewer/__tests__/connection.test.ts
+++ b/apps/desktop/src/main/remote-desktop-viewer/__tests__/connection.test.ts
@@ -1,6 +1,10 @@
import { describe, it, expect, vi } from 'vitest';
import { RemoteViewerConnection } from '../connection';
-import { ClipboardSync, type RemoteDesktopRequest } from '@cindy/device-link';
+import {
+ ClipboardSync,
+ remoteDesktopVideoSettingsWire,
+ type RemoteDesktopRequest,
+} from '@cindy/device-link';
import { DEFAULT_VIEWER_PREFERENCES } from '../../../shared/remoteDesktopViewer';
function fixture() {
@@ -174,6 +178,27 @@ describe('standalone remote viewer authority', () => {
});
expect(f.readClipboard).not.toHaveBeenCalled();
});
+ it('keeps the legacy bitrate on forwarded offers so older hosts accept video settings', async () => {
+ const f = fixture();
+ await f.connection.request(f.connection.generation, { op: 'start', displayId: 'screen' });
+ const generation = f.connection.generation;
+ f.connection.beginMedia(generation, '1');
+ f.request.mockImplementationOnce(async () => ({ sdp: 'answer' }));
+ await f.connection.request(
+ generation,
+ {
+ op: 'offer',
+ lease: 'lease-a',
+ sdp: 'offer',
+ settings: remoteDesktopVideoSettingsWire({ fps: 60, quality: 'hd', audio: false }),
+ },
+ '1',
+ );
+ expect(f.request.mock.calls.at(-1)?.[1]).toMatchObject({
+ op: 'offer',
+ settings: { fps: 60, quality: 'hd', audio: false, bitrate: 20_000_000 },
+ });
+ });
it('invalidates queued signaling after a newer media attempt without closing the lease', async () => {
const f = fixture();
await f.connection.request(f.connection.generation, { op: 'start', displayId: 'screen' });
diff --git a/apps/desktop/src/main/remote-desktop-viewer/connection.ts b/apps/desktop/src/main/remote-desktop-viewer/connection.ts
index 86b69f6bcd..0ea6146667 100644
--- a/apps/desktop/src/main/remote-desktop-viewer/connection.ts
+++ b/apps/desktop/src/main/remote-desktop-viewer/connection.ts
@@ -1,5 +1,6 @@
import {
parseRemoteDesktopRequest,
+ remoteDesktopVideoSettingsWire,
isDesktopAttemptId,
REMOTE_DESKTOP_MAX_CLIPBOARD_CHARS,
type RemoteDesktopRequest,
@@ -204,7 +205,13 @@ export class RemoteViewerConnection {
if ('lease' in request && request.lease !== this.lease)
throw new Error('DESKTOP_LEASE_EXPIRED');
if (isStart) this.attempted = true;
- const result = await this.deps.request(target.deviceId, request, check);
+ // Parsing normalizes offer settings to `quality`; older hosts still
+ // require the legacy `bitrate`, so restore the wire shape before sending.
+ const outgoing =
+ request.op === 'offer' && request.settings
+ ? { ...request, settings: remoteDesktopVideoSettingsWire(request.settings) }
+ : request;
+ const result = await this.deps.request(target.deviceId, outgoing, check);
if (request.op === 'capabilities') {
check();
this.caps = result as RemoteDesktopCapabilities;
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 0fa5b7d273..0f626c1af2 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -171,7 +171,9 @@ Mobile 未新增卡片入口。服务端无需改动。
hd→20M):旧被控端只校验 `bitrate` 并忽略 `quality`,无需新增能力声明。新被控端优先读取
已知档位;档位缺失或不认识时按旧 `bitrate` 换算(0→auto、2M→saver、8M/20M→hd),因此旧
控制端与未来新增档位都能降级连接。两者都无效时仍返回 `INVALID_REQUEST`。此变更不改 relay、
-不新增 channel,服务端无需改动。
+不新增 channel,服务端无需改动。Desktop 远程桌面窗口的主进程会先用 `parseRemoteDesktopRequest`
+校验 renderer 请求(解析结果只保留档位),转发给被控端前必须再经 `remoteDesktopVideoSettingsWire`
+补回旧 `bitrate`;否则旧被控端对每次 offer 都返回 `INVALID_REQUEST`,视频退回截图中转。
被控端在应用控制端 offer 前,仅为带 `settings` 的请求给视频编解码追加 `x-google-start-bitrate` /
`x-google-min-bitrate` / `x-google-max-bitrate`,避免近静止画面因发送量过低导致带宽估计塌到