@mentra/miniapp 3.3.0-dev.328 → 3.3.0-dev.331
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
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,+EAA+E;AAC/E,iDAAiD;AACjD,+EAA+E;AAE/E,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,+EAA+E;AAC/E,iDAAiD;AACjD,+EAA+E;AAE/E,MAAM,CAAN,IAAY,kBAqOX;AArOD,WAAY,kBAAkB;IAC5B,8EAA8E;IAC9E,iDAA2B,CAAA;IAE3B,yDAAyD;IACzD,2DAAqC,CAAA;IAErC,8DAA8D;IAC9D,qDAA+B,CAAA;IAE/B;;;;OAIG;IACH,iDAA2B,CAAA;IAE3B,uEAAuE;IACvE,+CAAyB,CAAA;IAEzB,8EAA8E;IAC9E,uDAAiC,CAAA;IAEjC,sDAAsD;IACtD,uDAAiC,CAAA;IAEjC,2DAA2D;IAC3D,6CAAuB,CAAA;IAEvB;;;;;OAKG;IACH,yEAAmD,CAAA;IACnD,2EAAqD,CAAA;IACrD,2EAAqD,CAAA;IACrD,2EAAqD,CA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C,gFAAgF;IAChF,+DAA2C,CAAA;IAC3C,gEAAgE;IAChE,2DAAuC,CAAA;IACvC,wEAAwE;IACxE,iEAA6C,CAAA;IAC7C,kFAAkF;IAClF,6DAAyC,CAAA;AAC3C,CAAC,EAxEW,gBAAgB,KAAhB,gBAAgB,QAwE3B;AA6BD,MAAM,CAAC,MAAM,mBAAmB,GAAgC;IAC9D,mBAAmB;IACnB,mBAAmB;IACnB,cAAc;IACd,mBAAmB;IACnB,cAAc;IACd,aAAa;IACb,aAAa;IACb,kBAAkB;IAClB,aAAa;IACb,mBAAmB;IACnB,sBAAsB;CACvB,CAAA;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,mBAAyC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAChG,CAAC;AAUD,kFAAkF;AAClF,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<StreamPreview>` — draws the raw decoded frames of the source the miniapp's background has
|
|
3
|
+
* leased with `session.stream.preview()`.
|
|
4
|
+
*
|
|
5
|
+
* The component owns only the renderer (canvas, WebGL context, textures). Mounting it shows the
|
|
6
|
+
* preview; unmounting it hides the preview and stops production, but keeps the document's
|
|
7
|
+
* connection open so the next mount starts without a handshake. Releasing the lease is the
|
|
8
|
+
* background's job (`handle.stop()`), not this component's.
|
|
9
|
+
*
|
|
10
|
+
* Frame bytes never enter React state: frames go from the transport to the renderer directly.
|
|
11
|
+
*/
|
|
12
|
+
import { type CSSProperties } from "react";
|
|
13
|
+
import type { PreviewConnectionState } from "./stream-preview/PreviewConnection";
|
|
14
|
+
import { type PreviewFit, type YuvRenderer, type YuvRendererOptions } from "./stream-preview/yuvRenderer";
|
|
15
|
+
export type { PreviewFit } from "./stream-preview/yuvRenderer";
|
|
16
|
+
export type { PreviewConnectionState } from "./stream-preview/PreviewConnection";
|
|
17
|
+
export interface StreamPreviewStatus {
|
|
18
|
+
state: PreviewConnectionState;
|
|
19
|
+
/** The Mentra App is in the background; production is paused and resumes on return. */
|
|
20
|
+
paused: boolean;
|
|
21
|
+
/** Why the state changed, when the host said (`source_ended`, `stopped`, ...). */
|
|
22
|
+
reason?: string;
|
|
23
|
+
/** Error code for `error` / `unsupported`. */
|
|
24
|
+
code?: string;
|
|
25
|
+
/** Latest once-a-second host counters plus page-side counters. */
|
|
26
|
+
stats?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
export interface StreamPreviewProps {
|
|
29
|
+
/** `contain` letterboxes (default); `cover` fills and crops. The picture is never stretched. */
|
|
30
|
+
fit?: PreviewFit;
|
|
31
|
+
onStatus?: (status: StreamPreviewStatus) => void;
|
|
32
|
+
/** Typed preview error codes: `source_ended`, `unsupported`, `transport_failed`, ... */
|
|
33
|
+
onError?: (code: string) => void;
|
|
34
|
+
className?: string;
|
|
35
|
+
style?: CSSProperties;
|
|
36
|
+
}
|
|
37
|
+
type RendererFactory = (canvas: HTMLCanvasElement, options: YuvRendererOptions) => YuvRenderer | null;
|
|
38
|
+
/** Test seam: WebGL is not available in headless DOMs. */
|
|
39
|
+
export declare function setStreamPreviewRendererFactoryForTests(factory: RendererFactory | null): void;
|
|
40
|
+
export declare function StreamPreview({ fit, onStatus, onError, className, style }: StreamPreviewProps): import("react").JSX.Element;
|
|
41
|
+
//# sourceMappingURL=StreamPreview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamPreview.d.ts","sourceRoot":"","sources":["../../src/react/StreamPreview.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAoB,KAAK,aAAa,EAAC,MAAM,OAAO,CAAA;AAE3D,OAAO,KAAK,EAAC,sBAAsB,EAAc,MAAM,oCAAoC,CAAA;AAK3F,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,8BAA8B,CAAA;AAErC,YAAY,EAAC,UAAU,EAAC,MAAM,8BAA8B,CAAA;AAC5D,YAAY,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAA;AAE9E,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,sBAAsB,CAAA;IAC7B,uFAAuF;IACvF,MAAM,EAAE,OAAO,CAAA;IACf,kFAAkF;IAClF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,8CAA8C;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,gGAAgG;IAChG,GAAG,CAAC,EAAE,UAAU,CAAA;IAChB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAA;IAChD,wFAAwF;IACxF,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAED,KAAK,eAAe,GAAG,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,kBAAkB,KAAK,WAAW,GAAG,IAAI,CAAA;AAIrG,0DAA0D;AAC1D,wBAAgB,uCAAuC,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAE7F;AAcD,wBAAgB,aAAa,CAAC,EAAC,GAAe,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAC,EAAE,kBAAkB,+BAkHvG"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* `<StreamPreview>` — draws the raw decoded frames of the source the miniapp's background has
|
|
4
|
+
* leased with `session.stream.preview()`.
|
|
5
|
+
*
|
|
6
|
+
* The component owns only the renderer (canvas, WebGL context, textures). Mounting it shows the
|
|
7
|
+
* preview; unmounting it hides the preview and stops production, but keeps the document's
|
|
8
|
+
* connection open so the next mount starts without a handshake. Releasing the lease is the
|
|
9
|
+
* background's job (`handle.stop()`), not this component's.
|
|
10
|
+
*
|
|
11
|
+
* Frame bytes never enter React state: frames go from the transport to the renderer directly.
|
|
12
|
+
*/
|
|
13
|
+
import { useEffect, useRef } from "react";
|
|
14
|
+
import { getPreviewConnection } from "./stream-preview/PreviewConnection";
|
|
15
|
+
import { ResizeCoalescer } from "./stream-preview/resizeCoalescer";
|
|
16
|
+
import { quantizePreviewTier, sameTier } from "./stream-preview/tiers";
|
|
17
|
+
import { previewTrace, previewTraceWarn } from "./stream-preview/trace";
|
|
18
|
+
import { createYuvRenderer, } from "./stream-preview/yuvRenderer";
|
|
19
|
+
let rendererFactory = createYuvRenderer;
|
|
20
|
+
/** Test seam: WebGL is not available in headless DOMs. */
|
|
21
|
+
export function setStreamPreviewRendererFactoryForTests(factory) {
|
|
22
|
+
rendererFactory = factory ?? createYuvRenderer;
|
|
23
|
+
}
|
|
24
|
+
const DEFAULT_STYLE = { display: "block", width: "100%", height: "100%" };
|
|
25
|
+
function measure(canvas) {
|
|
26
|
+
const rect = canvas.getBoundingClientRect();
|
|
27
|
+
const ratio = typeof window === "undefined" ? 1 : window.devicePixelRatio || 1;
|
|
28
|
+
return { width: Math.round(rect.width * ratio), height: Math.round(rect.height * ratio) };
|
|
29
|
+
}
|
|
30
|
+
function isDocumentVisible() {
|
|
31
|
+
return typeof document === "undefined" || document.visibilityState !== "hidden";
|
|
32
|
+
}
|
|
33
|
+
export function StreamPreview({ fit = "contain", onStatus, onError, className, style }) {
|
|
34
|
+
const canvasRef = useRef(null);
|
|
35
|
+
const rendererRef = useRef(null);
|
|
36
|
+
const fitRef = useRef(fit);
|
|
37
|
+
const onStatusRef = useRef(onStatus);
|
|
38
|
+
const onErrorRef = useRef(onError);
|
|
39
|
+
fitRef.current = fit;
|
|
40
|
+
onStatusRef.current = onStatus;
|
|
41
|
+
onErrorRef.current = onError;
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
rendererRef.current?.setFit(fit);
|
|
44
|
+
}, [fit]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const canvas = canvasRef.current;
|
|
47
|
+
if (!canvas)
|
|
48
|
+
return;
|
|
49
|
+
const connection = getPreviewConnection();
|
|
50
|
+
const mountEpoch = connection.nextMountEpoch();
|
|
51
|
+
let contextLosses = 0;
|
|
52
|
+
let status = { state: connection.currentState, paused: false };
|
|
53
|
+
let box = { width: 0, height: 0 };
|
|
54
|
+
let tier = null;
|
|
55
|
+
let running = isDocumentVisible();
|
|
56
|
+
let unmounted = false;
|
|
57
|
+
const emit = (next) => {
|
|
58
|
+
status = { ...status, ...next };
|
|
59
|
+
onStatusRef.current?.(status);
|
|
60
|
+
};
|
|
61
|
+
const buildRenderer = () => {
|
|
62
|
+
rendererRef.current?.dispose();
|
|
63
|
+
rendererRef.current = rendererFactory(canvas, {
|
|
64
|
+
fit: fitRef.current,
|
|
65
|
+
onError: (reason) => {
|
|
66
|
+
previewTraceWarn("renderer_error", { reason, mountEpoch, docGen: connection.documentGeneration });
|
|
67
|
+
connection.reportRendererError(mountEpoch, reason);
|
|
68
|
+
if (reason === "webgl_context_lost")
|
|
69
|
+
contextLosses += 1;
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
if (!rendererRef.current)
|
|
73
|
+
connection.reportRendererError(mountEpoch, "webgl_unavailable");
|
|
74
|
+
};
|
|
75
|
+
buildRenderer();
|
|
76
|
+
// Context loss rebuilds only the renderer. The connection and the lease are not involved,
|
|
77
|
+
// and frames that arrive meanwhile are still acked so the sender does not stall.
|
|
78
|
+
const onContextRestored = () => {
|
|
79
|
+
if (unmounted)
|
|
80
|
+
return;
|
|
81
|
+
previewTrace("renderer_rebuilt", { mountEpoch, contextLosses });
|
|
82
|
+
buildRenderer();
|
|
83
|
+
};
|
|
84
|
+
canvas.addEventListener("webglcontextrestored", onContextRestored);
|
|
85
|
+
const sink = {
|
|
86
|
+
mountEpoch,
|
|
87
|
+
draw: (frame) => rendererRef.current?.drawFrame(frame) ?? null,
|
|
88
|
+
onState: (state, detail) => emit({ state, paused: detail.paused ?? false, reason: detail.reason, code: detail.code }),
|
|
89
|
+
onStatus: (stats) => emit({ stats: { ...stats, contextLosses } }),
|
|
90
|
+
onError: (code) => onErrorRef.current?.(code),
|
|
91
|
+
};
|
|
92
|
+
const detach = connection.attach(sink);
|
|
93
|
+
previewTrace("mount", { mountEpoch, docGen: connection.documentGeneration });
|
|
94
|
+
const push = () => connection.update(mountEpoch, { boxWidth: box.width, boxHeight: box.height, tier, running });
|
|
95
|
+
const coalescer = new ResizeCoalescer({
|
|
96
|
+
apply: (next) => {
|
|
97
|
+
box = next;
|
|
98
|
+
const nextTier = quantizePreviewTier(next.width, next.height);
|
|
99
|
+
if (sameTier(nextTier, tier) && tier !== null)
|
|
100
|
+
return;
|
|
101
|
+
tier = nextTier;
|
|
102
|
+
if (!tier)
|
|
103
|
+
previewTrace("hidden_zero_size", { mountEpoch });
|
|
104
|
+
push();
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
let resizeObserver = null;
|
|
108
|
+
const onWindowResize = () => coalescer.push(measure(canvas));
|
|
109
|
+
if (typeof ResizeObserver === "function") {
|
|
110
|
+
resizeObserver = new ResizeObserver(() => coalescer.push(measure(canvas)));
|
|
111
|
+
resizeObserver.observe(canvas);
|
|
112
|
+
}
|
|
113
|
+
else if (typeof window !== "undefined") {
|
|
114
|
+
window.addEventListener("resize", onWindowResize);
|
|
115
|
+
}
|
|
116
|
+
coalescer.push(measure(canvas));
|
|
117
|
+
const onVisibility = () => {
|
|
118
|
+
const visible = isDocumentVisible();
|
|
119
|
+
if (visible === running)
|
|
120
|
+
return;
|
|
121
|
+
running = visible;
|
|
122
|
+
previewTrace("visibility_change", { mountEpoch, visible });
|
|
123
|
+
push();
|
|
124
|
+
};
|
|
125
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
126
|
+
return () => {
|
|
127
|
+
unmounted = true;
|
|
128
|
+
previewTrace("unmount", { mountEpoch, docGen: connection.documentGeneration });
|
|
129
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
130
|
+
resizeObserver?.disconnect();
|
|
131
|
+
if (typeof window !== "undefined")
|
|
132
|
+
window.removeEventListener("resize", onWindowResize);
|
|
133
|
+
coalescer.cancel();
|
|
134
|
+
canvas.removeEventListener("webglcontextrestored", onContextRestored);
|
|
135
|
+
running = false;
|
|
136
|
+
push();
|
|
137
|
+
detach();
|
|
138
|
+
rendererRef.current?.dispose();
|
|
139
|
+
rendererRef.current = null;
|
|
140
|
+
};
|
|
141
|
+
}, []);
|
|
142
|
+
return _jsx("canvas", { ref: canvasRef, className: className, style: { ...DEFAULT_STYLE, ...style } });
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=StreamPreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamPreview.js","sourceRoot":"","sources":["../../src/react/StreamPreview.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAC,SAAS,EAAE,MAAM,EAAqB,MAAM,OAAO,CAAA;AAG3D,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AACvE,OAAO,EAAC,eAAe,EAAkB,MAAM,kCAAkC,CAAA;AACjF,OAAO,EAAC,mBAAmB,EAAE,QAAQ,EAAmB,MAAM,wBAAwB,CAAA;AACtF,OAAO,EAAC,YAAY,EAAE,gBAAgB,EAAC,MAAM,wBAAwB,CAAA;AACrE,OAAO,EACL,iBAAiB,GAIlB,MAAM,8BAA8B,CAAA;AA6BrC,IAAI,eAAe,GAAoB,iBAAiB,CAAA;AAExD,0DAA0D;AAC1D,MAAM,UAAU,uCAAuC,CAAC,OAA+B;IACrF,eAAe,GAAG,OAAO,IAAI,iBAAiB,CAAA;AAChD,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export type { MiniappHeaderProps } from "./MiniappHeader";
|
|
|
10
10
|
export { MentraProvider } from "./MentraProvider";
|
|
11
11
|
export type { MentraProviderProps } from "./MentraProvider";
|
|
12
12
|
export { useRpc, type RpcCallable } from "./useRpc";
|
|
13
|
+
export { StreamPreview } from "./StreamPreview";
|
|
14
|
+
export type { StreamPreviewProps, StreamPreviewStatus, PreviewFit, PreviewConnectionState } from "./StreamPreview";
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AACzC,YAAY,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAA;AACpD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAA;AAC7D,YAAY,EAAC,4BAA4B,EAAC,MAAM,yBAAyB,CAAA;AACzE,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;AAC7C,YAAY,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAC/C,YAAY,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAC,MAAM,EAAE,KAAK,WAAW,EAAC,MAAM,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AACzC,YAAY,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAA;AACpD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAA;AAC7D,YAAY,EAAC,4BAA4B,EAAC,MAAM,yBAAyB,CAAA;AACzE,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;AAC7C,YAAY,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAC/C,YAAY,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAC,MAAM,EAAE,KAAK,WAAW,EAAC,MAAM,UAAU,CAAA;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;AAC7C,YAAY,EAAC,kBAAkB,EAAE,mBAAmB,EAAE,UAAU,EAAE,sBAAsB,EAAC,MAAM,iBAAiB,CAAA"}
|
package/dist/react/index.js
CHANGED
|
@@ -6,4 +6,5 @@ export { useCapsuleHeaderStyle } from "./useCapsuleHeaderStyle";
|
|
|
6
6
|
export { MiniappHeader } from "./MiniappHeader";
|
|
7
7
|
export { MentraProvider } from "./MentraProvider";
|
|
8
8
|
export { useRpc } from "./useRpc";
|
|
9
|
+
export { StreamPreview } from "./StreamPreview";
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAA;AAE7D,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;AAE7C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EAAC,MAAM,EAAmB,MAAM,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAA;AAE7D,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;AAE7C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EAAC,MAAM,EAAmB,MAAM,UAAU,CAAA;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The preview connection for this document.
|
|
3
|
+
*
|
|
4
|
+
* Three owners with three lifetimes meet here:
|
|
5
|
+
* - The **lease** belongs to the miniapp's background (`session.stream.preview()`). The page
|
|
6
|
+
* never creates or releases it; it only hears `lease_available` / `lease_ended`.
|
|
7
|
+
* - The **connection** belongs to this document: the host config (token, docGen), the frame
|
|
8
|
+
* transport and the credit loop. It is a module-scoped singleton so it survives
|
|
9
|
+
* `<StreamPreview>` unmounting and remounting; a remount sends `start` without a handshake.
|
|
10
|
+
* It ends with the document (reload, navigation, `pagehide`) or when the lease ends.
|
|
11
|
+
* - The **renderer** belongs to the component and is attached here only as a draw callback.
|
|
12
|
+
*
|
|
13
|
+
* Control is desired-state: the component says which mount epoch wants which tier and whether it
|
|
14
|
+
* wants frames, and `sync()` sends the difference to the host over `_preview`. A new document
|
|
15
|
+
* always needs a new handshake; a new mount never does.
|
|
16
|
+
*/
|
|
17
|
+
import type { PreviewControlChannel } from "./controlChannel";
|
|
18
|
+
import { type CreditLoopStats } from "./creditLoop";
|
|
19
|
+
import type { ParsedFrame } from "./protocol";
|
|
20
|
+
import { type PreviewTier } from "./tiers";
|
|
21
|
+
import { type PreviewTransport, type PreviewTransportOptions } from "./transport";
|
|
22
|
+
/** The only control protocol this SDK speaks. Anything else is reported as `unsupported`. */
|
|
23
|
+
export declare const PREVIEW_PROTOCOL_VERSION = 1;
|
|
24
|
+
export type PreviewConnectionState =
|
|
25
|
+
/** No handshake attempted yet in this document, or the lease ended and nobody wants frames. */
|
|
26
|
+
"idle" | "handshaking"
|
|
27
|
+
/** The host has no lease for this miniapp yet. Not an error: `lease_available` will follow. */
|
|
28
|
+
| "waiting_for_lease" | "connecting" | "open"
|
|
29
|
+
/** A failure that a re-handshake may fix (transport lost, ack timeout, host refused). */
|
|
30
|
+
| "error"
|
|
31
|
+
/** Terminal for this document: unknown protocol version or missing platform support. */
|
|
32
|
+
| "unsupported"
|
|
33
|
+
/** Not running inside a Mentra App WebView. */
|
|
34
|
+
| "unavailable" | "closed";
|
|
35
|
+
export interface PreviewConnectionStateDetail {
|
|
36
|
+
code?: string;
|
|
37
|
+
reason?: string;
|
|
38
|
+
paused?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** What a mounted `<StreamPreview>` gives the connection. */
|
|
41
|
+
export interface PreviewSink {
|
|
42
|
+
readonly mountEpoch: number;
|
|
43
|
+
/** Submit one frame; null when the renderer has no usable context. */
|
|
44
|
+
draw(frame: ParsedFrame): number | null;
|
|
45
|
+
onState(state: PreviewConnectionState, detail: PreviewConnectionStateDetail): void;
|
|
46
|
+
onStatus(status: Record<string, unknown>): void;
|
|
47
|
+
onError(code: string): void;
|
|
48
|
+
}
|
|
49
|
+
export interface PreviewDesiredState {
|
|
50
|
+
/** Rendered box in device pixels; only sent when `tier` changes. */
|
|
51
|
+
boxWidth: number;
|
|
52
|
+
boxHeight: number;
|
|
53
|
+
/** Null means hidden (zero-size box). */
|
|
54
|
+
tier: PreviewTier | null;
|
|
55
|
+
/** False while the page is hidden (`visibilitychange`) or the component is unmounting. */
|
|
56
|
+
running: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface PreviewConnectionCounters {
|
|
59
|
+
handshakes: number;
|
|
60
|
+
reconnects: number;
|
|
61
|
+
staleReplies: number;
|
|
62
|
+
staleLocalOps: number;
|
|
63
|
+
tierChanges: number;
|
|
64
|
+
page: CreditLoopStats;
|
|
65
|
+
}
|
|
66
|
+
export interface PreviewConnectionDeps {
|
|
67
|
+
channel: PreviewControlChannel | null;
|
|
68
|
+
createTransport?: (transport: "websocket" | "webmessage", options: PreviewTransportOptions) => PreviewTransport;
|
|
69
|
+
now?: () => number;
|
|
70
|
+
/** Document event hookup; defaults to the real `document`/`window`. */
|
|
71
|
+
listen?: (target: "document" | "window", type: string, handler: () => void) => () => void;
|
|
72
|
+
isDocumentVisible?: () => boolean;
|
|
73
|
+
}
|
|
74
|
+
export declare class PreviewConnection {
|
|
75
|
+
private readonly deps;
|
|
76
|
+
private state;
|
|
77
|
+
private detail;
|
|
78
|
+
private docGen;
|
|
79
|
+
private config;
|
|
80
|
+
private transport;
|
|
81
|
+
/** Bumped whenever the transport is dropped, so a stale async continuation can tell. */
|
|
82
|
+
private connectionGen;
|
|
83
|
+
private mountEpochCounter;
|
|
84
|
+
private latestEpoch;
|
|
85
|
+
private sink;
|
|
86
|
+
private desired;
|
|
87
|
+
private applied;
|
|
88
|
+
/** Epoch whose production the host halted on a non-recoverable error; not restarted until remount. */
|
|
89
|
+
private haltedEpoch;
|
|
90
|
+
private handshaking;
|
|
91
|
+
private opChain;
|
|
92
|
+
private reconnectTimes;
|
|
93
|
+
private paused;
|
|
94
|
+
private readonly creditLoop;
|
|
95
|
+
private readonly createTransport;
|
|
96
|
+
private readonly now;
|
|
97
|
+
private readonly isVisible;
|
|
98
|
+
private readonly unsubscribers;
|
|
99
|
+
private counters;
|
|
100
|
+
constructor(deps: PreviewConnectionDeps);
|
|
101
|
+
get currentState(): PreviewConnectionState;
|
|
102
|
+
get documentGeneration(): number;
|
|
103
|
+
snapshot(): PreviewConnectionCounters;
|
|
104
|
+
/** A fresh, strictly increasing epoch for a component mounting in this document. */
|
|
105
|
+
nextMountEpoch(): number;
|
|
106
|
+
/**
|
|
107
|
+
* Route frames to this component's renderer. The newest mount wins; an older sink detaching
|
|
108
|
+
* later cannot remove a newer one.
|
|
109
|
+
*/
|
|
110
|
+
attach(sink: PreviewSink): () => void;
|
|
111
|
+
/** Declare what `mountEpoch` wants. Operations from a superseded epoch are ignored. */
|
|
112
|
+
update(mountEpoch: number, state: PreviewDesiredState): void;
|
|
113
|
+
reportRendererError(mountEpoch: number, message: string): void;
|
|
114
|
+
/** End of document. The lease is untouched; a new document will handshake again. */
|
|
115
|
+
close(reason: string): void;
|
|
116
|
+
/** Test seam: detach from the channel and document. */
|
|
117
|
+
dispose(): void;
|
|
118
|
+
private sync;
|
|
119
|
+
private wantsFrames;
|
|
120
|
+
private syncOnce;
|
|
121
|
+
/** False when the host dropped the op as stale; our identity is then out of date. */
|
|
122
|
+
private accept;
|
|
123
|
+
private send;
|
|
124
|
+
private ensureOpen;
|
|
125
|
+
private handshake;
|
|
126
|
+
private openTransport;
|
|
127
|
+
private handleTransportError;
|
|
128
|
+
private handleHostEvent;
|
|
129
|
+
private handleHostError;
|
|
130
|
+
private handleVisibility;
|
|
131
|
+
private scheduleReconnect;
|
|
132
|
+
private dropTransport;
|
|
133
|
+
private setState;
|
|
134
|
+
}
|
|
135
|
+
/** The connection for this document, created on first use. */
|
|
136
|
+
export declare function getPreviewConnection(): PreviewConnection;
|
|
137
|
+
/** Test seam: replace (or clear) the document singleton, as a reload would. */
|
|
138
|
+
export declare function setPreviewConnectionForTests(next: PreviewConnection | null): void;
|
|
139
|
+
//# sourceMappingURL=PreviewConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreviewConnection.d.ts","sourceRoot":"","sources":["../../../src/react/stream-preview/PreviewConnection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EACV,qBAAqB,EAMtB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAa,KAAK,eAAe,EAAC,MAAM,cAAc,CAAA;AAC7D,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAW,KAAK,WAAW,EAAC,MAAM,SAAS,CAAA;AAElD,OAAO,EAAqC,KAAK,gBAAgB,EAAE,KAAK,uBAAuB,EAAC,MAAM,aAAa,CAAA;AAEnH,6FAA6F;AAC7F,eAAO,MAAM,wBAAwB,IAAI,CAAA;AAQzC,MAAM,MAAM,sBAAsB;AAChC,+FAA+F;AAC7F,MAAM,GACN,aAAa;AACf,+FAA+F;GAC7F,mBAAmB,GACnB,YAAY,GACZ,MAAM;AACR,yFAAyF;GACvF,OAAO;AACT,wFAAwF;GACtF,aAAa;AACf,+CAA+C;GAC7C,aAAa,GACb,QAAQ,CAAA;AAEZ,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,6DAA6D;AAC7D,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,sEAAsE;IACtE,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAAA;IACvC,OAAO,CAAC,KAAK,EAAE,sBAAsB,EAAE,MAAM,EAAE,4BAA4B,GAAG,IAAI,CAAA;IAClF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OA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