Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。
fix(native): report the active codec
AAA7af8bb93c2cc
diff --git a/native/sender/internal/app/ui/app.js b/native/sender/internal/app/ui/app.jsindex a5a8ffca..fa71672a 100644--- a/native/sender/internal/app/ui/app.js+++ b/native/sender/internal/app/ui/app.js@@ -193,6 +193,7 @@ async function connectMediaSocket(generation, codec, audio) {}async function startEncoder(generation, codec) {+ metrics.codec = codec;const preferred = {codec: codec === "h264" ? "avc1.42c01f" : "vp8",width: WIDTH,@@ -218,7 +219,9 @@ async function startEncoder(generation, codec) {metrics.hardwarePreference = HARDWARE_STATUS.PREFERENCE_ACCEPTED;}metrics.hardwareEvidence = HARDWARE_STATUS.UNVERIFIED;- if (!support.supported) throw new Error("此设备不支持 VP8 720p30 编码");+ if (!support.supported) {+ throw new Error(`此设备不支持 ${codecLabel(codec)} 720p30 编码`);+ }let activeEncoder;activeEncoder = new VideoEncoder({output: (chunk) => sendEncodedChunk(generation, activeEncoder, chunk),@@ -592,7 +595,7 @@ function updateDiagnostics() {const height = captureSettings?.height ?? "未知";const rate = captureSettings?.frameRate ?? "未知";elements.captureDiagnostic.textContent = `${width} × ${height} · ${rate} FPS`;- elements.encoderDiagnostic.textContent = `VP8 · 3 Mbps 上限 · 单对象 · 硬件偏好 ${hardwarePreferenceLabel(metrics.hardwarePreference)} · 硬件证据 ${hardwareEvidenceLabel(metrics.hardwareEvidence)}`;+ elements.encoderDiagnostic.textContent = `${codecLabel(metrics.codec)} · 3 Mbps 上限 · 单对象 · 硬件偏好 ${hardwarePreferenceLabel(metrics.hardwarePreference)} · 硬件证据 ${hardwareEvidenceLabel(metrics.hardwareEvidence)}`;elements.bridgeDiagnostic.textContent = `读取 ${metrics.framesRead} · 提交 ${metrics.framesSubmitted} · 输出 ${metrics.encoderOutputs} · 编码队列丢弃 ${metrics.encoderQueueDrops} · 编码队列峰值 ${metrics.encoderQueuePeak} 帧 · socket 峰值 ${metrics.socketBufferedPeak} B`;const helper = nativeDiagnostics?.media;const queue = helper?.queue;@@ -647,6 +650,7 @@ function selectedCodec() {function emptyMetrics() {return {+ codec: "vp8",framesRead: 0,framesSubmitted: 0,encoderOutputs: 0,@@ -659,6 +663,10 @@ function emptyMetrics() {};}+function codecLabel(codec) {+ return codec === "h264" ? "H.264" : "VP8";+}+function hardwarePreferenceLabel(value) {return {[HARDWARE_STATUS.UNREQUESTED]: "未请求",diff --git a/tests/native-hardware-status.test.ts b/tests/native-hardware-status.test.tsindex 95e5ceb8..5427c532 100644--- a/tests/native-hardware-status.test.ts+++ b/tests/native-hardware-status.test.ts@@ -38,6 +38,11 @@ describe("native sender hardware preference contract", () => {expect(senderHTML).toContain('<option value="vp8">VP8 (default)</option>');expect(senderUI).toContain('elements.codec?.value === "h264" ? "h264" : "vp8"');expect(senderUI).toContain('codec: codec === "h264" ? "avc1.42c01f" : "vp8"');+ expect(senderUI).toContain("metrics.codec = codec");+ expect(senderUI).toContain("codecLabel(metrics.codec)");+ expect(senderUI).toContain("codecLabel(codec)");+ expect(senderUI).not.toContain("此设备不支持 VP8 720p30 编码");+ expect(senderUI).not.toContain("`VP8 · 3 Mbps 上限");expect(senderUI).toContain("encoderInstances: 1");expect(senderUI).toContain("HARDWARE_STATUS.PREFERENCE_ACCEPTED");expect(senderUI).toContain("HARDWARE_STATUS.FALLBACK");