nucleus-core-ts 0.10.236 → 0.10.238
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/.build-ok +1 -1
- package/dist/fe/components/Replay/_hooks/index.d.ts +1 -0
- package/dist/fe/components/Replay/_hooks/index.js +1 -0
- package/dist/fe/components/Replay/_hooks/useReplayPlayer.d.ts +6 -0
- package/dist/fe/components/Replay/_hooks/useReplayPlayer.js +63 -0
- package/dist/fe/components/Replay/_store/index.d.ts +1 -0
- package/dist/fe/components/Replay/_store/index.js +1 -0
- package/dist/fe/components/Replay/_store/replayStore.d.ts +13 -0
- package/dist/fe/components/Replay/_store/replayStore.js +74 -0
- package/dist/fe/components/Replay/_types/index.d.ts +1 -0
- package/dist/fe/components/Replay/_types/index.js +1 -0
- package/dist/fe/components/Replay/_types/player.d.ts +105 -0
- package/dist/fe/components/Replay/_types/player.js +1 -0
- package/dist/fe/components/Replay/_utils/controller.d.ts +10 -0
- package/dist/fe/components/Replay/_utils/controller.js +208 -0
- package/dist/fe/components/Replay/_utils/controllerReports.d.ts +18 -0
- package/dist/fe/components/Replay/_utils/controllerReports.js +70 -0
- package/dist/fe/components/Replay/_utils/frameBridge.d.ts +40 -0
- package/dist/fe/components/Replay/_utils/frameBridge.js +167 -0
- package/dist/fe/components/Replay/_utils/framePoints.d.ts +17 -0
- package/dist/fe/components/Replay/_utils/framePoints.js +24 -0
- package/dist/fe/components/Replay/_utils/frameUrl.d.ts +21 -0
- package/dist/fe/components/Replay/_utils/frameUrl.js +23 -0
- package/dist/fe/components/Replay/_utils/index.d.ts +4 -0
- package/dist/fe/components/Replay/_utils/index.js +4 -0
- package/dist/fe/components/Replay/index.d.ts +4 -0
- package/dist/fe/components/Replay/index.js +4 -0
- package/dist/nucleus.config.d.ts +1 -0
- package/dist/src/Client/Replay/answers/aliases.d.ts +20 -0
- package/dist/src/Client/Replay/answers/aliases.js +57 -0
- package/dist/src/Client/Replay/answers/factory.d.ts +24 -0
- package/dist/src/Client/Replay/answers/factory.js +97 -0
- package/dist/src/Client/Replay/answers/index.d.ts +2 -0
- package/dist/src/Client/Replay/answers/index.js +2 -0
- package/dist/src/Client/Replay/answers/match.d.ts +34 -0
- package/dist/src/Client/Replay/answers/match.js +33 -0
- package/dist/src/Client/Replay/channel/channel.d.ts +144 -0
- package/dist/src/Client/Replay/channel/channel.js +150 -0
- package/dist/src/Client/Replay/channel/index.d.ts +1 -0
- package/dist/src/Client/Replay/channel/index.js +1 -0
- package/dist/src/Client/Replay/contract/index.d.ts +4 -0
- package/dist/src/Client/Replay/contract/index.js +4 -0
- package/dist/src/Client/Replay/contract/parse.d.ts +12 -0
- package/dist/src/Client/Replay/contract/parse.js +98 -0
- package/dist/src/Client/Replay/contract/schema.d.ts +290 -0
- package/dist/src/Client/Replay/contract/schema.js +256 -0
- package/dist/src/Client/Replay/contract/types.d.ts +197 -0
- package/dist/src/Client/Replay/contract/types.js +10 -0
- package/dist/src/Client/Replay/contract/v1.d.ts +72 -0
- package/dist/src/Client/Replay/contract/v1.js +70 -0
- package/dist/src/Client/Replay/driver/actions.d.ts +27 -0
- package/dist/src/Client/Replay/driver/actions.js +55 -0
- package/dist/src/Client/Replay/driver/choose.d.ts +15 -0
- package/dist/src/Client/Replay/driver/choose.js +46 -0
- package/dist/src/Client/Replay/driver/find.d.ts +44 -0
- package/dist/src/Client/Replay/driver/find.js +109 -0
- package/dist/src/Client/Replay/driver/index.d.ts +5 -0
- package/dist/src/Client/Replay/driver/index.js +5 -0
- package/dist/src/Client/Replay/driver/input.d.ts +21 -0
- package/dist/src/Client/Replay/driver/input.js +120 -0
- package/dist/src/Client/Replay/driver/run.d.ts +30 -0
- package/dist/src/Client/Replay/driver/run.js +66 -0
- package/dist/src/Client/Replay/index.d.ts +8 -0
- package/dist/src/Client/Replay/index.js +8 -0
- package/dist/src/Client/Replay/realm/clock.d.ts +16 -0
- package/dist/src/Client/Replay/realm/clock.js +19 -0
- package/dist/src/Client/Replay/realm/fetchRouter.d.ts +25 -0
- package/dist/src/Client/Replay/realm/fetchRouter.js +46 -0
- package/dist/src/Client/Replay/realm/frame.d.ts +40 -0
- package/dist/src/Client/Replay/realm/frame.js +38 -0
- package/dist/src/Client/Replay/realm/index.d.ts +5 -0
- package/dist/src/Client/Replay/realm/index.js +5 -0
- package/dist/src/Client/Replay/realm/install.d.ts +26 -0
- package/dist/src/Client/Replay/realm/install.js +27 -0
- package/dist/src/Client/Replay/realm/storage.d.ts +14 -0
- package/dist/src/Client/Replay/realm/storage.js +51 -0
- package/dist/src/Client/Replay/recorder/anchors.d.ts +18 -0
- package/dist/src/Client/Replay/recorder/anchors.js +39 -0
- package/dist/src/Client/Replay/recorder/bundle.d.ts +60 -0
- package/dist/src/Client/Replay/recorder/bundle.js +103 -0
- package/dist/src/Client/Replay/recorder/clock.d.ts +13 -0
- package/dist/src/Client/Replay/recorder/clock.js +9 -0
- package/dist/src/Client/Replay/recorder/factoryTap.d.ts +22 -0
- package/dist/src/Client/Replay/recorder/factoryTap.js +24 -0
- package/dist/src/Client/Replay/recorder/fetchTee.d.ts +37 -0
- package/dist/src/Client/Replay/recorder/fetchTee.js +121 -0
- package/dist/src/Client/Replay/recorder/index.d.ts +9 -0
- package/dist/src/Client/Replay/recorder/index.js +9 -0
- package/dist/src/Client/Replay/recorder/privacy.d.ts +27 -0
- package/dist/src/Client/Replay/recorder/privacy.js +115 -0
- package/dist/src/Client/Replay/recorder/redact.d.ts +8 -0
- package/dist/src/Client/Replay/recorder/redact.js +100 -0
- package/dist/src/Client/Replay/recorder/socketTap.d.ts +21 -0
- package/dist/src/Client/Replay/recorder/socketTap.js +43 -0
- package/dist/src/Client/Replay/recorder/sse.d.ts +15 -0
- package/dist/src/Client/Replay/recorder/sse.js +56 -0
- package/dist/src/Client/Replay/recorder/steps.d.ts +27 -0
- package/dist/src/Client/Replay/recorder/steps.js +152 -0
- package/dist/src/Client/Replay/streams/delivery.d.ts +9 -0
- package/dist/src/Client/Replay/streams/delivery.js +28 -0
- package/dist/src/Client/Replay/streams/emit.d.ts +16 -0
- package/dist/src/Client/Replay/streams/emit.js +66 -0
- package/dist/src/Client/Replay/streams/eventSource.d.ts +29 -0
- package/dist/src/Client/Replay/streams/eventSource.js +63 -0
- package/dist/src/Client/Replay/streams/index.d.ts +6 -0
- package/dist/src/Client/Replay/streams/index.js +6 -0
- package/dist/src/Client/Replay/streams/path.d.ts +10 -0
- package/dist/src/Client/Replay/streams/path.js +28 -0
- package/dist/src/Client/Replay/streams/schedule.d.ts +17 -0
- package/dist/src/Client/Replay/streams/schedule.js +39 -0
- package/dist/src/Client/Replay/streams/socket.d.ts +36 -0
- package/dist/src/Client/Replay/streams/socket.js +104 -0
- package/dist/src/Client/Replay/streams/sse.d.ts +20 -0
- package/dist/src/Client/Replay/streams/sse.js +65 -0
- package/dist/src/Client/Replay/timeline/clock.d.ts +8 -0
- package/dist/src/Client/Replay/timeline/clock.js +22 -0
- package/dist/src/Client/Replay/timeline/fakeClock.d.ts +7 -0
- package/dist/src/Client/Replay/timeline/fakeClock.js +43 -0
- package/dist/src/Client/Replay/timeline/index.d.ts +3 -0
- package/dist/src/Client/Replay/timeline/index.js +3 -0
- package/dist/src/Client/Replay/timeline/loader.d.ts +20 -0
- package/dist/src/Client/Replay/timeline/loader.js +84 -0
- package/dist/src/Client/Replay/timeline/timeline.d.ts +36 -0
- package/dist/src/Client/Replay/timeline/timeline.js +149 -0
- package/package.json +5 -1
package/dist/.build-ok
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.10.
|
|
1
|
+
0.10.238
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useReplayPlayer';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useReplayPlayer';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReplayPlayer, ReplayPlayerOptions } from '../_types';
|
|
2
|
+
/**
|
|
3
|
+
* Runs one replay in the page: loads the manifest, hands out the iframe URL, and keeps the player store in step
|
|
4
|
+
* with the frame. The stage renders `<iframe ref={frameRef} src={frameSrc}>`; controls call the returned functions.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useReplayPlayer(options: ReplayPlayerOptions): ReplayPlayer;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useEffectEvent, useRef, useState } from 'react';
|
|
3
|
+
import { useReplayStore } from '../_store';
|
|
4
|
+
import { createReplayController, createReplayNonce } from '../_utils/controller';
|
|
5
|
+
import { replayFrameUrl } from '../_utils/frameUrl';
|
|
6
|
+
/**
|
|
7
|
+
* Runs one replay in the page: loads the manifest, hands out the iframe URL, and keeps the player store in step
|
|
8
|
+
* with the frame. The stage renders `<iframe ref={frameRef} src={frameSrc}>`; controls call the returned functions.
|
|
9
|
+
*/ export function useReplayPlayer(options) {
|
|
10
|
+
const { manifestUrl, locale, autoplay } = options;
|
|
11
|
+
const state = useReplayStore();
|
|
12
|
+
const frameRef = useRef(null);
|
|
13
|
+
const controllerRef = useRef(null);
|
|
14
|
+
const [nonce] = useState(createReplayNonce);
|
|
15
|
+
const open = useEffectEvent(()=>{
|
|
16
|
+
state.reset();
|
|
17
|
+
if (locale) state.setLocale(locale);
|
|
18
|
+
const controller = createReplayController({
|
|
19
|
+
frameWindow: ()=>frameRef.current?.contentWindow ?? null,
|
|
20
|
+
origin: window.location.origin,
|
|
21
|
+
manifestUrl,
|
|
22
|
+
nonce,
|
|
23
|
+
store: state
|
|
24
|
+
});
|
|
25
|
+
controllerRef.current = controller;
|
|
26
|
+
return ()=>{
|
|
27
|
+
controller.dispose();
|
|
28
|
+
controllerRef.current = null;
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
const applyLocale = useEffectEvent((next)=>controllerRef.current?.setLocale(next));
|
|
32
|
+
const autoStart = useEffectEvent(()=>controllerRef.current?.play());
|
|
33
|
+
useEffect(()=>open(), [
|
|
34
|
+
manifestUrl
|
|
35
|
+
]);
|
|
36
|
+
useEffect(()=>{
|
|
37
|
+
if (locale) applyLocale(locale);
|
|
38
|
+
}, [
|
|
39
|
+
locale
|
|
40
|
+
]);
|
|
41
|
+
useEffect(()=>{
|
|
42
|
+
if (autoplay && state.status === 'ready') autoStart();
|
|
43
|
+
}, [
|
|
44
|
+
autoplay,
|
|
45
|
+
state.status
|
|
46
|
+
]);
|
|
47
|
+
const manifest = state.manifest;
|
|
48
|
+
return {
|
|
49
|
+
frameRef,
|
|
50
|
+
frameSrc: manifest ? replayFrameUrl({
|
|
51
|
+
startPath: manifest.startPath,
|
|
52
|
+
recordingId: manifest.id,
|
|
53
|
+
nonce
|
|
54
|
+
}) : null,
|
|
55
|
+
state,
|
|
56
|
+
play: ()=>controllerRef.current?.play(),
|
|
57
|
+
pause: ()=>controllerRef.current?.pause(),
|
|
58
|
+
setRate: (rate)=>controllerRef.current?.setRate(rate),
|
|
59
|
+
seekChapter: (chapterId)=>controllerRef.current?.seekChapter(chapterId),
|
|
60
|
+
setLocale: (next)=>controllerRef.current?.setLocale(next),
|
|
61
|
+
cursorArrived: (mark)=>controllerRef.current?.cursorArrived(mark)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './replayStore';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './replayStore';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReplayPlayerMethods, ReplayPlayerState } from '../_types';
|
|
2
|
+
export declare const initialReplayState: ReplayPlayerState;
|
|
3
|
+
type Creators = {
|
|
4
|
+
[K in keyof ReplayPlayerMethods]: (s: ReplayPlayerState) => ReplayPlayerMethods[K];
|
|
5
|
+
};
|
|
6
|
+
/** The store's methods as creators over a plain state object, so tests can run them without React. */
|
|
7
|
+
export declare const replayMethodCreators: Creators;
|
|
8
|
+
/**
|
|
9
|
+
* The one active replay: the controller writes it from the frame's messages, the stage and controls read it.
|
|
10
|
+
* The hook passes the live store object (`useReplayStore()`) to the controller.
|
|
11
|
+
*/
|
|
12
|
+
export declare const useReplayStore: () => import("h-state").StoreType<ReplayPlayerState, ReplayPlayerMethods>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createStore } from 'h-state';
|
|
3
|
+
export const initialReplayState = {
|
|
4
|
+
status: 'loading',
|
|
5
|
+
manifest: null,
|
|
6
|
+
chapterId: null,
|
|
7
|
+
stepId: null,
|
|
8
|
+
caption: null,
|
|
9
|
+
playhead: 0,
|
|
10
|
+
rate: 1,
|
|
11
|
+
locale: 'en',
|
|
12
|
+
cursor: null,
|
|
13
|
+
unanswered: [],
|
|
14
|
+
failure: null
|
|
15
|
+
};
|
|
16
|
+
/** The store's methods as creators over a plain state object, so tests can run them without React. */ export const replayMethodCreators = {
|
|
17
|
+
reset: (s)=>()=>{
|
|
18
|
+
Object.assign(s, {
|
|
19
|
+
...initialReplayState,
|
|
20
|
+
unanswered: [],
|
|
21
|
+
locale: s.locale
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
setManifest: (s)=>(manifest)=>{
|
|
25
|
+
s.manifest = manifest;
|
|
26
|
+
s.chapterId = manifest.chapters[0]?.id ?? null;
|
|
27
|
+
s.rate = manifest.chapters[0]?.rate ?? 1;
|
|
28
|
+
},
|
|
29
|
+
setStatus: (s)=>(status)=>{
|
|
30
|
+
s.status = status;
|
|
31
|
+
},
|
|
32
|
+
setChapter: (s)=>(chapterId)=>{
|
|
33
|
+
s.chapterId = chapterId;
|
|
34
|
+
},
|
|
35
|
+
startStep: (s)=>(stepId, caption)=>{
|
|
36
|
+
s.stepId = stepId;
|
|
37
|
+
s.caption = caption;
|
|
38
|
+
},
|
|
39
|
+
clearStep: (s)=>()=>{
|
|
40
|
+
s.stepId = null;
|
|
41
|
+
s.caption = null;
|
|
42
|
+
s.cursor = null;
|
|
43
|
+
},
|
|
44
|
+
setPlayhead: (s)=>(playhead)=>{
|
|
45
|
+
s.playhead = playhead;
|
|
46
|
+
},
|
|
47
|
+
setRate: (s)=>(rate)=>{
|
|
48
|
+
s.rate = rate;
|
|
49
|
+
},
|
|
50
|
+
setLocale: (s)=>(locale)=>{
|
|
51
|
+
s.locale = locale;
|
|
52
|
+
},
|
|
53
|
+
setCursor: (s)=>(cursor)=>{
|
|
54
|
+
s.cursor = cursor;
|
|
55
|
+
},
|
|
56
|
+
reportUnanswered: (s)=>(key)=>{
|
|
57
|
+
if (!s.unanswered.includes(key)) s.unanswered = [
|
|
58
|
+
...s.unanswered,
|
|
59
|
+
key
|
|
60
|
+
];
|
|
61
|
+
},
|
|
62
|
+
fail: (s)=>(failure)=>{
|
|
63
|
+
s.failure = failure;
|
|
64
|
+
s.status = 'failed';
|
|
65
|
+
s.cursor = null;
|
|
66
|
+
},
|
|
67
|
+
clearFailure: (s)=>()=>{
|
|
68
|
+
s.failure = null;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The one active replay: the controller writes it from the frame's messages, the stage and controls read it.
|
|
73
|
+
* The hook passes the live store object (`useReplayStore()`) to the controller.
|
|
74
|
+
*/ export const { useStore: useReplayStore } = createStore(initialReplayState, replayMethodCreators);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './player';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './player';
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
import type { FailureReason, Localized, Ms, PointBox, ReplayManifest } from '../../../../src/Client/Replay';
|
|
3
|
+
export type ReplayStatus = 'loading' | 'ready' | 'playing' | 'paused' | 'ended' | 'failed';
|
|
4
|
+
/** Why playback stopped: a driver failure, or one of the player's own load and handshake failures. */
|
|
5
|
+
export type ReplayFailureReason = FailureReason | 'manifest_unreachable' | 'manifest_invalid' | 'frame_timeout';
|
|
6
|
+
export interface ReplayFailure {
|
|
7
|
+
reason: ReplayFailureReason;
|
|
8
|
+
stepId: string | null;
|
|
9
|
+
actionIndex: number | null;
|
|
10
|
+
/** Validation issues or the HTTP status; for logs, never for display. */
|
|
11
|
+
detail: string | null;
|
|
12
|
+
}
|
|
13
|
+
/** The box the frame reported for the current pointer action; `arrived` flips once the drawn cursor got there. */
|
|
14
|
+
export interface ReplayCursor {
|
|
15
|
+
stepId: string;
|
|
16
|
+
mark: number;
|
|
17
|
+
box: PointBox;
|
|
18
|
+
arrived: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type ReplayPlayerState = {
|
|
21
|
+
status: ReplayStatus;
|
|
22
|
+
manifest: ReplayManifest | null;
|
|
23
|
+
chapterId: string | null;
|
|
24
|
+
stepId: string | null;
|
|
25
|
+
/** Caption of the current step in every language it has; pick one with `pickLocalized`. */
|
|
26
|
+
caption: Localized | null;
|
|
27
|
+
playhead: Ms;
|
|
28
|
+
rate: number;
|
|
29
|
+
locale: string;
|
|
30
|
+
cursor: ReplayCursor | null;
|
|
31
|
+
/** Endpoint keys the recording could not answer, each once: the audit wants none. */
|
|
32
|
+
unanswered: string[];
|
|
33
|
+
failure: ReplayFailure | null;
|
|
34
|
+
};
|
|
35
|
+
export type ReplayPlayerMethods = {
|
|
36
|
+
reset: () => void;
|
|
37
|
+
setManifest: (manifest: ReplayManifest) => void;
|
|
38
|
+
setStatus: (status: ReplayStatus) => void;
|
|
39
|
+
setChapter: (chapterId: string | null) => void;
|
|
40
|
+
startStep: (stepId: string, caption: Localized) => void;
|
|
41
|
+
clearStep: () => void;
|
|
42
|
+
setPlayhead: (playhead: Ms) => void;
|
|
43
|
+
setRate: (rate: number) => void;
|
|
44
|
+
setLocale: (locale: string) => void;
|
|
45
|
+
setCursor: (cursor: ReplayCursor | null) => void;
|
|
46
|
+
reportUnanswered: (key: string) => void;
|
|
47
|
+
fail: (failure: ReplayFailure) => void;
|
|
48
|
+
clearFailure: () => void;
|
|
49
|
+
};
|
|
50
|
+
/** What the controller reads and writes; the h-state store satisfies it, and so can a plain object in a test. */
|
|
51
|
+
export type ReplayStoreApi = ReplayPlayerState & ReplayPlayerMethods;
|
|
52
|
+
/** The window the player talks to: the iframe's `contentWindow`. */
|
|
53
|
+
export interface ReplayFrameTarget {
|
|
54
|
+
postMessage: (message: object, targetOrigin: string) => void;
|
|
55
|
+
}
|
|
56
|
+
/** The window the player listens on: the page's own `window`. */
|
|
57
|
+
export interface ReplayListenTarget {
|
|
58
|
+
addEventListener: (type: 'message', listener: (event: MessageEvent) => void) => void;
|
|
59
|
+
removeEventListener: (type: 'message', listener: (event: MessageEvent) => void) => void;
|
|
60
|
+
}
|
|
61
|
+
export interface ReplayControllerOptions {
|
|
62
|
+
/** Read on every use so a re-created iframe is followed; null until the iframe exists. */
|
|
63
|
+
frameWindow: () => ReplayFrameTarget | null;
|
|
64
|
+
/** The page's origin; the frame is same-origin, anything else is ignored. */
|
|
65
|
+
origin: string;
|
|
66
|
+
/** The recording folder's `manifest.json` URL. */
|
|
67
|
+
manifestUrl: string;
|
|
68
|
+
/** The session nonce; the same value is in the frame's URL (`replayFrameUrl`). */
|
|
69
|
+
nonce: string;
|
|
70
|
+
store: ReplayStoreApi;
|
|
71
|
+
/** Real-time timers (hello retries, handshake timeout); tests pass a fake. */
|
|
72
|
+
clock?: {
|
|
73
|
+
setTimeout: (run: () => void, ms: number) => number;
|
|
74
|
+
clearTimeout: (id: number) => void;
|
|
75
|
+
};
|
|
76
|
+
fetch?: (url: string) => Promise<Response>;
|
|
77
|
+
listenWindow?: ReplayListenTarget;
|
|
78
|
+
/** Real ms to wait for the frame's `ready` before failing; default 20000. */
|
|
79
|
+
readyTimeoutMs?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface ReplayController {
|
|
82
|
+
play: () => void;
|
|
83
|
+
pause: () => void;
|
|
84
|
+
setRate: (rate: number) => void;
|
|
85
|
+
/** Chapter starts are the only seek points; an unknown id is ignored. */
|
|
86
|
+
seekChapter: (chapterId: string) => void;
|
|
87
|
+
setLocale: (locale: string) => void;
|
|
88
|
+
/** The drawn cursor reached the reported box: lets the frame's driver act. */
|
|
89
|
+
cursorArrived: (mark: number) => void;
|
|
90
|
+
dispose: () => void;
|
|
91
|
+
}
|
|
92
|
+
export interface ReplayPlayerOptions {
|
|
93
|
+
/** The recording folder's `manifest.json` URL. */
|
|
94
|
+
manifestUrl: string;
|
|
95
|
+
locale?: string;
|
|
96
|
+
/** Start playing as soon as the frame is ready. */
|
|
97
|
+
autoplay?: boolean;
|
|
98
|
+
}
|
|
99
|
+
/** What `useReplayPlayer` hands to the stage and controls: render the iframe from `frameRef` + `frameSrc`, read `state`. */
|
|
100
|
+
export interface ReplayPlayer extends Omit<ReplayController, 'dispose'> {
|
|
101
|
+
frameRef: RefObject<HTMLIFrameElement | null>;
|
|
102
|
+
/** The iframe URL; null until the manifest is loaded. */
|
|
103
|
+
frameSrc: string | null;
|
|
104
|
+
state: ReplayPlayerState;
|
|
105
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/** What `useReplayPlayer` hands to the stage and controls: render the iframe from `frameRef` + `frameSrc`, read `state`. */ export { };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createNonce } from '../../../../src/Client/Replay';
|
|
2
|
+
import type { ReplayController, ReplayControllerOptions } from '../_types';
|
|
3
|
+
/** A fresh session nonce for a player; the frame's URL carries the same value. */
|
|
4
|
+
export declare const createReplayNonce: typeof createNonce;
|
|
5
|
+
/**
|
|
6
|
+
* The parent side of a replay. Loads and validates the manifest, performs the handshake with the frame, forwards
|
|
7
|
+
* play, pause, rate and chapter seeks, and mirrors what the frame reports (steps, cursor box, playhead, failures)
|
|
8
|
+
* into the store. The frame owns the timeline and runs the steps (`startReplayFrame`); nothing here reaches the product.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createReplayController(options: ReplayControllerOptions): ReplayController;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { createNonce, envelopeFor, parseManifest, readFrameMessage, sendMessage } from '../../../../src/Client/Replay';
|
|
2
|
+
import { createReportHandler, enterChapter } from './controllerReports';
|
|
3
|
+
const HELLO_INTERVAL_MS = 500;
|
|
4
|
+
const READY_TIMEOUT_MS = 20000;
|
|
5
|
+
const MAX_RATE = 64;
|
|
6
|
+
const realClock = {
|
|
7
|
+
setTimeout: (run, ms)=>Number(setTimeout(run, ms)),
|
|
8
|
+
clearTimeout: (id)=>clearTimeout(id)
|
|
9
|
+
};
|
|
10
|
+
/** A fresh session nonce for a player; the frame's URL carries the same value. */ export const createReplayNonce = createNonce;
|
|
11
|
+
/**
|
|
12
|
+
* The parent side of a replay. Loads and validates the manifest, performs the handshake with the frame, forwards
|
|
13
|
+
* play, pause, rate and chapter seeks, and mirrors what the frame reports (steps, cursor box, playhead, failures)
|
|
14
|
+
* into the store. The frame owns the timeline and runs the steps (`startReplayFrame`); nothing here reaches the product.
|
|
15
|
+
*/ export function createReplayController(options) {
|
|
16
|
+
const { store, origin, nonce } = options;
|
|
17
|
+
const clock = options.clock ?? realClock;
|
|
18
|
+
const listen = options.listenWindow ?? window;
|
|
19
|
+
const load = options.fetch ?? ((url)=>fetch(url));
|
|
20
|
+
const wants = {
|
|
21
|
+
playing: false,
|
|
22
|
+
rate: null,
|
|
23
|
+
seekAt: null
|
|
24
|
+
};
|
|
25
|
+
const timers = new Set();
|
|
26
|
+
let ready = false;
|
|
27
|
+
let disposed = false;
|
|
28
|
+
const after = (ms, run)=>{
|
|
29
|
+
const id = clock.setTimeout(()=>{
|
|
30
|
+
timers.delete(id);
|
|
31
|
+
run();
|
|
32
|
+
}, ms);
|
|
33
|
+
timers.add(id);
|
|
34
|
+
return id;
|
|
35
|
+
};
|
|
36
|
+
const cancel = (id)=>{
|
|
37
|
+
clock.clearTimeout(id);
|
|
38
|
+
timers.delete(id);
|
|
39
|
+
};
|
|
40
|
+
const send = (build)=>{
|
|
41
|
+
const frame = options.frameWindow();
|
|
42
|
+
if (frame) sendMessage(frame, origin, build(envelopeFor(nonce)));
|
|
43
|
+
};
|
|
44
|
+
const failWith = (reason, detail)=>{
|
|
45
|
+
store.fail({
|
|
46
|
+
reason,
|
|
47
|
+
detail,
|
|
48
|
+
stepId: null,
|
|
49
|
+
actionIndex: null
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const flush = ()=>{
|
|
53
|
+
const seekAt = wants.seekAt;
|
|
54
|
+
if (seekAt !== null) send((e)=>({
|
|
55
|
+
...e,
|
|
56
|
+
type: 'seek',
|
|
57
|
+
at: seekAt
|
|
58
|
+
}));
|
|
59
|
+
wants.seekAt = null;
|
|
60
|
+
const rate = wants.rate;
|
|
61
|
+
if (rate !== null) send((e)=>({
|
|
62
|
+
...e,
|
|
63
|
+
type: 'rate',
|
|
64
|
+
rate
|
|
65
|
+
}));
|
|
66
|
+
if (wants.playing) send((e)=>({
|
|
67
|
+
...e,
|
|
68
|
+
type: 'play'
|
|
69
|
+
}));
|
|
70
|
+
};
|
|
71
|
+
const handle = createReportHandler({
|
|
72
|
+
store,
|
|
73
|
+
send,
|
|
74
|
+
isReady: ()=>ready,
|
|
75
|
+
chosenRate: ()=>wants.rate,
|
|
76
|
+
stopPlaying: ()=>{
|
|
77
|
+
wants.playing = false;
|
|
78
|
+
},
|
|
79
|
+
onReady: (recordingId)=>{
|
|
80
|
+
if (recordingId !== store.manifest?.id) return;
|
|
81
|
+
const first = !ready;
|
|
82
|
+
ready = true;
|
|
83
|
+
if (first) store.setStatus(wants.playing ? 'playing' : 'ready');
|
|
84
|
+
else store.clearStep();
|
|
85
|
+
flush();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const onMessage = (event)=>{
|
|
89
|
+
const own = {
|
|
90
|
+
origin,
|
|
91
|
+
peer: options.frameWindow(),
|
|
92
|
+
nonce
|
|
93
|
+
};
|
|
94
|
+
const message = readFrameMessage({
|
|
95
|
+
origin: event.origin,
|
|
96
|
+
source: event.source,
|
|
97
|
+
data: event.data
|
|
98
|
+
}, own);
|
|
99
|
+
if (message && !disposed) handle(message);
|
|
100
|
+
};
|
|
101
|
+
listen.addEventListener('message', onMessage);
|
|
102
|
+
const awaitFrame = ()=>{
|
|
103
|
+
const giveUp = after(options.readyTimeoutMs ?? READY_TIMEOUT_MS, ()=>{
|
|
104
|
+
if (!ready) failWith('frame_timeout', null);
|
|
105
|
+
});
|
|
106
|
+
const ask = ()=>{
|
|
107
|
+
if (ready || disposed) {
|
|
108
|
+
cancel(giveUp);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
send((e)=>({
|
|
112
|
+
...e,
|
|
113
|
+
type: 'hello'
|
|
114
|
+
}));
|
|
115
|
+
after(HELLO_INTERVAL_MS, ask);
|
|
116
|
+
};
|
|
117
|
+
ask();
|
|
118
|
+
};
|
|
119
|
+
const boot = async ()=>{
|
|
120
|
+
const response = await load(options.manifestUrl).catch(()=>null);
|
|
121
|
+
if (disposed) return;
|
|
122
|
+
if (!response?.ok) {
|
|
123
|
+
failWith('manifest_unreachable', response ? String(response.status) : null);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const parsed = parseManifest(await response.text());
|
|
127
|
+
if (disposed) return;
|
|
128
|
+
if (!parsed.ok) {
|
|
129
|
+
failWith('manifest_invalid', parsed.errors.join('; '));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
store.setManifest(parsed.value);
|
|
133
|
+
awaitFrame();
|
|
134
|
+
};
|
|
135
|
+
void boot();
|
|
136
|
+
const seekChapter = (chapterId)=>{
|
|
137
|
+
const chapter = store.manifest?.chapters.find((item)=>item.id === chapterId);
|
|
138
|
+
if (!chapter) return;
|
|
139
|
+
store.clearFailure();
|
|
140
|
+
store.clearStep();
|
|
141
|
+
store.setPlayhead(chapter.from);
|
|
142
|
+
enterChapter(store, chapter, wants.rate);
|
|
143
|
+
if (!ready) {
|
|
144
|
+
wants.seekAt = chapter.from;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
send((e)=>({
|
|
148
|
+
...e,
|
|
149
|
+
type: 'seek',
|
|
150
|
+
at: chapter.from
|
|
151
|
+
}));
|
|
152
|
+
if (store.status === 'ended' || store.status === 'failed') store.setStatus('paused');
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
play () {
|
|
156
|
+
const first = store.manifest?.chapters[0];
|
|
157
|
+
if (store.status === 'ended' && first) seekChapter(first.id);
|
|
158
|
+
else if (store.status === 'failed') seekChapter(store.chapterId ?? first?.id ?? '');
|
|
159
|
+
wants.playing = true;
|
|
160
|
+
if (!ready) return;
|
|
161
|
+
send((e)=>({
|
|
162
|
+
...e,
|
|
163
|
+
type: 'play'
|
|
164
|
+
}));
|
|
165
|
+
store.setStatus('playing');
|
|
166
|
+
},
|
|
167
|
+
pause () {
|
|
168
|
+
wants.playing = false;
|
|
169
|
+
send((e)=>({
|
|
170
|
+
...e,
|
|
171
|
+
type: 'pause'
|
|
172
|
+
}));
|
|
173
|
+
if (store.status === 'playing') store.setStatus('paused');
|
|
174
|
+
},
|
|
175
|
+
setRate (rate) {
|
|
176
|
+
if (!Number.isFinite(rate) || rate <= 0 || rate > MAX_RATE) return;
|
|
177
|
+
wants.rate = rate;
|
|
178
|
+
store.setRate(rate);
|
|
179
|
+
if (ready) send((e)=>({
|
|
180
|
+
...e,
|
|
181
|
+
type: 'rate',
|
|
182
|
+
rate
|
|
183
|
+
}));
|
|
184
|
+
},
|
|
185
|
+
seekChapter,
|
|
186
|
+
setLocale: (locale)=>store.setLocale(locale),
|
|
187
|
+
cursorArrived (mark) {
|
|
188
|
+
const cursor = store.cursor;
|
|
189
|
+
if (!cursor || cursor.mark !== mark) return;
|
|
190
|
+
store.setCursor({
|
|
191
|
+
...cursor,
|
|
192
|
+
arrived: true
|
|
193
|
+
});
|
|
194
|
+
send((e)=>({
|
|
195
|
+
...e,
|
|
196
|
+
type: 'cursor-arrived',
|
|
197
|
+
mark
|
|
198
|
+
}));
|
|
199
|
+
},
|
|
200
|
+
dispose () {
|
|
201
|
+
disposed = true;
|
|
202
|
+
listen.removeEventListener('message', onMessage);
|
|
203
|
+
for (const id of [
|
|
204
|
+
...timers
|
|
205
|
+
])cancel(id);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { envelopeFor, FrameMessage, ParentMessage, ReplayChapter } from '../../../../src/Client/Replay';
|
|
2
|
+
import type { ReplayStoreApi } from '../_types';
|
|
3
|
+
export type SendToFrame = (build: (envelope: ReturnType<typeof envelopeFor>) => ParentMessage) => void;
|
|
4
|
+
export interface ReportDeps {
|
|
5
|
+
store: ReplayStoreApi;
|
|
6
|
+
send: SendToFrame;
|
|
7
|
+
/** The frame announced itself for this recording. */
|
|
8
|
+
onReady: (recordingId: string) => void;
|
|
9
|
+
isReady: () => boolean;
|
|
10
|
+
/** The visitor's intent to play ends with the run (failure, end). */
|
|
11
|
+
stopPlaying: () => void;
|
|
12
|
+
/** The rate the visitor chose, or null while the chapter's own rate shows. */
|
|
13
|
+
chosenRate: () => number | null;
|
|
14
|
+
}
|
|
15
|
+
/** Mirrors the chapter into the store; the chapter's rate shows unless the visitor chose one. */
|
|
16
|
+
export declare function enterChapter(store: ReplayStoreApi, chapter: ReplayChapter | null, chosenRate: number | null): void;
|
|
17
|
+
/** The reducer from what the frame reports to what the store shows. */
|
|
18
|
+
export declare function createReportHandler(deps: ReportDeps): (message: FrameMessage) => void;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
function chapterAt(manifest, at) {
|
|
2
|
+
return manifest.chapters.filter((chapter)=>chapter.from <= at).pop() ?? null;
|
|
3
|
+
}
|
|
4
|
+
/** Mirrors the chapter into the store; the chapter's rate shows unless the visitor chose one. */ export function enterChapter(store, chapter, chosenRate) {
|
|
5
|
+
if (!chapter || chapter.id === store.chapterId) return;
|
|
6
|
+
store.setChapter(chapter.id);
|
|
7
|
+
if (chosenRate === null) store.setRate(chapter.rate);
|
|
8
|
+
}
|
|
9
|
+
/** The reducer from what the frame reports to what the store shows. */ export function createReportHandler(deps) {
|
|
10
|
+
const { store, send } = deps;
|
|
11
|
+
const onTick = (manifest, at, playing)=>{
|
|
12
|
+
store.setPlayhead(at);
|
|
13
|
+
enterChapter(store, chapterAt(manifest, at), deps.chosenRate());
|
|
14
|
+
if (store.status === 'failed') return;
|
|
15
|
+
if (at >= manifest.clock.durationMs && !playing) {
|
|
16
|
+
deps.stopPlaying();
|
|
17
|
+
store.setStatus('ended');
|
|
18
|
+
} else if (playing) store.setStatus('playing');
|
|
19
|
+
else if (store.status === 'playing') store.setStatus('paused');
|
|
20
|
+
};
|
|
21
|
+
const onStepStarted = (manifest, stepId)=>{
|
|
22
|
+
const step = manifest.steps.find((item)=>item.id === stepId);
|
|
23
|
+
if (!step) return;
|
|
24
|
+
store.startStep(step.id, step.caption);
|
|
25
|
+
enterChapter(store, manifest.chapters.find((item)=>item.id === step.chapter) ?? null, deps.chosenRate());
|
|
26
|
+
};
|
|
27
|
+
return (message)=>{
|
|
28
|
+
const manifest = store.manifest;
|
|
29
|
+
if (message.type === 'ready') {
|
|
30
|
+
deps.onReady(message.recordingId);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!manifest || !deps.isReady()) return;
|
|
34
|
+
switch(message.type){
|
|
35
|
+
case 'step-started':
|
|
36
|
+
onStepStarted(manifest, message.stepId);
|
|
37
|
+
break;
|
|
38
|
+
case 'point':
|
|
39
|
+
store.setCursor({
|
|
40
|
+
stepId: message.stepId,
|
|
41
|
+
mark: message.mark,
|
|
42
|
+
box: message.box,
|
|
43
|
+
arrived: false
|
|
44
|
+
});
|
|
45
|
+
break;
|
|
46
|
+
case 'step-done':
|
|
47
|
+
store.setCursor(null);
|
|
48
|
+
break;
|
|
49
|
+
case 'step-failed':
|
|
50
|
+
deps.stopPlaying();
|
|
51
|
+
send((e)=>({
|
|
52
|
+
...e,
|
|
53
|
+
type: 'pause'
|
|
54
|
+
}));
|
|
55
|
+
store.fail({
|
|
56
|
+
reason: message.reason,
|
|
57
|
+
detail: null,
|
|
58
|
+
stepId: message.stepId,
|
|
59
|
+
actionIndex: message.actionIndex
|
|
60
|
+
});
|
|
61
|
+
break;
|
|
62
|
+
case 'tick':
|
|
63
|
+
onTick(manifest, message.at, message.playing);
|
|
64
|
+
break;
|
|
65
|
+
case 'unanswered':
|
|
66
|
+
store.reportUnanswered(message.key);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ReplayChapter, type ReplayManifest, type Timeline, type VisibleCheck, type Win } from '../../../../src/Client/Replay';
|
|
2
|
+
import type { ReplayFrameTarget } from '../_types';
|
|
3
|
+
export interface ReplayFrameOptions {
|
|
4
|
+
/** The frame's own window: DOM for the driver, `message` events, timers. */
|
|
5
|
+
win: Win;
|
|
6
|
+
/** The embedding page's window: where messages go and the only source accepted. */
|
|
7
|
+
parent: ReplayFrameTarget;
|
|
8
|
+
origin: string;
|
|
9
|
+
/** The session nonce from the frame's URL (`readReplayNonce`). */
|
|
10
|
+
nonce: string;
|
|
11
|
+
manifest: ReplayManifest;
|
|
12
|
+
/** The realm's timeline: the one the clock, streams and `waitUntil` run on. */
|
|
13
|
+
timeline: Timeline;
|
|
14
|
+
/** Moves the product to a path of the app (its router); resolves true once it is there. */
|
|
15
|
+
navigate: (path: string) => Promise<boolean>;
|
|
16
|
+
/** Resolves when that frame of that stream has been delivered (the realm's streams own it). */
|
|
17
|
+
waitForFrame: (stream: string, seq: number) => Promise<void>;
|
|
18
|
+
/** Resolves when the page has settled between actions; defaults to one task. */
|
|
19
|
+
settle?: () => Promise<void>;
|
|
20
|
+
/** Subscribes to calls no recorded answer covered; the bridge reports each key to the parent. */
|
|
21
|
+
onUnanswered?: (listener: (key: string) => void) => () => void;
|
|
22
|
+
/** The parent asked for a chapter: the timeline already snapped; the app may reload the frame (`?chapter=`). */
|
|
23
|
+
onSeek?: (chapter: ReplayChapter) => void;
|
|
24
|
+
/** The chapter this frame was started at (`readReplayChapter`). */
|
|
25
|
+
startChapter?: string | null;
|
|
26
|
+
typingDelayMs?: number;
|
|
27
|
+
tickMs?: number;
|
|
28
|
+
pointTimeoutMs?: number;
|
|
29
|
+
targetTimeoutMs?: number;
|
|
30
|
+
visible?: VisibleCheck;
|
|
31
|
+
}
|
|
32
|
+
export interface ReplayFrameHandle {
|
|
33
|
+
stop: () => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The frame side of a replay: answers the parent's hello, forwards play, pause, rate and seek to the timeline, runs
|
|
37
|
+
* every step through the driver when the playhead reaches its `at`, and reports started, point, done, failed and
|
|
38
|
+
* ticks. Installing the realm itself is the app's job; this only wires the channel to the driver.
|
|
39
|
+
*/
|
|
40
|
+
export declare function startReplayFrame(options: ReplayFrameOptions): ReplayFrameHandle;
|