From d653283bc442faa8f1a567e72c294cf0e6c063a0 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 15 May 2026 20:07:40 +0200 Subject: [PATCH] feat(fix-d12): add TransferredVideoChunk wire-format type in src/shared/types.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add TransferredVideoChunk { data: string (base64); type: string (MIME); timestamp: number; isFirst?: boolean } as the JSON-serializable shape for chunks traversing the offscreen↔SW chrome.runtime.Port boundary. - Retarget PortMessage.chunks?: TransferredVideoChunk[] (was VideoChunk[]). The in-memory VideoChunk type is unchanged — both the offscreen ring buffer and the SW-side merge step keep using it after decoding the wire payload. - No behavior change yet; this commit only lands the type. The encode/decode call sites land in the next two commits. Refs: debug session d12-blob-port-transfer-fails. --- src/shared/types.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/shared/types.ts b/src/shared/types.ts index b6f0ec8..e5f4856 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -29,16 +29,33 @@ export type PortMessageType = export interface PortMessage { type: PortMessageType; - chunks?: VideoChunk[]; + // Wire-format (post-D-12 fix): chunks travel as TransferredVideoChunk[] + // because chrome.runtime.Port JSON-serializes payloads, and + // JSON.stringify(blob) === "{}" loses binary content. The receive + // side reconstructs VideoChunk[] via src/shared/binary.ts. + chunks?: TransferredVideoChunk[]; } -// Видеобуфер +// In-memory chunk shape used by the offscreen ring buffer and by +// mergeVideoChunks after the SW decodes the wire format. export interface VideoChunk { data: Blob; timestamp: number; isFirst?: boolean; } +// Wire-format for video chunks traveling across the offscreen↔SW +// chrome.runtime.Port boundary. Replaces the previous VideoChunk[] +// payload, which failed because Blob is not JSON-serializable. +// See debug session d12-blob-port-transfer-fails and the GREEN block +// of tests/offscreen/port-serialization.test.ts for the pinned shape. +export interface TransferredVideoChunk { + data: string; // base64-encoded blob bytes (no data: prefix) + type: string; // MIME type to apply when reconstructing the Blob + timestamp: number; + isFirst?: boolean; +} + // Лог событий пользователя export interface UserEvent { timestamp: number;