@vitrinka/web 0.3.2 → 0.3.3
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/CHANGELOG.md +29 -0
- package/build/hud.d.ts +1 -1
- package/build/hud.iife.js +4 -4
- package/build/protocol/index.d.ts +11 -1
- package/build/recorder/control.js +2 -1
- package/build/recorder/hud/Hud.js +2 -2
- package/build/recorder/hud/RecorderPill.js +4 -1
- package/build/recorder/hud/controller.d.ts +11 -6
- package/build/recorder/hud/flow.d.ts +5 -1
- package/build/recorder/hud/flow.js +6 -1
- package/build/recorder/page-controller.js +5 -5
- package/build/recorder/queue.d.ts +24 -0
- package/build/recorder/queue.js +60 -1
- package/build/recorder/recents.d.ts +30 -0
- package/build/recorder/recents.js +53 -2
- package/build/recorder/report.d.ts +1 -0
- package/build/recorder/report.js +5 -3
- package/build/recorder/session.d.ts +2 -2
- package/build/recorder/session.js +20 -5
- package/package.json +1 -1
|
@@ -65,10 +65,20 @@ export interface SessionReconcileResponse {
|
|
|
65
65
|
status?: string;
|
|
66
66
|
deletedAt?: string | null;
|
|
67
67
|
}
|
|
68
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* PATCH response when a session completes. The board is projected AFTER the
|
|
70
|
+
* stop, so `boardUrl` is usually absent here: `projection` says how far it
|
|
71
|
+
* got, and the session read names the board once it exists.
|
|
72
|
+
*/
|
|
69
73
|
export interface SessionDone {
|
|
70
74
|
boardSlug?: string;
|
|
75
|
+
/** The board's address, minted by the server; only once the board exists. */
|
|
76
|
+
boardUrl?: string;
|
|
77
|
+
/** An older server's spelling of `boardUrl`. */
|
|
71
78
|
board?: {
|
|
72
79
|
url?: string;
|
|
73
80
|
};
|
|
81
|
+
projection?: {
|
|
82
|
+
state?: string;
|
|
83
|
+
};
|
|
74
84
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* the HUD, and read a status snapshot back.
|
|
6
6
|
*/
|
|
7
7
|
import { getState, health } from './queue';
|
|
8
|
+
import { boardUrlOf } from './recents';
|
|
8
9
|
import { addNote, elapsedOf, startSession, stopSession, togglePause } from './session';
|
|
9
10
|
export function snapshot() {
|
|
10
11
|
const rec = getState();
|
|
@@ -42,7 +43,7 @@ export function installControl() {
|
|
|
42
43
|
async stop() {
|
|
43
44
|
const captured = snapshot();
|
|
44
45
|
const done = await stopSession();
|
|
45
|
-
return { ...captured, boardUrl: done
|
|
46
|
+
return { ...captured, boardUrl: boardUrlOf(done) ?? captured.boardUrl };
|
|
46
47
|
},
|
|
47
48
|
note(text) {
|
|
48
49
|
const t = text.trim();
|
|
@@ -201,7 +201,7 @@ export function Hud({ controller, hostMount, defaultTitle, storage }) {
|
|
|
201
201
|
return;
|
|
202
202
|
sent.then((res) => {
|
|
203
203
|
setReportDraft('');
|
|
204
|
-
settle({ type: 'saved', ...
|
|
204
|
+
settle({ type: 'saved', ...res });
|
|
205
205
|
}, (e) => {
|
|
206
206
|
console.warn('vitrinka: report —', errorText(e));
|
|
207
207
|
settle({ type: 'failed', message: errorText(e) });
|
|
@@ -259,7 +259,7 @@ export function Hud({ controller, hostMount, defaultTitle, storage }) {
|
|
|
259
259
|
const runStop = useCallback(() => {
|
|
260
260
|
const t0 = Date.now();
|
|
261
261
|
const settle = (ev) => setTimeout(() => dispatch(ev), Math.max(0, MIN_SAVING_MS - (Date.now() - t0)));
|
|
262
|
-
controller.stop().then((r) => settle({ type: 'saved', ...
|
|
262
|
+
controller.stop().then((r) => settle({ type: 'saved', ...r }), (e) => {
|
|
263
263
|
console.warn('vitrinka: stop —', errorText(e));
|
|
264
264
|
settle({ type: 'failed', message: errorText(e) });
|
|
265
265
|
});
|
|
@@ -302,7 +302,10 @@ export function RecorderPill(p) {
|
|
|
302
302
|
};
|
|
303
303
|
const flowShown = shownFlow.face;
|
|
304
304
|
const confirmAction = shownFlow.face === 'confirm' ? shownFlow.action : 'stop';
|
|
305
|
-
|
|
305
|
+
// Saved before its board was built: the link arrives on the recent once the server names it.
|
|
306
|
+
const savedUrl = shownFlow.face === 'saved'
|
|
307
|
+
? (shownFlow.boardUrl ?? p.snap.recents.find((r) => r.sessionId === shownFlow.sessionId)?.boardUrl)
|
|
308
|
+
: undefined;
|
|
306
309
|
const failure = shownFlow.face === 'failed' ? shownFlow.message : '';
|
|
307
310
|
// A bug report's send: "Sending…", "Sent", "Couldn't send" — and it can always be retried.
|
|
308
311
|
const report = 'report' in shownFlow && shownFlow.report === true;
|
|
@@ -136,6 +136,15 @@ export interface HudReport {
|
|
|
136
136
|
/** The marked element's selector; '' for a region or no mark. */
|
|
137
137
|
selector: string;
|
|
138
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* What a stop or an idle report saved. `boardUrl` when the board already
|
|
141
|
+
* exists; else `sessionId` names the recent whose link the Saved face takes
|
|
142
|
+
* once the server has built the board.
|
|
143
|
+
*/
|
|
144
|
+
export interface HudSaved {
|
|
145
|
+
boardUrl?: string;
|
|
146
|
+
sessionId?: string;
|
|
147
|
+
}
|
|
139
148
|
export interface HudController {
|
|
140
149
|
getSnapshot(): HudSnapshot;
|
|
141
150
|
subscribe(listener: () => void): () => void;
|
|
@@ -144,9 +153,7 @@ export interface HudController {
|
|
|
144
153
|
}): Promise<void>;
|
|
145
154
|
togglePause(): Promise<void>;
|
|
146
155
|
/** Drains, then closes the session; rejects (session kept) while unreachable. */
|
|
147
|
-
stop(): Promise<
|
|
148
|
-
boardUrl?: string;
|
|
149
|
-
}>;
|
|
156
|
+
stop(): Promise<HudSaved>;
|
|
150
157
|
note(text: string): void;
|
|
151
158
|
annotate(a: HudAnnotation): void;
|
|
152
159
|
setAnnotating(active: boolean): void;
|
|
@@ -170,8 +177,6 @@ export interface HudController {
|
|
|
170
177
|
* second call after a rejection retries the same report. Optional: a host
|
|
171
178
|
* without it never offers the menu row.
|
|
172
179
|
*/
|
|
173
|
-
report?(r: HudReport): Promise<
|
|
174
|
-
boardUrl?: string;
|
|
175
|
-
}>;
|
|
180
|
+
report?(r: HudReport): Promise<HudSaved>;
|
|
176
181
|
}
|
|
177
182
|
export declare const DEFAULT_PREFS: HudPrefs;
|
|
@@ -25,9 +25,12 @@ export type Flow = {
|
|
|
25
25
|
face: 'saving';
|
|
26
26
|
total: number;
|
|
27
27
|
report?: true;
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
|
+
/** `sessionId` lets a face saved before its board existed take the link from recents. */
|
|
30
|
+
| {
|
|
29
31
|
face: 'saved';
|
|
30
32
|
boardUrl?: string;
|
|
33
|
+
sessionId?: string;
|
|
31
34
|
report?: true;
|
|
32
35
|
} | {
|
|
33
36
|
face: 'failed';
|
|
@@ -52,6 +55,7 @@ export type FlowEvent = {
|
|
|
52
55
|
} | {
|
|
53
56
|
type: 'saved';
|
|
54
57
|
boardUrl?: string;
|
|
58
|
+
sessionId?: string;
|
|
55
59
|
} | {
|
|
56
60
|
type: 'failed';
|
|
57
61
|
message: string;
|
|
@@ -34,7 +34,12 @@ export function flowReducer(flow, ev) {
|
|
|
34
34
|
return flow.face === 'failed' ? { face: 'saving', total: ev.queued, ...reportOf(flow) } : flow;
|
|
35
35
|
case 'saved':
|
|
36
36
|
return flow.face === 'saving'
|
|
37
|
-
? {
|
|
37
|
+
? {
|
|
38
|
+
face: 'saved',
|
|
39
|
+
...(ev.boardUrl ? { boardUrl: ev.boardUrl } : {}),
|
|
40
|
+
...(ev.sessionId ? { sessionId: ev.sessionId } : {}),
|
|
41
|
+
...reportOf(flow),
|
|
42
|
+
}
|
|
38
43
|
: flow;
|
|
39
44
|
case 'failed':
|
|
40
45
|
return flow.face === 'saving' ? { face: 'failed', message: ev.message, ...reportOf(flow) } : flow;
|
|
@@ -2,7 +2,7 @@ import { readLink, recorderConfig, vitrinkaLinked } from './config';
|
|
|
2
2
|
import { forgetLink, linkDevice } from './link';
|
|
3
3
|
import { cachedAccount, cachedPrefs, fetchMe, savePrefs } from './me';
|
|
4
4
|
import { getState, health } from './queue';
|
|
5
|
-
import { readRecents, refreshRecents } from './recents';
|
|
5
|
+
import { boardUrlOf, readRecents, refreshRecents } from './recents';
|
|
6
6
|
import { canReport, holdReport, sendReport } from './report';
|
|
7
7
|
import { addAnnotation, addNote, RECORDER_ID, startSession, stopSession, togglePause } from './session';
|
|
8
8
|
import { annotateState, setAnnotating, subscribe } from './state';
|
|
@@ -71,13 +71,13 @@ export function createPageController() {
|
|
|
71
71
|
},
|
|
72
72
|
async stop() {
|
|
73
73
|
const boardUrl = getState()?.boardUrl;
|
|
74
|
-
const
|
|
74
|
+
const sessionId = getState()?.sessionId;
|
|
75
75
|
const done = await stopSession();
|
|
76
76
|
// null for a live session = the server refused to close it (ended locally, not saved).
|
|
77
|
-
if (
|
|
77
|
+
if (sessionId && done === null)
|
|
78
78
|
throw new Error('the server refused to close this session — it ended locally, not saved');
|
|
79
|
-
const url = done
|
|
80
|
-
return url ? { boardUrl: url } : {};
|
|
79
|
+
const url = boardUrlOf(done) ?? boardUrl;
|
|
80
|
+
return { ...(url ? { boardUrl: url } : {}), ...(sessionId ? { sessionId } : {}) };
|
|
81
81
|
},
|
|
82
82
|
note: (text) => addNote(text),
|
|
83
83
|
annotate: ({ text, rect, selector, task }) => addAnnotation(text, rect, selector, { task }),
|
|
@@ -61,7 +61,24 @@ export interface SessionState {
|
|
|
61
61
|
* reload re-applies the same rules instead of silently reverting.
|
|
62
62
|
*/
|
|
63
63
|
policy?: RedactionPolicy | null;
|
|
64
|
+
/**
|
|
65
|
+
* When (ISO) another tab last renewed its claim to be stopping this
|
|
66
|
+
* session: the copy it stores reads as paused with its clock frozen at the
|
|
67
|
+
* Stop, so every other tab stops capturing and painting rec at once, not
|
|
68
|
+
* when the save ends. The stopping tab renews the mark every
|
|
69
|
+
* `STOPPING_RENEW_MS` for as long as its Stop is out (however long a
|
|
70
|
+
* request hangs); pause and resume are refused on a mark younger than
|
|
71
|
+
* `STOPPING_TTL_MS` (`stoppingElsewhere`). An older one outlived its tab
|
|
72
|
+
* and is an ordinary pause. Stop always works.
|
|
73
|
+
*/
|
|
74
|
+
stopping?: string;
|
|
64
75
|
}
|
|
76
|
+
/** How often a tab renews its `stopping` mark while its Stop is out. */
|
|
77
|
+
export declare const STOPPING_RENEW_MS = 20000;
|
|
78
|
+
/** A mark not renewed for this long outlived its tab: several missed renewals, and past the one wake a minute Chrome allows a long-hidden tab. */
|
|
79
|
+
export declare const STOPPING_TTL_MS = 90000;
|
|
80
|
+
/** Is another tab still stopping `rec` (a fresh `stopping` mark)? */
|
|
81
|
+
export declare function stoppingElsewhere(rec: SessionState): boolean;
|
|
65
82
|
export type { RecorderEvent };
|
|
66
83
|
/** Storage key of the session record — shared by every tab of the origin. */
|
|
67
84
|
export declare const REC_KEY = "rec";
|
|
@@ -72,6 +89,13 @@ export declare const REC_KEY = "rec";
|
|
|
72
89
|
*/
|
|
73
90
|
export declare function getState(): SessionState | null;
|
|
74
91
|
export declare function setState(rec: SessionState | null): void;
|
|
92
|
+
/**
|
|
93
|
+
* This tab started (`sessionId`) or finished (null) stopping a session. Only
|
|
94
|
+
* the STORED record changes: this tab's own cache stays live, so the tail
|
|
95
|
+
* its Stop still drains (rrweb's last events, settled captures) lands.
|
|
96
|
+
* Finishing writes the record back without the mark.
|
|
97
|
+
*/
|
|
98
|
+
export declare function markStopping(sessionId: string | null, activeMs?: number, renewMs?: number): void;
|
|
75
99
|
export type StoredChange = 'joined' | 'updated' | 'ended' | 'unchanged';
|
|
76
100
|
/**
|
|
77
101
|
* Another document of this origin (a second tab) wrote the session record.
|
package/build/recorder/queue.js
CHANGED
|
@@ -39,6 +39,14 @@ export const RECONCILE_MS = 10_000;
|
|
|
39
39
|
const OFFLINE_AFTER_MS = 15_000;
|
|
40
40
|
const BACKLOG_ITEMS = 40;
|
|
41
41
|
const kv = () => getRecorderStorage();
|
|
42
|
+
/** How often a tab renews its `stopping` mark while its Stop is out. */
|
|
43
|
+
export const STOPPING_RENEW_MS = 20_000;
|
|
44
|
+
/** A mark not renewed for this long outlived its tab: several missed renewals, and past the one wake a minute Chrome allows a long-hidden tab. */
|
|
45
|
+
export const STOPPING_TTL_MS = 90_000;
|
|
46
|
+
/** Is another tab still stopping `rec` (a fresh `stopping` mark)? */
|
|
47
|
+
export function stoppingElsewhere(rec) {
|
|
48
|
+
return rec.stopping !== undefined && Date.now() - Date.parse(rec.stopping) < STOPPING_TTL_MS;
|
|
49
|
+
}
|
|
42
50
|
function readJson(key, fallback) {
|
|
43
51
|
const raw = kv().getString(key);
|
|
44
52
|
if (!raw)
|
|
@@ -85,7 +93,46 @@ export function setState(rec) {
|
|
|
85
93
|
if (rec === null)
|
|
86
94
|
kv().remove(REC_KEY);
|
|
87
95
|
else
|
|
88
|
-
safeSet(REC_KEY, JSON.stringify(rec));
|
|
96
|
+
safeSet(REC_KEY, JSON.stringify(stored(rec)));
|
|
97
|
+
}
|
|
98
|
+
/** The session this tab is stopping, its clock at the Stop, and when its mark was last renewed. */
|
|
99
|
+
let stoppingHere = null;
|
|
100
|
+
let stoppingLease = null;
|
|
101
|
+
/** What the other tabs read of `rec`: while this tab stops it, the frozen `stopping` copy. */
|
|
102
|
+
function stored(rec) {
|
|
103
|
+
if (stoppingHere?.sessionId !== rec.sessionId)
|
|
104
|
+
return rec;
|
|
105
|
+
return { ...rec, paused: true, activeMs: stoppingHere.activeMs, resumeAt: null, stopping: stoppingHere.at };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* This tab started (`sessionId`) or finished (null) stopping a session. Only
|
|
109
|
+
* the STORED record changes: this tab's own cache stays live, so the tail
|
|
110
|
+
* its Stop still drains (rrweb's last events, settled captures) lands.
|
|
111
|
+
* Finishing writes the record back without the mark.
|
|
112
|
+
*/
|
|
113
|
+
export function markStopping(sessionId, activeMs = 0, renewMs = STOPPING_RENEW_MS) {
|
|
114
|
+
const was = stoppingHere?.sessionId;
|
|
115
|
+
if (stoppingLease)
|
|
116
|
+
clearInterval(stoppingLease);
|
|
117
|
+
stoppingLease = null;
|
|
118
|
+
stoppingHere = sessionId ? { sessionId, activeMs, at: new Date().toISOString() } : null;
|
|
119
|
+
// The lease: a Stop whose request hangs is still this tab's, never mistaken for a gone tab's.
|
|
120
|
+
if (sessionId)
|
|
121
|
+
stoppingLease = setInterval(() => renewStopping(sessionId), renewMs);
|
|
122
|
+
const live = getState();
|
|
123
|
+
if (!live || (live.sessionId !== sessionId && live.sessionId !== was))
|
|
124
|
+
return;
|
|
125
|
+
delete live.stopping;
|
|
126
|
+
setState(live);
|
|
127
|
+
}
|
|
128
|
+
/** Re-stamp this tab's `stopping` mark while its Stop is still out. */
|
|
129
|
+
function renewStopping(sessionId) {
|
|
130
|
+
if (stoppingHere?.sessionId !== sessionId)
|
|
131
|
+
return;
|
|
132
|
+
stoppingHere.at = new Date().toISOString();
|
|
133
|
+
const live = getState();
|
|
134
|
+
if (live?.sessionId === sessionId)
|
|
135
|
+
setState(live);
|
|
89
136
|
}
|
|
90
137
|
/**
|
|
91
138
|
* Another document of this origin (a second tab) wrote the session record.
|
|
@@ -121,6 +168,14 @@ export function adoptStoredState(raw) {
|
|
|
121
168
|
// A policy this tab already holds outlives a record written before it.
|
|
122
169
|
if (next.policy === undefined && cur.policy !== undefined)
|
|
123
170
|
next.policy = cur.policy;
|
|
171
|
+
// A session this tab is stopping comes back as the frozen copy it wrote
|
|
172
|
+
// (another tab wrote its cache back): this tab's clock and capture stay live.
|
|
173
|
+
if (stoppingHere?.sessionId === next.sessionId) {
|
|
174
|
+
next.paused = cur.paused;
|
|
175
|
+
next.activeMs = cur.activeMs;
|
|
176
|
+
next.resumeAt = cur.resumeAt;
|
|
177
|
+
delete next.stopping;
|
|
178
|
+
}
|
|
124
179
|
recCache = next;
|
|
125
180
|
return 'updated';
|
|
126
181
|
}
|
|
@@ -729,6 +784,10 @@ export function __dropCachesForTests() {
|
|
|
729
784
|
}
|
|
730
785
|
flushBusy = false;
|
|
731
786
|
tailDropped = false;
|
|
787
|
+
stoppingHere = null;
|
|
788
|
+
if (stoppingLease)
|
|
789
|
+
clearInterval(stoppingLease);
|
|
790
|
+
stoppingLease = null;
|
|
732
791
|
recCache = undefined;
|
|
733
792
|
bufferCache = undefined;
|
|
734
793
|
chunkCache = undefined;
|
|
@@ -14,6 +14,35 @@ export declare function readRecents(): readonly HudRecent[];
|
|
|
14
14
|
export declare function noteRecent(entry: HudRecent): void;
|
|
15
15
|
/** Patch a recording in place; a no-op for one not listed. */
|
|
16
16
|
export declare function updateRecent(sessionId: string, patch: Partial<Omit<HudRecent, 'sessionId'>>): void;
|
|
17
|
+
/** What the reconcile read answers (the fields a recent can use). */
|
|
18
|
+
interface SessionRead {
|
|
19
|
+
status?: string;
|
|
20
|
+
deletedAt?: string | null;
|
|
21
|
+
boardUrl?: string;
|
|
22
|
+
board?: {
|
|
23
|
+
url?: string;
|
|
24
|
+
};
|
|
25
|
+
projection?: {
|
|
26
|
+
state?: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** A session answer's board link: the server's `boardUrl`, or an older server's `board.url`. */
|
|
30
|
+
export declare function boardUrlOf(s: Pick<SessionRead, 'boardUrl' | 'board'> | null | undefined): string | undefined;
|
|
31
|
+
/** How often, and how long, a saved session is read until its board exists (the extension's D11 numbers). */
|
|
32
|
+
export declare const BOARD_POLL_MS = 1500;
|
|
33
|
+
export declare const BOARD_WAIT_MS: number;
|
|
34
|
+
/**
|
|
35
|
+
* The server answered a stop (or a report) before the session's board was
|
|
36
|
+
* built — it projects after the stop, stills first, 30–60 s. Read the
|
|
37
|
+
* session until it names its board and put the link on the recent, where
|
|
38
|
+
* the Saved face and the menu pick it up. Ends on a failed or empty
|
|
39
|
+
* projection, a gone or refused session, or after `forMs`; a transient
|
|
40
|
+
* error keeps waiting. Never rejects.
|
|
41
|
+
*/
|
|
42
|
+
export declare function awaitBoard(sessionId: string, { everyMs, forMs }?: {
|
|
43
|
+
everyMs?: number;
|
|
44
|
+
forMs?: number;
|
|
45
|
+
}): Promise<void>;
|
|
17
46
|
/**
|
|
18
47
|
* Fill the board links the list lacks — `live` (the recording in progress)
|
|
19
48
|
* is skipped, its link arrives with its stop. Never rejects.
|
|
@@ -23,3 +52,4 @@ export declare function refreshRecents(live: string | null): Promise<void>;
|
|
|
23
52
|
export declare function forgetRecents(): void;
|
|
24
53
|
/** Test-only: forget the in-memory list (storage stays). */
|
|
25
54
|
export declare function __resetRecentsForTests(): void;
|
|
55
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { api, VitrinkaApiError } from './api';
|
|
1
|
+
import { api, permanentStatus, VitrinkaApiError } from './api';
|
|
2
2
|
import { notify } from './state';
|
|
3
3
|
import { getRecorderStorage } from './storage';
|
|
4
4
|
export const RECENTS_KEY = 'recents';
|
|
@@ -47,6 +47,53 @@ export function updateRecent(sessionId, patch) {
|
|
|
47
47
|
return;
|
|
48
48
|
write(list.map((r) => (r.sessionId === sessionId ? { ...r, ...patch } : r)));
|
|
49
49
|
}
|
|
50
|
+
/** A session answer's board link: the server's `boardUrl`, or an older server's `board.url`. */
|
|
51
|
+
export function boardUrlOf(s) {
|
|
52
|
+
return s?.boardUrl || s?.board?.url || undefined;
|
|
53
|
+
}
|
|
54
|
+
/** How often, and how long, a saved session is read until its board exists (the extension's D11 numbers). */
|
|
55
|
+
export const BOARD_POLL_MS = 1_500;
|
|
56
|
+
export const BOARD_WAIT_MS = 10 * 60_000;
|
|
57
|
+
const awaiting = new Set();
|
|
58
|
+
/**
|
|
59
|
+
* The server answered a stop (or a report) before the session's board was
|
|
60
|
+
* built — it projects after the stop, stills first, 30–60 s. Read the
|
|
61
|
+
* session until it names its board and put the link on the recent, where
|
|
62
|
+
* the Saved face and the menu pick it up. Ends on a failed or empty
|
|
63
|
+
* projection, a gone or refused session, or after `forMs`; a transient
|
|
64
|
+
* error keeps waiting. Never rejects.
|
|
65
|
+
*/
|
|
66
|
+
export async function awaitBoard(sessionId, { everyMs = BOARD_POLL_MS, forMs = BOARD_WAIT_MS } = {}) {
|
|
67
|
+
if (awaiting.has(sessionId))
|
|
68
|
+
return;
|
|
69
|
+
awaiting.add(sessionId);
|
|
70
|
+
const until = Date.now() + forMs;
|
|
71
|
+
try {
|
|
72
|
+
while (Date.now() < until) {
|
|
73
|
+
await new Promise((res) => setTimeout(res, everyMs));
|
|
74
|
+
try {
|
|
75
|
+
const s = await api('GET', `/api/v1/sessions/${sessionId}`);
|
|
76
|
+
const boardUrl = boardUrlOf(s);
|
|
77
|
+
if (boardUrl)
|
|
78
|
+
return updateRecent(sessionId, { boardUrl });
|
|
79
|
+
if (s.deletedAt)
|
|
80
|
+
return updateRecent(sessionId, { status: 'deleted' });
|
|
81
|
+
if (s.projection?.state === 'failed' || s.projection?.state === 'empty')
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
if (e instanceof VitrinkaApiError && e.status === 404)
|
|
86
|
+
return updateRecent(sessionId, { status: 'deleted' });
|
|
87
|
+
if (e instanceof VitrinkaApiError && permanentStatus(e.status))
|
|
88
|
+
return;
|
|
89
|
+
console.warn(`vitrinka: waiting for the board of session ${sessionId}`, e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
awaiting.delete(sessionId);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
50
97
|
/** Ids already asked this document — a refused read is not retried on every menu open. */
|
|
51
98
|
const asked = new Set();
|
|
52
99
|
/**
|
|
@@ -59,11 +106,14 @@ export async function refreshRecents(live) {
|
|
|
59
106
|
asked.add(r.sessionId);
|
|
60
107
|
try {
|
|
61
108
|
const s = await api('GET', `/api/v1/sessions/${r.sessionId}`);
|
|
62
|
-
const boardUrl = s
|
|
109
|
+
const boardUrl = boardUrlOf(s);
|
|
63
110
|
if (s.deletedAt)
|
|
64
111
|
updateRecent(r.sessionId, { status: 'deleted' });
|
|
65
112
|
else if (boardUrl)
|
|
66
113
|
updateRecent(r.sessionId, { boardUrl, ...(s.status === 'done' ? { status: 'saved' } : {}) });
|
|
114
|
+
// Still projecting (the document that waited for it reloaded or left): wait here instead.
|
|
115
|
+
else if (s.projection?.state === 'running')
|
|
116
|
+
void awaitBoard(r.sessionId);
|
|
67
117
|
}
|
|
68
118
|
catch (e) {
|
|
69
119
|
if (e instanceof VitrinkaApiError && e.status === 404)
|
|
@@ -82,4 +132,5 @@ export function forgetRecents() {
|
|
|
82
132
|
export function __resetRecentsForTests() {
|
|
83
133
|
cache = undefined;
|
|
84
134
|
asked.clear();
|
|
135
|
+
awaiting.clear();
|
|
85
136
|
}
|
|
@@ -29,6 +29,7 @@ export declare function holdReport(on: boolean): void;
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function sendReport(note: ReportNote): Promise<{
|
|
31
31
|
boardUrl?: string;
|
|
32
|
+
sessionId?: string;
|
|
32
33
|
}>;
|
|
33
34
|
/** The provider unmounted: forget the buffer and any held clip; a remount re-arms. */
|
|
34
35
|
export declare function dropFlight(): void;
|
package/build/recorder/report.js
CHANGED
|
@@ -4,7 +4,7 @@ import { checkoutRRWeb } from './capture/rrweb';
|
|
|
4
4
|
import { recorderConfig, vitrinkaLinked } from './config';
|
|
5
5
|
import { clipHasSnapshot, flightActive, startFlightBuffer, stopFlightBuffer, takeFlightClip } from './flight';
|
|
6
6
|
import { EVENTS_PER_POST, getState, MAX_BATCH_BYTES, splitRRWebEvents, utf8Bytes } from './queue';
|
|
7
|
-
import { noteRecent } from './recents';
|
|
7
|
+
import { awaitBoard, boardUrlOf, noteRecent } from './recents';
|
|
8
8
|
import { addAnnotation, createSession, imagePixels } from './session';
|
|
9
9
|
import { currentRoute, notify } from './state';
|
|
10
10
|
// -- the gate ----------------------------------------------------------------
|
|
@@ -196,7 +196,7 @@ const steps = [
|
|
|
196
196
|
(j) => postEvents(j.sessionId, [j.note]),
|
|
197
197
|
async (j) => {
|
|
198
198
|
const done = await api('PATCH', `/api/v1/sessions/${j.sessionId}`, { status: 'done' });
|
|
199
|
-
const url = done
|
|
199
|
+
const url = boardUrlOf(done);
|
|
200
200
|
if (url)
|
|
201
201
|
j.boardUrl = url;
|
|
202
202
|
},
|
|
@@ -244,7 +244,9 @@ export async function sendReport(note) {
|
|
|
244
244
|
status: 'saved',
|
|
245
245
|
...(j.boardUrl ? { boardUrl: j.boardUrl } : {}),
|
|
246
246
|
});
|
|
247
|
-
|
|
247
|
+
if (!j.boardUrl)
|
|
248
|
+
void awaitBoard(j.sessionId);
|
|
249
|
+
return { ...(j.boardUrl ? { boardUrl: j.boardUrl } : {}), sessionId: j.sessionId };
|
|
248
250
|
}
|
|
249
251
|
/** The provider unmounted: forget the buffer and any held clip; a remount re-arms. */
|
|
250
252
|
export function dropFlight() {
|
|
@@ -17,8 +17,8 @@ import { type SessionState } from './queue';
|
|
|
17
17
|
export { currentRoute, notify, subscribe } from './state';
|
|
18
18
|
export type { SessionDone } from '../protocol';
|
|
19
19
|
/** Sent as `meta.recorder`; bumped with the package version. */
|
|
20
|
-
export declare const RECORDER_VERSION = "0.3.
|
|
21
|
-
export declare const RECORDER_ID = "web/0.3.
|
|
20
|
+
export declare const RECORDER_VERSION = "0.3.3";
|
|
21
|
+
export declare const RECORDER_ID = "web/0.3.3";
|
|
22
22
|
/** What `POST /api/v1/sessions` answers (the fields this recorder keeps). */
|
|
23
23
|
export interface SessionOut {
|
|
24
24
|
id: string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { api, fetchPolicy, permanentStatus, VitrinkaApiError } from './api';
|
|
2
2
|
import { redactUrl, setRedactionPolicy } from './capture/redact';
|
|
3
3
|
import { recorderConfig } from './config';
|
|
4
|
-
import { adoptStoredState, armReconcile, capturesSettled, disarmReconcile, drainBuffer, getState, pushEvent, queuedCount, REC_KEY, resetHealth, resetIdle, resetQueues, setState, } from './queue';
|
|
5
|
-
import { forgetRecents, noteRecent, RECENTS_KEY, updateRecent } from './recents';
|
|
4
|
+
import { adoptStoredState, armReconcile, capturesSettled, disarmReconcile, drainBuffer, getState, markStopping, pushEvent, queuedCount, REC_KEY, resetHealth, resetIdle, resetQueues, setState, stoppingElsewhere, } from './queue';
|
|
5
|
+
import { awaitBoard, boardUrlOf, forgetRecents, noteRecent, RECENTS_KEY, updateRecent } from './recents';
|
|
6
6
|
import { currentRoute, notify } from './state';
|
|
7
7
|
import { getRecorderStorage } from './storage';
|
|
8
8
|
export { currentRoute, notify, subscribe } from './state';
|
|
9
9
|
/** Sent as `meta.recorder`; bumped with the package version. */
|
|
10
|
-
export const RECORDER_VERSION = '0.3.
|
|
10
|
+
export const RECORDER_VERSION = '0.3.3';
|
|
11
11
|
export const RECORDER_ID = `web/${RECORDER_VERSION}`;
|
|
12
12
|
/**
|
|
13
13
|
* Re-apply a RECOVERED session's redaction policy after a reload — and
|
|
@@ -176,8 +176,10 @@ async function attachTags(sessionId, tags) {
|
|
|
176
176
|
}
|
|
177
177
|
export async function togglePause() {
|
|
178
178
|
const rec = getState();
|
|
179
|
-
if (!rec || rec.dead)
|
|
179
|
+
if (!rec || rec.dead || stoppingElsewhere(rec))
|
|
180
180
|
return false;
|
|
181
|
+
// A stale mark: the tab that was stopping it is gone, so this is a plain pause.
|
|
182
|
+
delete rec.stopping;
|
|
181
183
|
rec.paused = !rec.paused;
|
|
182
184
|
if (rec.paused) {
|
|
183
185
|
rec.activeMs = (rec.activeMs || 0) + (rec.resumeAt ? Date.now() - Date.parse(rec.resumeAt) : 0);
|
|
@@ -245,6 +247,17 @@ export async function stopSession() {
|
|
|
245
247
|
return null;
|
|
246
248
|
// The recording's length is what the tester saw at Stop, not Stop + drain.
|
|
247
249
|
const durationMs = elapsedOf(rec);
|
|
250
|
+
// The other tabs leave rec at the Stop, not when the save ends; a stop
|
|
251
|
+
// that keeps the session hands it back to them as it now is.
|
|
252
|
+
markStopping(rec.sessionId, durationMs);
|
|
253
|
+
try {
|
|
254
|
+
return await finishStop(rec, durationMs);
|
|
255
|
+
}
|
|
256
|
+
finally {
|
|
257
|
+
markStopping(null);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async function finishStop(rec, durationMs) {
|
|
248
261
|
disarmReconcile();
|
|
249
262
|
for (const fn of beforeStopHooks) {
|
|
250
263
|
try {
|
|
@@ -300,8 +313,10 @@ export async function stopSession() {
|
|
|
300
313
|
}
|
|
301
314
|
}
|
|
302
315
|
// A permanent refusal still ends the recording locally, but it was not saved.
|
|
303
|
-
const boardUrl = done
|
|
316
|
+
const boardUrl = boardUrlOf(done) ?? rec.boardUrl;
|
|
304
317
|
updateRecent(rec.sessionId, { status: done ? 'saved' : 'unsaved', durationMs, ...(boardUrl ? { boardUrl } : {}) });
|
|
318
|
+
if (done && !boardUrl)
|
|
319
|
+
void awaitBoard(rec.sessionId);
|
|
305
320
|
// Another tab may have ended this session or started the next one while
|
|
306
321
|
// the stop was out: the state and the queues are then not this stop's to clear.
|
|
307
322
|
if (getState()?.sessionId === rec.sessionId) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitrinka/web",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "vitrinka toolkit for React DOM apps — the journey recorder: capture manual-testing sessions (rrweb DOM stream, clicks, navigation, network, console, notes) straight into vitrinka boards.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"repository": {
|