@mentra/miniapp 3.3.0-dev.327 → 3.3.0-dev.329
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/background/index.d.ts +3 -1
- package/dist/background/index.d.ts.map +1 -1
- package/dist/background/index.js +1 -0
- package/dist/background/index.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/modules/meeting.d.ts +11 -0
- package/dist/modules/meeting.d.ts.map +1 -1
- package/dist/modules/meeting.js +19 -0
- package/dist/modules/meeting.js.map +1 -1
- package/dist/modules/stream.d.ts +46 -0
- package/dist/modules/stream.d.ts.map +1 -1
- package/dist/modules/stream.js +107 -0
- package/dist/modules/stream.js.map +1 -1
- package/dist/protocol.d.ts +35 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +32 -0
- package/dist/protocol.js.map +1 -1
- package/dist/react/StreamPreview.d.ts +41 -0
- package/dist/react/StreamPreview.d.ts.map +1 -0
- package/dist/react/StreamPreview.js +144 -0
- package/dist/react/StreamPreview.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/stream-preview/PreviewConnection.d.ts +139 -0
- package/dist/react/stream-preview/PreviewConnection.d.ts.map +1 -0
- package/dist/react/stream-preview/PreviewConnection.js +454 -0
- package/dist/react/stream-preview/PreviewConnection.js.map +1 -0
- package/dist/react/stream-preview/controlChannel.d.ts +75 -0
- package/dist/react/stream-preview/controlChannel.d.ts.map +1 -0
- package/dist/react/stream-preview/controlChannel.js +55 -0
- package/dist/react/stream-preview/controlChannel.js.map +1 -0
- package/dist/react/stream-preview/creditLoop.d.ts +81 -0
- package/dist/react/stream-preview/creditLoop.d.ts.map +1 -0
- package/dist/react/stream-preview/creditLoop.js +146 -0
- package/dist/react/stream-preview/creditLoop.js.map +1 -0
- package/dist/react/stream-preview/protocol.d.ts +113 -0
- package/dist/react/stream-preview/protocol.d.ts.map +1 -0
- package/dist/react/stream-preview/protocol.js +148 -0
- package/dist/react/stream-preview/protocol.js.map +1 -0
- package/dist/react/stream-preview/resizeCoalescer.d.ts +38 -0
- package/dist/react/stream-preview/resizeCoalescer.d.ts.map +1 -0
- package/dist/react/stream-preview/resizeCoalescer.js +71 -0
- package/dist/react/stream-preview/resizeCoalescer.js.map +1 -0
- package/dist/react/stream-preview/testFrames.d.ts +38 -0
- package/dist/react/stream-preview/testFrames.d.ts.map +1 -0
- package/dist/react/stream-preview/testFrames.js +50 -0
- package/dist/react/stream-preview/testFrames.js.map +1 -0
- package/dist/react/stream-preview/tiers.d.ts +21 -0
- package/dist/react/stream-preview/tiers.d.ts.map +1 -0
- package/dist/react/stream-preview/tiers.js +33 -0
- package/dist/react/stream-preview/tiers.js.map +1 -0
- package/dist/react/stream-preview/trace.d.ts +23 -0
- package/dist/react/stream-preview/trace.d.ts.map +1 -0
- package/dist/react/stream-preview/trace.js +71 -0
- package/dist/react/stream-preview/trace.js.map +1 -0
- package/dist/react/stream-preview/transport.d.ts +79 -0
- package/dist/react/stream-preview/transport.d.ts.map +1 -0
- package/dist/react/stream-preview/transport.js +209 -0
- package/dist/react/stream-preview/transport.js.map +1 -0
- package/dist/react/stream-preview/yuvRenderer.d.ts +31 -0
- package/dist/react/stream-preview/yuvRenderer.d.ts.map +1 -0
- package/dist/react/stream-preview/yuvRenderer.js +398 -0
- package/dist/react/stream-preview/yuvRenderer.js.map +1 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +5 -0
- package/dist/session.js.map +1 -1
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +1 -0
- package/dist/ui/index.js.map +1 -1
- package/package.json +8 -3
- package/src/background/index.ts +9 -1
- package/src/index.ts +7 -0
- package/src/modules/meeting.ts +23 -0
- package/src/modules/stream.ts +153 -1
- package/src/protocol.ts +71 -0
- package/src/react/StreamPreview.tsx +187 -0
- package/src/react/index.ts +2 -0
- package/src/react/stream-preview/PreviewConnection.ts +543 -0
- package/src/react/stream-preview/controlChannel.ts +119 -0
- package/src/react/stream-preview/creditLoop.ts +189 -0
- package/src/react/stream-preview/protocol.ts +227 -0
- package/src/react/stream-preview/resizeCoalescer.ts +88 -0
- package/src/react/stream-preview/testFrames.ts +86 -0
- package/src/react/stream-preview/tiers.ts +37 -0
- package/src/react/stream-preview/trace.ts +81 -0
- package/src/react/stream-preview/transport.ts +242 -0
- package/src/react/stream-preview/yuvRenderer.ts +453 -0
- package/src/session.ts +6 -0
- package/src/ui/index.ts +2 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build `MFPV` frames for tests. Lives beside the parser so the golden-bytes test and the parser
|
|
3
|
+
* cannot drift apart silently. Not exported from the package entry.
|
|
4
|
+
*/
|
|
5
|
+
import { type PreviewPixelFormat } from "./protocol";
|
|
6
|
+
export interface BuildPreviewFrameOptions {
|
|
7
|
+
width?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
pixelFormat?: PreviewPixelFormat;
|
|
10
|
+
sessionGen?: number;
|
|
11
|
+
frameSeq?: number;
|
|
12
|
+
rotationQuarters?: number;
|
|
13
|
+
/** Raw header codes so a test can send "unknown" (0) and check the fallback. */
|
|
14
|
+
colorMatrixCode?: number;
|
|
15
|
+
colorRangeCode?: number;
|
|
16
|
+
flags?: number;
|
|
17
|
+
timestampNs?: bigint;
|
|
18
|
+
sentAtNs?: bigint;
|
|
19
|
+
/** Byte written into every sample of each plane, so plane views can be told apart. */
|
|
20
|
+
fill?: {
|
|
21
|
+
y?: number;
|
|
22
|
+
u?: number;
|
|
23
|
+
v?: number;
|
|
24
|
+
};
|
|
25
|
+
/** Deliberate corruption, for the rejection tests. Every field overrides what would be written. */
|
|
26
|
+
corrupt?: {
|
|
27
|
+
magic?: readonly number[];
|
|
28
|
+
version?: number;
|
|
29
|
+
headerLen?: number;
|
|
30
|
+
payloadLen?: number;
|
|
31
|
+
/** Payload bytes actually appended, independent of the declared `payloadLen`. */
|
|
32
|
+
payloadBytes?: number;
|
|
33
|
+
pixelFormatCode?: number;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Build a wire-format frame. */
|
|
37
|
+
export declare function buildPreviewFrame(options?: BuildPreviewFrameOptions): ArrayBuffer;
|
|
38
|
+
//# sourceMappingURL=testFrames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testFrames.d.ts","sourceRoot":"","sources":["../../../src/react/stream-preview/testFrames.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAQL,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAA;AAEnB,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAChC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gFAAgF;IAChF,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,sFAAsF;IACtF,IAAI,CAAC,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAA;IAC3C,mGAAmG;IACnG,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;QACzB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,iFAAiF;QACjF,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,eAAe,CAAC,EAAE,MAAM,CAAA;KACzB,CAAA;CACF;AAED,iCAAiC;AACjC,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,WAAW,CAyCrF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build `MFPV` frames for tests. Lives beside the parser so the golden-bytes test and the parser
|
|
3
|
+
* cannot drift apart silently. Not exported from the package entry.
|
|
4
|
+
*/
|
|
5
|
+
import { chromaDimensions, packedPayloadBytes, PIXEL_FORMAT_I420, PIXEL_FORMAT_NV12, PREVIEW_FRAME_HEADER_BYTES, PREVIEW_FRAME_MAGIC, PREVIEW_FRAME_VERSION, } from "./protocol";
|
|
6
|
+
/** Build a wire-format frame. */
|
|
7
|
+
export function buildPreviewFrame(options = {}) {
|
|
8
|
+
const width = options.width ?? 1280;
|
|
9
|
+
const height = options.height ?? 720;
|
|
10
|
+
const pixelFormat = options.pixelFormat ?? "i420";
|
|
11
|
+
const corrupt = options.corrupt ?? {};
|
|
12
|
+
const chroma = chromaDimensions(width, height);
|
|
13
|
+
const declaredPayload = corrupt.payloadLen ?? packedPayloadBytes(width, height);
|
|
14
|
+
const actualPayload = corrupt.payloadBytes ?? packedPayloadBytes(width, height);
|
|
15
|
+
const buffer = new ArrayBuffer(PREVIEW_FRAME_HEADER_BYTES + actualPayload);
|
|
16
|
+
const header = new DataView(buffer, 0, PREVIEW_FRAME_HEADER_BYTES);
|
|
17
|
+
const magic = corrupt.magic ?? PREVIEW_FRAME_MAGIC;
|
|
18
|
+
for (let index = 0; index < 4; index += 1)
|
|
19
|
+
header.setUint8(index, magic[index] ?? 0);
|
|
20
|
+
header.setUint16(4, corrupt.version ?? PREVIEW_FRAME_VERSION, true);
|
|
21
|
+
header.setUint16(6, corrupt.headerLen ?? PREVIEW_FRAME_HEADER_BYTES, true);
|
|
22
|
+
header.setUint32(8, declaredPayload, true);
|
|
23
|
+
header.setUint32(12, options.sessionGen ?? 1, true);
|
|
24
|
+
header.setUint32(16, options.frameSeq ?? 1, true);
|
|
25
|
+
header.setUint16(20, width, true);
|
|
26
|
+
header.setUint16(22, height, true);
|
|
27
|
+
header.setUint8(24, corrupt.pixelFormatCode ?? (pixelFormat === "nv12" ? PIXEL_FORMAT_NV12 : PIXEL_FORMAT_I420));
|
|
28
|
+
header.setUint8(25, options.rotationQuarters ?? 0);
|
|
29
|
+
header.setUint8(26, options.colorMatrixCode ?? 1);
|
|
30
|
+
header.setUint8(27, options.colorRangeCode ?? 1);
|
|
31
|
+
header.setUint16(28, options.flags ?? 0, true);
|
|
32
|
+
header.setBigInt64(32, options.timestampNs ?? 0n, true);
|
|
33
|
+
header.setBigInt64(40, options.sentAtNs ?? 0n, true);
|
|
34
|
+
const payload = new Uint8Array(buffer, PREVIEW_FRAME_HEADER_BYTES);
|
|
35
|
+
const luma = Math.min(width * height, payload.length);
|
|
36
|
+
const chromaPlane = chroma.width * chroma.height;
|
|
37
|
+
payload.fill(options.fill?.y ?? 0x80, 0, luma);
|
|
38
|
+
if (pixelFormat === "nv12") {
|
|
39
|
+
for (let index = luma; index + 1 < payload.length; index += 2) {
|
|
40
|
+
payload[index] = options.fill?.u ?? 0x40;
|
|
41
|
+
payload[index + 1] = options.fill?.v ?? 0xc0;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
payload.fill(options.fill?.u ?? 0x40, luma, Math.min(luma + chromaPlane, payload.length));
|
|
46
|
+
payload.fill(options.fill?.v ?? 0xc0, Math.min(luma + chromaPlane, payload.length));
|
|
47
|
+
}
|
|
48
|
+
return buffer;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=testFrames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testFrames.js","source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
|
|
4
|
+
* The page measures its box (CSS pixels × devicePixelRatio, after rotation) and only tells the
|
|
5
|
+
* host when the quantized tier changes, so a resize storm costs at most one reconfigure per tier.
|
|
6
|
+
* The host quantizes again with the same table and is the authority; native never upscales.
|
|
7
|
+
*/
|
|
8
|
+
export interface PreviewTier {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
maxFps: number;
|
|
12
|
+
}
|
|
13
|
+
/** Smallest first. The last entry is the ceiling until measurements justify raising it. */
|
|
14
|
+
export declare const PREVIEW_TIERS: readonly PreviewTier[];
|
|
15
|
+
/**
|
|
16
|
+
* The smallest tier that covers the box, capped at the ceiling. A zero-area box means the preview
|
|
17
|
+
* is hidden and returns null.
|
|
18
|
+
*/
|
|
19
|
+
export declare function quantizePreviewTier(boxWidth: number, boxHeight: number): PreviewTier | null;
|
|
20
|
+
export declare function sameTier(a: PreviewTier | null, b: PreviewTier | null): boolean;
|
|
21
|
+
//# sourceMappingURL=tiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiers.d.ts","sourceRoot":"","sources":["../../../src/react/stream-preview/tiers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAED,2FAA2F;AAC3F,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAG/C,CAAA;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAM3F;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,EAAE,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,CAI9E"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preview sizing tiers.
|
|
3
|
+
*
|
|
4
|
+
* The page measures its box (CSS pixels × devicePixelRatio, after rotation) and only tells the
|
|
5
|
+
* host when the quantized tier changes, so a resize storm costs at most one reconfigure per tier.
|
|
6
|
+
* The host quantizes again with the same table and is the authority; native never upscales.
|
|
7
|
+
*/
|
|
8
|
+
/** Smallest first. The last entry is the ceiling until measurements justify raising it. */
|
|
9
|
+
export const PREVIEW_TIERS = [
|
|
10
|
+
{ width: 320, height: 180, maxFps: 15 },
|
|
11
|
+
{ width: 640, height: 360, maxFps: 15 },
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* The smallest tier that covers the box, capped at the ceiling. A zero-area box means the preview
|
|
15
|
+
* is hidden and returns null.
|
|
16
|
+
*/
|
|
17
|
+
export function quantizePreviewTier(boxWidth, boxHeight) {
|
|
18
|
+
if (!(boxWidth > 0) || !(boxHeight > 0))
|
|
19
|
+
return null;
|
|
20
|
+
for (const tier of PREVIEW_TIERS) {
|
|
21
|
+
if (tier.width >= boxWidth && tier.height >= boxHeight)
|
|
22
|
+
return tier;
|
|
23
|
+
}
|
|
24
|
+
return PREVIEW_TIERS[PREVIEW_TIERS.length - 1];
|
|
25
|
+
}
|
|
26
|
+
export function sameTier(a, b) {
|
|
27
|
+
if (a === b)
|
|
28
|
+
return true;
|
|
29
|
+
if (!a || !b)
|
|
30
|
+
return false;
|
|
31
|
+
return a.width === b.width && a.height === b.height && a.maxFps === b.maxFps;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=tiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiers.js","sourceRoot":"","sources":["../../../src/react/stream-preview/tiers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,2FAA2F;AAC3F,MAAM,CAAC,MAAM,aAAa,GAA2B;IACnD,EAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAC;IACrC,EAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAC;CACtC,CAAA;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAgB,EAAE,SAAiB;IACrE,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;QAAE,OAAO,IAAI,CAAA;IACpD,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;QACjC,IAAI,IAAI,CAAC,KAAK,IAAI,QAAQ,IAAI,IAAI,CAAC,MAAM,IAAI,SAAS;YAAE,OAAO,IAAI,CAAA;IACrE,CAAC;IACD,OAAO,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAE,CAAA;AACjD,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,CAAqB,EAAE,CAAqB;IACnE,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACxB,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAA;IAC1B,OAAO,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,CAAA;AAC9E,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page-side `PREVIEW_TRACE` lines.
|
|
3
|
+
*
|
|
4
|
+
* Same shape as the host and native layers: a literal grep marker, `phase=`, then `key=value`
|
|
5
|
+
* pairs. The WebView console is forwarded to the host as `dev_log`, so these lines land in the
|
|
6
|
+
* Mentra App log buffer next to the host's and ship with bug reports.
|
|
7
|
+
*
|
|
8
|
+
* Nothing here runs per frame. Per-frame facts are counters.
|
|
9
|
+
*/
|
|
10
|
+
/** Grep marker. Never build this by concatenation — a single grep must be exhaustive. */
|
|
11
|
+
export declare const PREVIEW_TRACE_MARKER = "PREVIEW_TRACE";
|
|
12
|
+
export type PreviewTraceFields = Record<string, string | number | boolean | null | undefined>;
|
|
13
|
+
type Sink = (line: string, level: "log" | "warn") => void;
|
|
14
|
+
/** Render one line. Exported for tests. */
|
|
15
|
+
export declare function formatPreviewTrace(phase: string, fields?: PreviewTraceFields): string;
|
|
16
|
+
export declare function previewTrace(phase: string, fields?: PreviewTraceFields): void;
|
|
17
|
+
export declare function previewTraceWarn(phase: string, fields?: PreviewTraceFields): void;
|
|
18
|
+
/** Warn once per key, then report how many were suppressed at most every 10 s. */
|
|
19
|
+
export declare function previewTraceWarnLimited(key: string, phase: string, fields?: PreviewTraceFields): void;
|
|
20
|
+
/** Test seam: capture lines and drive the clock. Pass nothing to restore the defaults. */
|
|
21
|
+
export declare function setPreviewTraceSinkForTests(next?: Sink, clock?: () => number): void;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../../src/react/stream-preview/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,yFAAyF;AACzF,eAAO,MAAM,oBAAoB,kBAAkB,CAAA;AAOnD,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;AAE7F,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,KAAK,IAAI,CAAA;AAgBzD,2CAA2C;AAC3C,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,kBAAuB,GAAG,MAAM,CASzF;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAE7E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAEjF;AAID,kFAAkF;AAClF,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAcrG;AAED,0FAA0F;AAC1F,wBAAgB,2BAA2B,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAInF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page-side `PREVIEW_TRACE` lines.
|
|
3
|
+
*
|
|
4
|
+
* Same shape as the host and native layers: a literal grep marker, `phase=`, then `key=value`
|
|
5
|
+
* pairs. The WebView console is forwarded to the host as `dev_log`, so these lines land in the
|
|
6
|
+
* Mentra App log buffer next to the host's and ship with bug reports.
|
|
7
|
+
*
|
|
8
|
+
* Nothing here runs per frame. Per-frame facts are counters.
|
|
9
|
+
*/
|
|
10
|
+
/** Grep marker. Never build this by concatenation — a single grep must be exhaustive. */
|
|
11
|
+
export const PREVIEW_TRACE_MARKER = "PREVIEW_TRACE";
|
|
12
|
+
const REDACTED = "<redacted>";
|
|
13
|
+
const SENSITIVE_KEYS = ["token", "secret", "password", "authorization", "url", "meetingurl"];
|
|
14
|
+
/** Repeated identical warnings: log the first, then a count at most this often. */
|
|
15
|
+
const RATE_LIMIT_WINDOW_MS = 10000;
|
|
16
|
+
function defaultSink(line, level) {
|
|
17
|
+
if (typeof console === "undefined")
|
|
18
|
+
return;
|
|
19
|
+
if (level === "warn")
|
|
20
|
+
console.warn(line);
|
|
21
|
+
else
|
|
22
|
+
console.log(line);
|
|
23
|
+
}
|
|
24
|
+
let sink = defaultSink;
|
|
25
|
+
let now = () => (typeof performance !== "undefined" ? performance.now() : Date.now());
|
|
26
|
+
function isSensitive(key) {
|
|
27
|
+
const lower = key.toLowerCase();
|
|
28
|
+
return SENSITIVE_KEYS.some((sensitive) => lower.includes(sensitive));
|
|
29
|
+
}
|
|
30
|
+
/** Render one line. Exported for tests. */
|
|
31
|
+
export function formatPreviewTrace(phase, fields = {}) {
|
|
32
|
+
const parts = [`[${PREVIEW_TRACE_MARKER}]`, `layer=page`, `phase=${phase}`];
|
|
33
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
34
|
+
if (value === undefined)
|
|
35
|
+
continue;
|
|
36
|
+
const rendered = isSensitive(key) ? REDACTED : String(value).replace(/\s+/g, "_");
|
|
37
|
+
parts.push(`${key}=${rendered}`);
|
|
38
|
+
}
|
|
39
|
+
parts.push(`t=${Math.round(now())}`);
|
|
40
|
+
return parts.join(" ");
|
|
41
|
+
}
|
|
42
|
+
export function previewTrace(phase, fields) {
|
|
43
|
+
sink(formatPreviewTrace(phase, fields), "log");
|
|
44
|
+
}
|
|
45
|
+
export function previewTraceWarn(phase, fields) {
|
|
46
|
+
sink(formatPreviewTrace(phase, fields), "warn");
|
|
47
|
+
}
|
|
48
|
+
const rateLimited = new Map();
|
|
49
|
+
/** Warn once per key, then report how many were suppressed at most every 10 s. */
|
|
50
|
+
export function previewTraceWarnLimited(key, phase, fields) {
|
|
51
|
+
const at = now();
|
|
52
|
+
const entry = rateLimited.get(key);
|
|
53
|
+
if (!entry) {
|
|
54
|
+
rateLimited.set(key, { firstAt: at, suppressed: 0 });
|
|
55
|
+
previewTraceWarn(phase, fields);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
entry.suppressed += 1;
|
|
59
|
+
if (at - entry.firstAt >= RATE_LIMIT_WINDOW_MS) {
|
|
60
|
+
previewTraceWarn(phase, { ...fields, repeated: entry.suppressed });
|
|
61
|
+
entry.firstAt = at;
|
|
62
|
+
entry.suppressed = 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Test seam: capture lines and drive the clock. Pass nothing to restore the defaults. */
|
|
66
|
+
export function setPreviewTraceSinkForTests(next, clock) {
|
|
67
|
+
sink = next ?? defaultSink;
|
|
68
|
+
now = clock ?? (() => (typeof performance !== "undefined" ? performance.now() : Date.now()));
|
|
69
|
+
rateLimited.clear();
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../../src/react/stream-preview/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,yFAAyF;AACzF,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAAe,CAAA;AAEnD,MAAM,QAAQ,GAAG,YAAY,CAAA;AAC7B,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,CAAC,CAAA;AAC5F,mFAAmF;AACnF,MAAM,oBAAoB,GAAG,KAAM,CAAA;AAMnC,SAAS,WAAW,CAAC,IAAY,EAAE,KAAqB;IACtD,IAAI,OAAO,OAAO,KAAK,WAAW;QAAE,OAAM;IAC1C,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;;QACnC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC;AAED,IAAI,IAAI,GAAS,WAAW,CAAA;AAC5B,IAAI,GAAG,GAAiB,GAAG,EAAE,CAAC,CAAC,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;AAEnG,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;IAC/B,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAA;AACtE,CAAC;AAED,2CAA2C;AAC3C,MAAM,UAAU,kBAA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KAAK,EAAE,CAAC;QACX,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,EAAC,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAC,CAAC,CAAA;QAClD,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC/B,OAAM;IACR,CAAC;IACD,KAAK,CAAC,UAAU,IAAI,CAAC,CAAA;IACrB,IAAI,EAAE,GAAG,KAAK,CAAC,OAAO,IAAI,oBAAoB,EAAE,CAAC;QAC/C,gBAAgB,CAAC,KAAK,EAAE,EAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,UAAU,EAAC,CAAC,CAAA;QAChE,KAAK,CAAC,OAAO,GAAG,EAAE,CAAA;QAClB,KAAK,CAAC,UAAU,GAAG,CAAC,CAAA;IACtB,CAAC;AACH,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,2BAA2B,CAAC,IAAW,EAAE,KAAoB;IAC3E,IAAI,GAAG,IAAI,IAAI,WAAW,CAAA;IAC1B,GAAG,GAAG,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;IAC5F,WAAW,CAAC,KAAK,EAAE,CAAA;AACrB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two ways raw frames reach this WebView, behind one interface.
|
|
3
|
+
*
|
|
4
|
+
* iOS has no way to hand a WebView binary without a copy through JavaScriptCore, so it gets a
|
|
5
|
+
* loopback WebSocket. Android has `WebViewCompat.addWebMessageListener`, which delivers an
|
|
6
|
+
* ArrayBuffer to a JS object the native side installs on `window`. Which one is in use is decided
|
|
7
|
+
* by the host's config, never by the page.
|
|
8
|
+
*
|
|
9
|
+
* Reconnection is not here. Every failure is surfaced with its own reason and `PreviewConnection`
|
|
10
|
+
* decides whether to handshake again.
|
|
11
|
+
*/
|
|
12
|
+
export interface PreviewTransport {
|
|
13
|
+
connect(): Promise<void>;
|
|
14
|
+
onBinary(cb: (buf: ArrayBuffer) => void): void;
|
|
15
|
+
onError(cb: (reason: string) => void): void;
|
|
16
|
+
sendText(json: string): void;
|
|
17
|
+
close(): void;
|
|
18
|
+
}
|
|
19
|
+
/** Carries the machine-readable reason so a caller does not have to match on message text. */
|
|
20
|
+
export declare class PreviewTransportError extends Error {
|
|
21
|
+
readonly reason: string;
|
|
22
|
+
constructor(reason: string);
|
|
23
|
+
}
|
|
24
|
+
/** The Android-side object installed by `WebViewCompat.addWebMessageListener`. */
|
|
25
|
+
export interface PreviewWebMessagePort {
|
|
26
|
+
postMessage(message: string): void;
|
|
27
|
+
addEventListener(type: "message", handler: (event: {
|
|
28
|
+
data: unknown;
|
|
29
|
+
}) => void): void;
|
|
30
|
+
removeEventListener?(type: "message", handler: (event: {
|
|
31
|
+
data: unknown;
|
|
32
|
+
}) => void): void;
|
|
33
|
+
}
|
|
34
|
+
/** Used when an older host config omits `portName`. */
|
|
35
|
+
export declare const DEFAULT_PREVIEW_PORT_NAME = "MentraFramePreviewPort";
|
|
36
|
+
/** `{t:"ack",gen,seq}` — the one message the consumer sends per frame. */
|
|
37
|
+
export declare function ackMessage(gen: number, seq: number): string;
|
|
38
|
+
/** iOS: a loopback WebSocket from the native host. */
|
|
39
|
+
export declare class WebSocketTransport implements PreviewTransport {
|
|
40
|
+
private readonly url;
|
|
41
|
+
private readonly token;
|
|
42
|
+
private socket;
|
|
43
|
+
private binaryHandler;
|
|
44
|
+
private errorHandler;
|
|
45
|
+
private opened;
|
|
46
|
+
private closed;
|
|
47
|
+
constructor(url: string, token: string);
|
|
48
|
+
connect(): Promise<void>;
|
|
49
|
+
onBinary(cb: (buf: ArrayBuffer) => void): void;
|
|
50
|
+
onError(cb: (reason: string) => void): void;
|
|
51
|
+
sendText(json: string): void;
|
|
52
|
+
close(): void;
|
|
53
|
+
private fail;
|
|
54
|
+
}
|
|
55
|
+
/** Android: the JS object native installs with `WebViewCompat.addWebMessageListener`. */
|
|
56
|
+
export declare class WebMessagePortTransport implements PreviewTransport {
|
|
57
|
+
private readonly token;
|
|
58
|
+
private readonly portName;
|
|
59
|
+
private port;
|
|
60
|
+
private binaryHandler;
|
|
61
|
+
private errorHandler;
|
|
62
|
+
private closed;
|
|
63
|
+
private readonly listener;
|
|
64
|
+
constructor(token: string, portName?: string);
|
|
65
|
+
connect(): Promise<void>;
|
|
66
|
+
onBinary(cb: (buf: ArrayBuffer) => void): void;
|
|
67
|
+
onError(cb: (reason: string) => void): void;
|
|
68
|
+
sendText(json: string): void;
|
|
69
|
+
close(): void;
|
|
70
|
+
private report;
|
|
71
|
+
}
|
|
72
|
+
export interface PreviewTransportOptions {
|
|
73
|
+
url?: string;
|
|
74
|
+
portName?: string;
|
|
75
|
+
token: string;
|
|
76
|
+
}
|
|
77
|
+
/** Build the transport the host asked for. The page never picks on its own. */
|
|
78
|
+
export declare function createPreviewTransport(transport: "websocket" | "webmessage", options: PreviewTransportOptions): PreviewTransport;
|
|
79
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/react/stream-preview/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACxB,QAAQ,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,GAAG,IAAI,CAAA;IAC9C,OAAO,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAA;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,KAAK,IAAI,IAAI,CAAA;CACd;AAED,8FAA8F;AAC9F,qBAAa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;IAa5B,KAAK,IAAI,IAAI;IAgBb,OAAO,CAAC,IAAI;CAKb;AAED,yFAAyF;AACzF,qBAAa,uBAAwB,YAAW,gBAAgB;IAc5D,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAd3B,OAAO,CAAC,IAAI,CAAqC;IACjD,OAAO,CAAC,aAAa,CAA4C;IACjE,OAAO,CAAC,YAAY,CAA0C;IAC9D,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAMxB;gBAGkB,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,MAAkC;IAG/D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBxB,QAAQ,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,GAAG,IAAI;IAI9C,OAAO,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAI3C,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAa5B,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,MAAM;CAIf;AAED,MAAM,WAAW,uBAAuB;IACtC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,+EAA+E;AAC/E,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,WAAW,GAAG,YAAY,EACrC,OAAO,EAAE,uBAAuB,GAC/B,gBAAgB,CAMlB"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two ways raw frames reach this WebView, behind one interface.
|
|
3
|
+
*
|
|
4
|
+
* iOS has no way to hand a WebView binary without a copy through JavaScriptCore, so it gets a
|
|
5
|
+
* loopback WebSocket. Android has `WebViewCompat.addWebMessageListener`, which delivers an
|
|
6
|
+
* ArrayBuffer to a JS object the native side installs on `window`. Which one is in use is decided
|
|
7
|
+
* by the host's config, never by the page.
|
|
8
|
+
*
|
|
9
|
+
* Reconnection is not here. Every failure is surfaced with its own reason and `PreviewConnection`
|
|
10
|
+
* decides whether to handshake again.
|
|
11
|
+
*/
|
|
12
|
+
import { previewTrace, previewTraceWarn } from "./trace";
|
|
13
|
+
/** Carries the machine-readable reason so a caller does not have to match on message text. */
|
|
14
|
+
export class PreviewTransportError extends Error {
|
|
15
|
+
constructor(reason) {
|
|
16
|
+
super(reason);
|
|
17
|
+
this.name = "PreviewTransportError";
|
|
18
|
+
this.reason = reason;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Used when an older host config omits `portName`. */
|
|
22
|
+
export const DEFAULT_PREVIEW_PORT_NAME = "MentraFramePreviewPort";
|
|
23
|
+
/** `{t:"ack",gen,seq}` — the one message the consumer sends per frame. */
|
|
24
|
+
export function ackMessage(gen, seq) {
|
|
25
|
+
return JSON.stringify({ t: "ack", gen, seq });
|
|
26
|
+
}
|
|
27
|
+
function helloMessage(token) {
|
|
28
|
+
return JSON.stringify({ t: "hello", token });
|
|
29
|
+
}
|
|
30
|
+
/** iOS: a loopback WebSocket from the native host. */
|
|
31
|
+
export class WebSocketTransport {
|
|
32
|
+
constructor(url, token) {
|
|
33
|
+
this.url = url;
|
|
34
|
+
this.token = token;
|
|
35
|
+
this.socket = null;
|
|
36
|
+
this.binaryHandler = null;
|
|
37
|
+
this.errorHandler = null;
|
|
38
|
+
this.opened = false;
|
|
39
|
+
this.closed = false;
|
|
40
|
+
}
|
|
41
|
+
connect() {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
let socket;
|
|
44
|
+
try {
|
|
45
|
+
socket = new WebSocket(this.url);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
previewTraceWarn("transport_error", {
|
|
49
|
+
transport: "websocket",
|
|
50
|
+
reason: "websocket_unavailable",
|
|
51
|
+
error: error instanceof Error ? error.message : String(error),
|
|
52
|
+
});
|
|
53
|
+
reject(new PreviewTransportError("websocket_unavailable"));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
socket.binaryType = "arraybuffer";
|
|
57
|
+
this.socket = socket;
|
|
58
|
+
socket.onopen = () => {
|
|
59
|
+
this.opened = true;
|
|
60
|
+
try {
|
|
61
|
+
// `connect()` must not resolve before the host knows who we are, or the first frames
|
|
62
|
+
// would race the hello and be dropped by the sender as unauthenticated.
|
|
63
|
+
socket.send(helloMessage(this.token));
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
this.fail("hello_send_failed");
|
|
67
|
+
reject(new PreviewTransportError("hello_send_failed"));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
previewTrace("transport_open", { transport: "websocket" });
|
|
71
|
+
resolve();
|
|
72
|
+
};
|
|
73
|
+
socket.onmessage = (event) => {
|
|
74
|
+
// Text frames are not this channel: control lives on the `_preview` UI channel.
|
|
75
|
+
if (event.data instanceof ArrayBuffer)
|
|
76
|
+
this.binaryHandler?.(event.data);
|
|
77
|
+
};
|
|
78
|
+
socket.onerror = () => {
|
|
79
|
+
const reason = this.opened ? "websocket_error" : "websocket_connect_error";
|
|
80
|
+
this.fail(reason);
|
|
81
|
+
if (!this.opened)
|
|
82
|
+
reject(new PreviewTransportError(reason));
|
|
83
|
+
};
|
|
84
|
+
socket.onclose = (event) => {
|
|
85
|
+
const reason = this.opened ? `websocket_closed:${event.code}` : `websocket_closed_before_open:${event.code}`;
|
|
86
|
+
this.fail(reason);
|
|
87
|
+
if (!this.opened)
|
|
88
|
+
reject(new PreviewTransportError(reason));
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
onBinary(cb) {
|
|
93
|
+
this.binaryHandler = cb;
|
|
94
|
+
}
|
|
95
|
+
onError(cb) {
|
|
96
|
+
this.errorHandler = cb;
|
|
97
|
+
}
|
|
98
|
+
sendText(json) {
|
|
99
|
+
const socket = this.socket;
|
|
100
|
+
if (!socket || socket.readyState !== WebSocket.OPEN) {
|
|
101
|
+
this.fail("send_while_closed");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
socket.send(json);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
this.fail("send_failed");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
close() {
|
|
112
|
+
this.closed = true;
|
|
113
|
+
const socket = this.socket;
|
|
114
|
+
this.socket = null;
|
|
115
|
+
if (!socket)
|
|
116
|
+
return;
|
|
117
|
+
socket.onopen = null;
|
|
118
|
+
socket.onmessage = null;
|
|
119
|
+
socket.onerror = null;
|
|
120
|
+
socket.onclose = null;
|
|
121
|
+
try {
|
|
122
|
+
socket.close();
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// A socket that never opened throws here on some engines; the transport is gone either way.
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
fail(reason) {
|
|
129
|
+
// A close the caller asked for is not a failure.
|
|
130
|
+
if (this.closed)
|
|
131
|
+
return;
|
|
132
|
+
this.errorHandler?.(reason);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** Android: the JS object native installs with `WebViewCompat.addWebMessageListener`. */
|
|
136
|
+
export class WebMessagePortTransport {
|
|
137
|
+
constructor(token, portName = DEFAULT_PREVIEW_PORT_NAME) {
|
|
138
|
+
this.token = token;
|
|
139
|
+
this.portName = portName;
|
|
140
|
+
this.port = null;
|
|
141
|
+
this.binaryHandler = null;
|
|
142
|
+
this.errorHandler = null;
|
|
143
|
+
this.closed = false;
|
|
144
|
+
this.listener = (event) => {
|
|
145
|
+
if (event.data instanceof ArrayBuffer) {
|
|
146
|
+
this.binaryHandler?.(event.data);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (typeof event.data !== "string")
|
|
150
|
+
this.report("port_unexpected_payload");
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
connect() {
|
|
154
|
+
const port = typeof window === "undefined"
|
|
155
|
+
? undefined
|
|
156
|
+
: window[this.portName];
|
|
157
|
+
if (!port)
|
|
158
|
+
return Promise.reject(new PreviewTransportError("port_missing"));
|
|
159
|
+
this.port = port;
|
|
160
|
+
port.addEventListener("message", this.listener);
|
|
161
|
+
try {
|
|
162
|
+
port.postMessage(helloMessage(this.token));
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return Promise.reject(new PreviewTransportError("hello_send_failed"));
|
|
166
|
+
}
|
|
167
|
+
previewTrace("transport_open", { transport: "webmessage" });
|
|
168
|
+
return Promise.resolve();
|
|
169
|
+
}
|
|
170
|
+
onBinary(cb) {
|
|
171
|
+
this.binaryHandler = cb;
|
|
172
|
+
}
|
|
173
|
+
onError(cb) {
|
|
174
|
+
this.errorHandler = cb;
|
|
175
|
+
}
|
|
176
|
+
sendText(json) {
|
|
177
|
+
const port = this.port;
|
|
178
|
+
if (!port) {
|
|
179
|
+
this.report("send_while_closed");
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
port.postMessage(json);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
this.report("send_failed");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
close() {
|
|
190
|
+
this.closed = true;
|
|
191
|
+
this.port?.removeEventListener?.("message", this.listener);
|
|
192
|
+
this.port = null;
|
|
193
|
+
}
|
|
194
|
+
report(reason) {
|
|
195
|
+
if (this.closed)
|
|
196
|
+
return;
|
|
197
|
+
this.errorHandler?.(reason);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Build the transport the host asked for. The page never picks on its own. */
|
|
201
|
+
export function createPreviewTransport(transport, options) {
|
|
202
|
+
if (transport === "websocket") {
|
|
203
|
+
if (!options.url)
|
|
204
|
+
throw new PreviewTransportError("missing_url");
|
|
205
|
+
return new WebSocketTransport(options.url, options.token);
|
|
206
|
+
}
|
|
207
|
+
return new WebMessagePortTransport(options.token, options.portName);
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/react/stream-preview/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAC,YAAY,EAAE,gBAAgB,EAAC,MAAM,SAAS,CAAA;AAUtD,8FAA8F;AAC9F,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAG9C,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AASD,uDAAuD;AACvD,MAAM,CAAC,MAAM,yBAAyB,GAAG,wBAAwB,CAAA;AAEjE,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,GAAW;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,EAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAC,CAAC,CAAA;AAC7C,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,OAAO,IAAI,CAAC,SAAS,CAAC,EAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC,CAAA;AAC5C,CAAC;AAED,sDAAsD;AACtD,MAAM,OAAO,kBAAkB;IAO7B,YACmB,GAAW,EACX,KAAa;QADb,QAAG,GAAH,GAAG,CAAQ;QACX,UAAK,GAAL,KAAK,CAAQ;QARxB,WAAM,GAAqB,IAAI,CAAA;QAC/B,kBAAa,GAAwC,IAAI,CAAA;QACzD,iBAAY,GAAsC,IAAI,CAAA;QACtD,WAAM,GAAG,KAAK,CAAA;QACd,WAAM,GAAG,KAAK,CAAA;IAKnB,CAAC;IAEJ,OAAO;QACL,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,MAAiB,CAA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B,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QAClB,IAAI,CAAC,IAAI,EAAE,mBAAmB,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC1D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEO,MAAM,CAAC,MAAc;QAC3B,IAAI,IAAI,CAAC,MAAM;YAAE,OAAM;QACvB,IAAI,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,CAAA;IAC7B,CAAC;CACF;AAQD,+EAA+E;AAC/E,MAAM,UAAU,sBAAsB,CACpC,SAAqC,EACrC,OAAgC;IAEhC,IAAI,SAAS,KAAK,WAAW,EAAE,CAAC;QAC9B,IAAI,CAAC,OAAO,CAAC,GAAG;YAAE,MAAM,IAAI,qBAAqB,CAAC,aAAa,CAAC,CAAA;QAChE,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3D,CAAC;IACD,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;AACrE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebGL1 YUV → RGB renderer for raw preview frames.
|
|
3
|
+
*
|
|
4
|
+
* WebGL1 only, on purpose: the Mentra App supports iOS 15.5 / Safari 15, where WebGL2, WebCodecs,
|
|
5
|
+
* `VideoFrame` and `OffscreenCanvas` are either absent or unreliable. Everything here is the
|
|
6
|
+
* 2013 feature set — `LUMINANCE` textures, one draw call, a fragment shader doing the colour
|
|
7
|
+
* conversion.
|
|
8
|
+
*
|
|
9
|
+
* Rules:
|
|
10
|
+
* - JavaScript never touches a pixel. Planes go to `texImage2D`/`texSubImage2D` as views.
|
|
11
|
+
* - `readPixels` is never called; it would stall the pipeline.
|
|
12
|
+
* - `drawFrame` times the SUBMIT, not the paint. See the comment on that method.
|
|
13
|
+
*/
|
|
14
|
+
import type { ParsedFrame } from "./protocol";
|
|
15
|
+
/** `contain` letterboxes; `cover` fills the canvas and crops the overflow. Never stretches. */
|
|
16
|
+
export type PreviewFit = "contain" | "cover";
|
|
17
|
+
export interface YuvRendererOptions {
|
|
18
|
+
/** Context loss, a failed compile, a failed upload: anything that makes the canvas stop. */
|
|
19
|
+
onError?: (reason: string) => void;
|
|
20
|
+
fit?: PreviewFit;
|
|
21
|
+
}
|
|
22
|
+
export interface YuvRenderer {
|
|
23
|
+
/** False once the GL context is lost, until it is restored. */
|
|
24
|
+
readonly alive: boolean;
|
|
25
|
+
setFit(fit: PreviewFit): void;
|
|
26
|
+
drawFrame(frame: ParsedFrame): number | null;
|
|
27
|
+
dispose(): void;
|
|
28
|
+
}
|
|
29
|
+
/** Create the renderer, or null when this WebView has no WebGL1 context to give. */
|
|
30
|
+
export declare function createYuvRenderer(canvas: HTMLCanvasElement, options?: YuvRendererOptions): YuvRenderer | null;
|
|
31
|
+
//# sourceMappingURL=yuvRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yuvRenderer.d.ts","sourceRoot":"","sources":["../../../src/react/stream-preview/yuvRenderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAC,WAAW,EAA4D,MAAM,YAAY,CAAA;AA6EtG,+FAA+F;AAC/F,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,OAAO,CAAA;AAE5C,MAAM,WAAW,kBAAkB;IACjC,4FAA4F;IAC5F,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,GAAG,CAAC,EAAE,UAAU,CAAA;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI,CAAA;IAC7B,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAAA;IAC5C,OAAO,IAAI,IAAI,CAAA;CAChB;AAwUD,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,GAAE,kBAAuB,GAAG,WAAW,GAAG,IAAI,CAiBjH"}
|