diff --git a/src/views/devices/remote-control/controlProtocol.ts b/src/views/devices/remote-control/controlProtocol.ts index 256d2ebf..c45c2b67 100644 --- a/src/views/devices/remote-control/controlProtocol.ts +++ b/src/views/devices/remote-control/controlProtocol.ts @@ -37,8 +37,105 @@ export function readTouchMode(data: ArrayBuffer): TouchMode { return 0; } +export type ResolutionReport = { + width: number; + height: number; + fps: number; + supportedFps: number[]; +}; + +/** 解析被控端 REPORT_RESOLUTION;非该消息返回 undefined。 */ +export function readResolutionReport(data: ArrayBuffer): ResolutionReport | undefined { + const bytes = new Uint8Array(data); + let position = 0; + let action = 0; + let width = 0; + let height = 0; + let fps = 0; + const supportedFps: number[] = []; + function readVarint() { + let value = 0; + for (let shift = 0; shift <= 28 && position < bytes.length; shift += 7) { + const byte = bytes[position++]; + value += (byte & 127) * 2 ** shift; + if ((byte & 128) === 0) return value; + } + throw new Error("Invalid resolution report"); + } + + try { + while (position < bytes.length) { + const tag = readVarint(); + const field = tag >>> 3; + switch (tag & 7) { + case 0: { + const value = readVarint(); + if (field === 1) action = value; + else if (field === 12) width = value; + else if (field === 13) height = value; + else if (field === 14) fps = value; + else if (field === 16) supportedFps.push(value); + break; + } + case 2: { + const length = readVarint(); + const end = position + length; + if (end > bytes.length) return undefined; + if (field === 16) { + while (position < end) supportedFps.push(readVarint()); + } + position = end; + break; + } + default: + return undefined; + } + } + } catch { + return undefined; + } + return action === 7 && width > 0 && height > 0 ? { width, height, fps, supportedFps } : undefined; +} + +/** 编码 SET_RESOLUTION;width<=0 表示原始分辨率,fps<=0 表示沿用当前帧率。 */ +export function encodeResolution(width: number, height: number, fps: number) { + const bytes = new Uint8Array(32); + let offset = 0; + function varint(field: number, value: number) { + bytes[offset++] = field << 3; + while (value >= 128) { + bytes[offset++] = (value & 127) | 128; + value >>>= 7; + } + bytes[offset++] = value; + } + varint(1, 6); + varint(12, width); + varint(13, height); + varint(14, fps); + return bytes.slice(0, offset); +} + export type Point = { x: number; y: number }; +/** 编码 KEY 指令;keyAction 传 -1 表示按下并立即抬起。 */ +export function encodeKey(keyCode: number, keyAction: number) { + const bytes = new Uint8Array(16); + let offset = 0; + function varint(field: number, value: number) { + bytes[offset++] = field << 3; + while (value >= 128 || value < 0) { + bytes[offset++] = (value & 127) | 128; + value >>>= 7; + } + bytes[offset++] = value; + } + varint(1, 3); + varint(9, keyCode); + varint(10, keyAction); + return bytes.slice(0, offset); +} + export function encodeTouch(action: number, start: Point, end?: Point, detail?: number) { const bytes = new Uint8Array(48); const view = new DataView(bytes.buffer); diff --git a/src/views/devices/remote-control/index.vue b/src/views/devices/remote-control/index.vue index d975b933..3cf2a57f 100644 --- a/src/views/devices/remote-control/index.vue +++ b/src/views/devices/remote-control/index.vue @@ -27,6 +27,44 @@

管理员可直接连接在线设备,无需老人逐次确认。

{{ status }}

+
+ + 分辨率 + {{ stats.resolution }} + + + 帧率 + {{ stats.fps }} + + + 编码 + {{ stats.codec }} + + + 延迟 + {{ stats.latency }} + + + 抖动 + {{ stats.jitter }} + + + 丢帧 + {{ stats.framesDropped }} + + + 丢包 + {{ stats.packetLoss }} + + + 下载 + {{ stats.downSpeed }} + + + 时长 + {{ stats.duration }} + +