perf(relay): reduce encrypted binary traffic overhead (#2480)

Preserve application frame identity through encryption so negotiated binary traffic avoids base64 expansion while mixed-version peers remain compatible.
This commit is contained in:
Mohamed Boudra
2026-07-27 12:12:02 +02:00
committed by GitHub
parent 1a1ff8828f
commit 1d1132de9c
22 changed files with 397 additions and 113 deletions
@@ -14,17 +14,25 @@ export function normalizeTransportPayload(
return copyArrayBufferViewToBuffer(data);
}
export function extractRelayMessageData(event: unknown): string | ArrayBuffer {
export interface RelayTransportMessage {
data: string | ArrayBuffer;
isBinary: boolean;
}
export function extractRelayMessage(event: unknown, nodeIsBinary?: boolean): RelayTransportMessage {
const raw =
event && typeof event === "object" && "data" in event
? (event as { data: unknown }).data
: event;
if (typeof raw === "string") return raw;
if (raw instanceof ArrayBuffer) return raw;
if (ArrayBuffer.isView(raw)) {
return copyArrayBufferViewToBuffer(raw);
const isBinary = nodeIsBinary ?? typeof raw !== "string";
if (!isBinary) {
return { data: decodeMessageData(raw) ?? String(raw ?? ""), isBinary: false };
}
return String(raw ?? "");
if (raw instanceof ArrayBuffer) return { data: raw, isBinary: true };
if (ArrayBuffer.isView(raw)) {
return { data: copyArrayBufferViewToBuffer(raw), isBinary: true };
}
return { data: String(raw ?? ""), isBinary: true };
}
export function describeTransportClose(event?: unknown): string {