@vitrinka/web 0.3.4 → 0.5.0
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 +118 -0
- package/README.md +93 -6
- package/build/hud.d.ts +4 -1
- package/build/hud.iife.js +46 -9
- package/build/one.iife.js +1 -0
- package/build/protocol/index.d.ts +55 -4
- package/build/protocol/index.js +4 -2
- package/build/recorder/RecorderProvider.js +48 -9
- package/build/recorder/api.d.ts +25 -5
- package/build/recorder/api.js +21 -9
- package/build/recorder/attachments.d.ts +19 -0
- package/build/recorder/attachments.js +31 -0
- package/build/recorder/capture/console.d.ts +2 -0
- package/build/recorder/capture/console.js +22 -2
- package/build/recorder/capture/nav.d.ts +13 -2
- package/build/recorder/capture/nav.js +49 -11
- package/build/recorder/capture/net.d.ts +2 -0
- package/build/recorder/capture/net.js +30 -4
- package/build/recorder/control.d.ts +17 -0
- package/build/recorder/control.js +39 -2
- package/build/recorder/hud/Hud.d.ts +1 -1
- package/build/recorder/hud/Hud.js +113 -30
- package/build/recorder/hud/RecorderPill.js +6 -2
- package/build/recorder/hud/Sheet.d.ts +40 -5
- package/build/recorder/hud/Sheet.js +134 -8
- package/build/recorder/hud/attach.d.ts +26 -0
- package/build/recorder/hud/attach.js +136 -0
- package/build/recorder/hud/chords.d.ts +10 -0
- package/build/recorder/hud/chords.js +34 -0
- package/build/recorder/hud/controller.d.ts +55 -3
- package/build/recorder/hud/controller.js +1 -1
- package/build/recorder/hud/flow.d.ts +22 -1
- package/build/recorder/hud/flow.js +16 -1
- package/build/recorder/hud/host.js +2 -0
- package/build/recorder/hud/icons.d.ts +3 -0
- package/build/recorder/hud/icons.js +7 -0
- package/build/recorder/hud/layer.d.ts +4 -1
- package/build/recorder/hud/layer.js +11 -3
- package/build/recorder/hud/resize.d.ts +83 -0
- package/build/recorder/hud/resize.js +236 -0
- package/build/recorder/hud/styles.d.ts +1 -1
- package/build/recorder/hud/styles.js +38 -1
- package/build/recorder/index.d.ts +1 -0
- package/build/recorder/index.js +1 -0
- package/build/recorder/lead.d.ts +90 -0
- package/build/recorder/lead.js +404 -0
- package/build/recorder/link.d.ts +4 -1
- package/build/recorder/link.js +6 -2
- package/build/recorder/me.d.ts +7 -0
- package/build/recorder/me.js +62 -12
- package/build/recorder/one-iife.d.ts +13 -0
- package/build/recorder/one-iife.js +13 -0
- package/build/recorder/one.d.ts +170 -0
- package/build/recorder/one.js +292 -0
- package/build/recorder/page-controller.js +26 -4
- package/build/recorder/queue.d.ts +33 -3
- package/build/recorder/queue.js +409 -26
- package/build/recorder/report.d.ts +9 -0
- package/build/recorder/report.js +55 -6
- package/build/recorder/session.d.ts +33 -7
- package/build/recorder/session.js +111 -31
- package/build/recorder/state.d.ts +9 -0
- package/build/recorder/state.js +7 -0
- package/build/recorder/storage/blobs.d.ts +32 -0
- package/build/recorder/storage/blobs.js +83 -0
- package/build/recorder/storage/index.js +3 -2
- package/build/recorder/version.d.ts +3 -0
- package/build/recorder/version.js +3 -0
- package/package.json +5 -3
package/build/recorder/report.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { api, fetchPolicy, uploadChunk } from './api';
|
|
1
|
+
import { api, fetchPolicy, uploadChunk, uploadImage } from './api';
|
|
2
|
+
import { stageAttachments } from './attachments';
|
|
2
3
|
import { setRedactionPolicy } from './capture/redact';
|
|
3
4
|
import { checkoutRRWeb } from './capture/rrweb';
|
|
4
5
|
import { recorderConfig, vitrinkaLinked } from './config';
|
|
@@ -6,12 +7,14 @@ import { clipHasSnapshot, flightActive, startFlightBuffer, stopFlightBuffer, tak
|
|
|
6
7
|
import { EVENTS_PER_POST, getState, MAX_BATCH_BYTES, splitRRWebEvents, utf8Bytes } from './queue';
|
|
7
8
|
import { awaitBoard, boardUrlOf, noteRecent } from './recents';
|
|
8
9
|
import { addAnnotation, createSession, imagePixels } from './session';
|
|
9
|
-
import { currentRoute, notify } from './state';
|
|
10
|
+
import { currentRoute, leadState, notify } from './state';
|
|
10
11
|
// -- the gate ----------------------------------------------------------------
|
|
11
12
|
let pills = 0;
|
|
12
13
|
let armed = false;
|
|
13
14
|
let generation = 0;
|
|
14
15
|
let arming = Promise.resolve();
|
|
16
|
+
/** The armed buffer's policy read answered `attachments: true`. */
|
|
17
|
+
let flightAttachments = false;
|
|
15
18
|
/** A mounted pill wants the flight recorder; returns the release. */
|
|
16
19
|
export function wantFlight() {
|
|
17
20
|
pills++;
|
|
@@ -25,8 +28,13 @@ export function wantFlight() {
|
|
|
25
28
|
notify();
|
|
26
29
|
};
|
|
27
30
|
}
|
|
31
|
+
/** …and this recorder leads or is idle: a follower keeps no last minute (ONE recorder D2). */
|
|
28
32
|
function flightWanted() {
|
|
29
|
-
return pills > 0 &&
|
|
33
|
+
return (pills > 0 &&
|
|
34
|
+
getState() === null &&
|
|
35
|
+
leadState.following === null &&
|
|
36
|
+
vitrinkaLinked() &&
|
|
37
|
+
recorderConfig().flightRecorder !== false);
|
|
30
38
|
}
|
|
31
39
|
/**
|
|
32
40
|
* Arm or disarm the flight recorder to match the gate; the provider calls it
|
|
@@ -39,10 +47,11 @@ export function syncFlight() {
|
|
|
39
47
|
const gen = ++generation;
|
|
40
48
|
setRedactionPolicy(null);
|
|
41
49
|
// fetchPolicy never rejects: null is the engine's safe defaults.
|
|
42
|
-
arming = fetchPolicy().then((policy) => {
|
|
50
|
+
arming = fetchPolicy().then(({ policy, attachments }) => {
|
|
43
51
|
if (!armed || gen !== generation)
|
|
44
52
|
return;
|
|
45
53
|
setRedactionPolicy(policy);
|
|
54
|
+
flightAttachments = attachments;
|
|
46
55
|
startFlightBuffer();
|
|
47
56
|
notify();
|
|
48
57
|
});
|
|
@@ -50,6 +59,7 @@ export function syncFlight() {
|
|
|
50
59
|
else if (!want && armed) {
|
|
51
60
|
armed = false;
|
|
52
61
|
generation++;
|
|
62
|
+
flightAttachments = false;
|
|
53
63
|
stopFlightBuffer();
|
|
54
64
|
// A session that just started owns the rules now; only an idle page resets them.
|
|
55
65
|
if (getState() === null)
|
|
@@ -59,11 +69,24 @@ export function syncFlight() {
|
|
|
59
69
|
}
|
|
60
70
|
/** Can the pill offer "Report a bug" now — into the live session, or with the idle clip? */
|
|
61
71
|
export function canReport() {
|
|
72
|
+
if (leadState.following)
|
|
73
|
+
return false;
|
|
62
74
|
const rec = getState();
|
|
63
75
|
if (rec)
|
|
64
76
|
return !rec.paused && !rec.dead;
|
|
65
77
|
return flightWanted() && flightActive();
|
|
66
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Do the sheets take images now (recorder attachments D6)? Recording: the
|
|
81
|
+
* session's policy read said so. Idle: the flight recorder's did — only the
|
|
82
|
+
* bug report sheet opens then.
|
|
83
|
+
*/
|
|
84
|
+
export function canAttach() {
|
|
85
|
+
const rec = getState();
|
|
86
|
+
if (rec)
|
|
87
|
+
return rec.attachments === true;
|
|
88
|
+
return flightAttachments && canReport();
|
|
89
|
+
}
|
|
67
90
|
let held = null;
|
|
68
91
|
let job = null;
|
|
69
92
|
let sending = false;
|
|
@@ -133,13 +156,25 @@ function buildJob(clip, note) {
|
|
|
133
156
|
const lastLane = clip.lanes.at(-1);
|
|
134
157
|
if (lastLane)
|
|
135
158
|
endMs = Math.max(endMs, Date.parse(lastLane.ts));
|
|
159
|
+
const sentAt = new Date().toISOString();
|
|
160
|
+
// Stamped at Send like the note, in its lane; only when the workspace takes them.
|
|
161
|
+
const images = (flightAttachments ? stageAttachments(note.attachments) : []).map((image) => ({
|
|
162
|
+
seq: ++seq,
|
|
163
|
+
ts: sentAt,
|
|
164
|
+
...tab,
|
|
165
|
+
...image,
|
|
166
|
+
}));
|
|
167
|
+
if (!flightAttachments && note.attachments?.length) {
|
|
168
|
+
console.warn('vitrinka: this workspace takes no attachments — the report is sent without its images');
|
|
169
|
+
}
|
|
136
170
|
return {
|
|
137
171
|
title: reportTitle(note.text),
|
|
138
172
|
events,
|
|
139
173
|
chunks,
|
|
174
|
+
images,
|
|
140
175
|
note: {
|
|
141
176
|
seq: ++seq,
|
|
142
|
-
ts:
|
|
177
|
+
ts: sentAt,
|
|
143
178
|
...tab,
|
|
144
179
|
kind: 'note',
|
|
145
180
|
payload: {
|
|
@@ -149,6 +184,7 @@ function buildJob(clip, note) {
|
|
|
149
184
|
annotate: true,
|
|
150
185
|
task: true,
|
|
151
186
|
route: currentRoute.pathname,
|
|
187
|
+
...(images.length ? { attachments: images.map((image) => image.seq) } : {}),
|
|
152
188
|
},
|
|
153
189
|
},
|
|
154
190
|
durationMs: startMs !== undefined ? Math.max(0, endMs - startMs) : 0,
|
|
@@ -193,6 +229,15 @@ const steps = [
|
|
|
193
229
|
}
|
|
194
230
|
await postEvents(j.sessionId, rows);
|
|
195
231
|
},
|
|
232
|
+
async (j) => {
|
|
233
|
+
// The images the same way, through the screenshot leaf: bytes first, then their rows.
|
|
234
|
+
const rows = [];
|
|
235
|
+
for (const im of j.images) {
|
|
236
|
+
const up = await uploadImage(j.sessionId, im.seq, im.blob);
|
|
237
|
+
rows.push({ seq: im.seq, ts: im.ts, tabId: im.tabId, tabHost: im.tabHost, kind: 'attachment', payload: { ...im.payload }, blobKey: up.blobKey });
|
|
238
|
+
}
|
|
239
|
+
await postEvents(j.sessionId, rows);
|
|
240
|
+
},
|
|
196
241
|
(j) => postEvents(j.sessionId, [j.note]),
|
|
197
242
|
async (j) => {
|
|
198
243
|
const done = await api('PATCH', `/api/v1/sessions/${j.sessionId}`, { status: 'done' });
|
|
@@ -211,7 +256,10 @@ export async function sendReport(note) {
|
|
|
211
256
|
if (rec) {
|
|
212
257
|
if (rec.paused || rec.dead)
|
|
213
258
|
throw new Error('the recording is not capturing — resume it to report');
|
|
214
|
-
addAnnotation(note.text, note.rect ?? viewportRect(), note.selector, {
|
|
259
|
+
addAnnotation(note.text, note.rect ?? viewportRect(), note.selector, {
|
|
260
|
+
task: true,
|
|
261
|
+
...(note.attachments?.length ? { attachments: note.attachments } : {}),
|
|
262
|
+
});
|
|
215
263
|
return rec.boardUrl ? { boardUrl: rec.boardUrl } : {};
|
|
216
264
|
}
|
|
217
265
|
if (sending)
|
|
@@ -252,6 +300,7 @@ export async function sendReport(note) {
|
|
|
252
300
|
export function dropFlight() {
|
|
253
301
|
armed = false;
|
|
254
302
|
generation++;
|
|
303
|
+
flightAttachments = false;
|
|
255
304
|
arming = Promise.resolve();
|
|
256
305
|
held = null;
|
|
257
306
|
if (!sending)
|
|
@@ -13,13 +13,12 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { RedactionPolicy } from '@vitrinka/redact';
|
|
15
15
|
import type { SessionDone } from '../protocol';
|
|
16
|
-
import {
|
|
16
|
+
import type { HudAttachment } from './hud/controller';
|
|
17
|
+
import { type SessionState, type StoredChange } from './queue';
|
|
17
18
|
export { currentRoute, notify, subscribe } from './state';
|
|
18
19
|
export { onBeforeStop } from './queue';
|
|
19
20
|
export type { SessionDone } from '../protocol';
|
|
20
|
-
|
|
21
|
-
export declare const RECORDER_VERSION = "0.3.4";
|
|
22
|
-
export declare const RECORDER_ID = "web/0.3.4";
|
|
21
|
+
export { RECORDER_ID, RECORDER_VERSION } from './version';
|
|
23
22
|
/** What `POST /api/v1/sessions` answers (the fields this recorder keeps). */
|
|
24
23
|
export interface SessionOut {
|
|
25
24
|
id: string;
|
|
@@ -38,6 +37,20 @@ export declare function recoverRedactionPolicy(): void;
|
|
|
38
37
|
* others (their pills go idle, their lanes stop sending into it), a Start
|
|
39
38
|
* is joined as a reload joins it, a pause follows. Returns the unsubscribe.
|
|
40
39
|
*/
|
|
40
|
+
/**
|
|
41
|
+
* Take a session record this document did not write — another tab's, or
|
|
42
|
+
* another recorder bundle's in this very document — with what it implies:
|
|
43
|
+
* an ended session drops its rules, a joined one recovers its policy and
|
|
44
|
+
* reconcile poll, and a policy that arrived late applies at once.
|
|
45
|
+
*/
|
|
46
|
+
export declare function applyStoredRecord(raw: string | null): StoredChange;
|
|
47
|
+
/**
|
|
48
|
+
* Re-read the durable record before a waiting session resumes (ONE
|
|
49
|
+
* recorder): another recorder bundle in THIS document may have ended or
|
|
50
|
+
* replaced it, and storage events never reach the document that wrote them.
|
|
51
|
+
* True when the cached session is still the one to resume.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resyncStoredSession(): boolean;
|
|
41
54
|
export declare function followOtherTabs(): () => void;
|
|
42
55
|
export declare function elapsedOf(rec: SessionState | null): number;
|
|
43
56
|
export interface StartOptions {
|
|
@@ -59,10 +72,22 @@ export declare function createSession(title: string, opts?: {
|
|
|
59
72
|
environment?: string;
|
|
60
73
|
meta?: Record<string, unknown>;
|
|
61
74
|
}): Promise<SessionOut>;
|
|
75
|
+
/**
|
|
76
|
+
* Start a recording. The claim on this document comes first, synchronously
|
|
77
|
+
* and before any network call: while the extension (or another recorder on
|
|
78
|
+
* this page) leads, this rejects with a `RecorderBusyError` and nothing is
|
|
79
|
+
* created (ONE recorder D12).
|
|
80
|
+
*/
|
|
62
81
|
export declare function startSession(opts?: StartOptions): Promise<SessionState>;
|
|
63
82
|
export declare function togglePause(): Promise<boolean>;
|
|
64
|
-
/**
|
|
65
|
-
|
|
83
|
+
/**
|
|
84
|
+
* A plain note — `{text, route}`, the extension's shape. With attachments
|
|
85
|
+
* (recorder attachments) each image becomes an `attachment` event whose seq
|
|
86
|
+
* is allocated just before the note's, in this tab's lane, and the note
|
|
87
|
+
* lists them: `{text, route, attachments: [seq…]}`; `text` may then be
|
|
88
|
+
* empty. Their bytes upload through `/shot` before their rows ride (queue.ts).
|
|
89
|
+
*/
|
|
90
|
+
export declare function addNote(text: string, attachments?: readonly HudAttachment[]): void;
|
|
66
91
|
/** A rect in CSS pixels (viewport coordinates). */
|
|
67
92
|
export interface ViewRect {
|
|
68
93
|
x: number;
|
|
@@ -77,10 +102,11 @@ export declare function imagePixels(r: ViewRect): ViewRect;
|
|
|
77
102
|
* annotate: true}` (+ `task` when the tester chose the task destination);
|
|
78
103
|
* vitrinka projects it into a board annotation. `selector` is '' for a free
|
|
79
104
|
* region. The rect is in device pixels. An empty note is still a valid
|
|
80
|
-
* annotation, matching the extension.
|
|
105
|
+
* annotation, matching the extension. `attachments` ride as for `addNote`.
|
|
81
106
|
*/
|
|
82
107
|
export declare function addAnnotation(text: string, rect: ViewRect, selector: string, opts?: {
|
|
83
108
|
task?: boolean;
|
|
109
|
+
attachments?: readonly HudAttachment[];
|
|
84
110
|
}): void;
|
|
85
111
|
/**
|
|
86
112
|
* Hooks that run at the top of Stop, before the drain snapshot — the rrweb
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { api, fetchPolicy, permanentStatus, VitrinkaApiError } from './api';
|
|
2
|
+
import { stageAttachments } from './attachments';
|
|
3
|
+
import { primeNavigation } from './capture/nav';
|
|
2
4
|
import { redactUrl, setRedactionPolicy } from './capture/redact';
|
|
3
5
|
import { recorderConfig } from './config';
|
|
4
|
-
import { adoptStoredState, armReconcile, capturesSettled, disarmReconcile, drainBuffer, getState, markStopping, persistNow, pushEvent, queuedCount, REC_KEY, resetHealth, resetIdle, resetQueues, runBeforeStopHooks, setState, stoppingElsewhere, } from './queue';
|
|
6
|
+
import { adoptStoredState, armReconcile, capturesSettled, disarmReconcile, drainBuffer, getState, markStopping, persistNow, pruneBlobJournal, pushEvent, queuedCount, REC_KEY, resetHealth, resetIdle, resetQueues, runBeforeStopHooks, setState, stoppingElsewhere, } from './queue';
|
|
7
|
+
import { claimForStart, settleStart, setLeadStopping } from './lead';
|
|
5
8
|
import { awaitBoard, boardUrlOf, forgetRecents, noteRecent, RECENTS_KEY, updateRecent } from './recents';
|
|
6
9
|
import { currentRoute, notify } from './state';
|
|
7
10
|
import { getRecorderStorage } from './storage';
|
|
8
11
|
import { recorderPeers, registerRecorderTab, waitForRecorderPeers } from './tabs';
|
|
12
|
+
import { RECORDER_ID } from './version';
|
|
9
13
|
export { currentRoute, notify, subscribe } from './state';
|
|
10
14
|
export { onBeforeStop } from './queue';
|
|
11
|
-
|
|
12
|
-
export const RECORDER_VERSION = '0.3.4';
|
|
13
|
-
export const RECORDER_ID = `web/${RECORDER_VERSION}`;
|
|
15
|
+
export { RECORDER_ID, RECORDER_VERSION } from './version';
|
|
14
16
|
/**
|
|
15
17
|
* Re-apply a RECOVERED session's redaction policy after a reload — and
|
|
16
|
-
* re-FETCH it when the original fetch never settled (`policy === undefined`)
|
|
18
|
+
* re-FETCH it when the original fetch never settled (`policy === undefined`),
|
|
19
|
+
* with the `attachments` answer the same read carries.
|
|
17
20
|
*/
|
|
18
21
|
let policyRecoveryInFlight = false;
|
|
19
22
|
export function recoverRedactionPolicy() {
|
|
@@ -27,14 +30,15 @@ export function recoverRedactionPolicy() {
|
|
|
27
30
|
return;
|
|
28
31
|
policyRecoveryInFlight = true;
|
|
29
32
|
void fetchPolicy()
|
|
30
|
-
.then((policy) => {
|
|
33
|
+
.then(({ policy, attachments }) => {
|
|
31
34
|
const live = getState();
|
|
32
35
|
if (live?.sessionId !== rec.sessionId)
|
|
33
36
|
return;
|
|
34
37
|
if (live.policy !== undefined)
|
|
35
38
|
return;
|
|
36
39
|
setRedactionPolicy(policy);
|
|
37
|
-
setState({ ...live, policy });
|
|
40
|
+
setState({ ...live, policy, attachments });
|
|
41
|
+
notify();
|
|
38
42
|
})
|
|
39
43
|
.finally(() => {
|
|
40
44
|
policyRecoveryInFlight = false;
|
|
@@ -47,26 +51,51 @@ export function recoverRedactionPolicy() {
|
|
|
47
51
|
* others (their pills go idle, their lanes stop sending into it), a Start
|
|
48
52
|
* is joined as a reload joins it, a pause follows. Returns the unsubscribe.
|
|
49
53
|
*/
|
|
54
|
+
/**
|
|
55
|
+
* Take a session record this document did not write — another tab's, or
|
|
56
|
+
* another recorder bundle's in this very document — with what it implies:
|
|
57
|
+
* an ended session drops its rules, a joined one recovers its policy and
|
|
58
|
+
* reconcile poll, and a policy that arrived late applies at once.
|
|
59
|
+
*/
|
|
60
|
+
export function applyStoredRecord(raw) {
|
|
61
|
+
const had = getState()?.policy;
|
|
62
|
+
const change = adoptStoredState(raw);
|
|
63
|
+
if (change === 'unchanged')
|
|
64
|
+
return change;
|
|
65
|
+
if (change === 'ended')
|
|
66
|
+
setRedactionPolicy(null);
|
|
67
|
+
if (change === 'joined') {
|
|
68
|
+
recoverRedactionPolicy();
|
|
69
|
+
armReconcile();
|
|
70
|
+
}
|
|
71
|
+
// The starting tab writes the workspace policy after its first record:
|
|
72
|
+
// its rules apply here the moment they arrive.
|
|
73
|
+
const policy = getState()?.policy;
|
|
74
|
+
if (change === 'updated' && had === undefined && policy !== undefined)
|
|
75
|
+
setRedactionPolicy(policy);
|
|
76
|
+
return change;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Re-read the durable record before a waiting session resumes (ONE
|
|
80
|
+
* recorder): another recorder bundle in THIS document may have ended or
|
|
81
|
+
* replaced it, and storage events never reach the document that wrote them.
|
|
82
|
+
* True when the cached session is still the one to resume.
|
|
83
|
+
*/
|
|
84
|
+
export function resyncStoredSession() {
|
|
85
|
+
const change = applyStoredRecord(getRecorderStorage().getString(REC_KEY) ?? null);
|
|
86
|
+
if (change !== 'ended' && change !== 'joined')
|
|
87
|
+
return true;
|
|
88
|
+
notify();
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
50
91
|
export function followOtherTabs() {
|
|
51
92
|
const storage = getRecorderStorage();
|
|
52
93
|
const participant = registerRecorderTab();
|
|
53
94
|
const offRec = storage.watch?.(REC_KEY, (raw) => {
|
|
54
|
-
const
|
|
55
|
-
const change = adoptStoredState(raw);
|
|
95
|
+
const change = applyStoredRecord(raw);
|
|
56
96
|
if (change === 'unchanged')
|
|
57
97
|
return;
|
|
58
98
|
participant?.sync();
|
|
59
|
-
if (change === 'ended')
|
|
60
|
-
setRedactionPolicy(null);
|
|
61
|
-
if (change === 'joined') {
|
|
62
|
-
recoverRedactionPolicy();
|
|
63
|
-
armReconcile();
|
|
64
|
-
}
|
|
65
|
-
// The starting tab writes the workspace policy after its first record:
|
|
66
|
-
// its rules apply here the moment they arrive.
|
|
67
|
-
const policy = getState()?.policy;
|
|
68
|
-
if (change === 'updated' && had === undefined && policy !== undefined)
|
|
69
|
-
setRedactionPolicy(policy);
|
|
70
99
|
notify();
|
|
71
100
|
if (getState()?.stopping)
|
|
72
101
|
void participant?.settle().catch((error) => {
|
|
@@ -121,22 +150,39 @@ export function createSession(title, opts = {}) {
|
|
|
121
150
|
},
|
|
122
151
|
});
|
|
123
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Start a recording. The claim on this document comes first, synchronously
|
|
155
|
+
* and before any network call: while the extension (or another recorder on
|
|
156
|
+
* this page) leads, this rejects with a `RecorderBusyError` and nothing is
|
|
157
|
+
* created (ONE recorder D12).
|
|
158
|
+
*/
|
|
124
159
|
export async function startSession(opts = {}) {
|
|
160
|
+
claimForStart();
|
|
125
161
|
// The safe defaults apply from the first captured byte; the workspace
|
|
126
162
|
// policy (fetched in parallel — fetchPolicy never rejects) can only ADD
|
|
127
163
|
// rules or, self-host only, fullFidelity.
|
|
128
164
|
setRedactionPolicy(null);
|
|
129
165
|
const policyPromise = fetchPolicy();
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
166
|
+
let ses;
|
|
167
|
+
try {
|
|
168
|
+
ses = await createSession(opts.title || '', {
|
|
169
|
+
...(opts.environment ? { environment: opts.environment } : {}),
|
|
170
|
+
...(opts.driver ? { meta: { driver: opts.driver } } : {}),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
// Nothing was created: the `starting` claim goes.
|
|
175
|
+
settleStart(false);
|
|
176
|
+
throw e;
|
|
177
|
+
}
|
|
178
|
+
void policyPromise.then(({ policy, attachments }) => {
|
|
135
179
|
const rec = getState();
|
|
136
180
|
if (rec?.sessionId !== ses.id)
|
|
137
181
|
return;
|
|
138
182
|
setRedactionPolicy(policy);
|
|
139
|
-
setState({ ...rec, policy });
|
|
183
|
+
setState({ ...rec, policy, attachments });
|
|
184
|
+
// The sheets offer images from here on (canAttach).
|
|
185
|
+
notify();
|
|
140
186
|
});
|
|
141
187
|
setState({
|
|
142
188
|
sessionId: ses.id,
|
|
@@ -149,9 +195,13 @@ export async function startSession(opts = {}) {
|
|
|
149
195
|
activeMs: 0,
|
|
150
196
|
resumeAt: new Date().toISOString(),
|
|
151
197
|
});
|
|
198
|
+
// The claim moves from `starting` to `recording` with the session's id.
|
|
199
|
+
settleStart(true);
|
|
152
200
|
resetQueues();
|
|
153
201
|
resetHealth();
|
|
154
202
|
resetIdle();
|
|
203
|
+
// Images an earlier session left in the blob journal (a tab closed mid-upload) never go now.
|
|
204
|
+
void pruneBlobJournal();
|
|
155
205
|
noteRecent({
|
|
156
206
|
sessionId: ses.id,
|
|
157
207
|
title: ses.title,
|
|
@@ -161,6 +211,10 @@ export async function startSession(opts = {}) {
|
|
|
161
211
|
});
|
|
162
212
|
await attachTags(ses.id, opts.tags);
|
|
163
213
|
armReconcile();
|
|
214
|
+
// The start's nav names where the document is NOW (a recorder bundle that
|
|
215
|
+
// followed until this Start never heard the navigations in between) and
|
|
216
|
+
// seeds the nav lane's dedupe with it.
|
|
217
|
+
primeNavigation();
|
|
164
218
|
pushEvent('nav', { url: redactUrl(currentUrl()), route: currentRoute.pathname }, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
|
|
165
219
|
notify();
|
|
166
220
|
return getState();
|
|
@@ -205,9 +259,29 @@ export async function togglePause() {
|
|
|
205
259
|
return rec.paused;
|
|
206
260
|
}
|
|
207
261
|
const route = () => ({ tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
|
|
208
|
-
/**
|
|
209
|
-
|
|
210
|
-
|
|
262
|
+
/**
|
|
263
|
+
* The images a note may carry: none unless this session's policy read said
|
|
264
|
+
* `attachments: true` (the workspace switch, D6) — the HUD offers none then,
|
|
265
|
+
* and another caller's are not uploaded against it.
|
|
266
|
+
*/
|
|
267
|
+
function imagesOf(list) {
|
|
268
|
+
if (!list?.length)
|
|
269
|
+
return [];
|
|
270
|
+
if (getState()?.attachments !== true) {
|
|
271
|
+
console.warn('vitrinka: this session takes no attachments — the note is sent without its images');
|
|
272
|
+
return [];
|
|
273
|
+
}
|
|
274
|
+
return stageAttachments(list);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* A plain note — `{text, route}`, the extension's shape. With attachments
|
|
278
|
+
* (recorder attachments) each image becomes an `attachment` event whose seq
|
|
279
|
+
* is allocated just before the note's, in this tab's lane, and the note
|
|
280
|
+
* lists them: `{text, route, attachments: [seq…]}`; `text` may then be
|
|
281
|
+
* empty. Their bytes upload through `/shot` before their rows ride (queue.ts).
|
|
282
|
+
*/
|
|
283
|
+
export function addNote(text, attachments) {
|
|
284
|
+
pushEvent('note', { text, route: currentRoute.pathname }, route(), imagesOf(attachments));
|
|
211
285
|
}
|
|
212
286
|
/** Scale a viewport rect to device pixels — the extension's `imageRect` space. */
|
|
213
287
|
export function imagePixels(r) {
|
|
@@ -224,7 +298,7 @@ export function imagePixels(r) {
|
|
|
224
298
|
* annotate: true}` (+ `task` when the tester chose the task destination);
|
|
225
299
|
* vitrinka projects it into a board annotation. `selector` is '' for a free
|
|
226
300
|
* region. The rect is in device pixels. An empty note is still a valid
|
|
227
|
-
* annotation, matching the extension.
|
|
301
|
+
* annotation, matching the extension. `attachments` ride as for `addNote`.
|
|
228
302
|
*/
|
|
229
303
|
export function addAnnotation(text, rect, selector, opts = {}) {
|
|
230
304
|
pushEvent('note', {
|
|
@@ -234,7 +308,7 @@ export function addAnnotation(text, rect, selector, opts = {}) {
|
|
|
234
308
|
annotate: true,
|
|
235
309
|
route: currentRoute.pathname,
|
|
236
310
|
...(opts.task ? { task: true } : {}),
|
|
237
|
-
}, route());
|
|
311
|
+
}, route(), imagesOf(opts.attachments));
|
|
238
312
|
}
|
|
239
313
|
/**
|
|
240
314
|
* Hooks that run at the top of Stop, before the drain snapshot — the rrweb
|
|
@@ -255,11 +329,14 @@ export async function stopSession() {
|
|
|
255
329
|
// The other tabs leave rec at the Stop, not when the save ends; a stop
|
|
256
330
|
// that keeps the session hands it back to them as it now is.
|
|
257
331
|
markStopping(rec.sessionId, durationMs);
|
|
332
|
+
// The claim reads `stopping` while the drain runs (a remote stop or pause is refused meanwhile).
|
|
333
|
+
setLeadStopping(rec.sessionId);
|
|
258
334
|
try {
|
|
259
335
|
return await finishStop(rec, durationMs, peers);
|
|
260
336
|
}
|
|
261
337
|
finally {
|
|
262
338
|
markStopping(null);
|
|
339
|
+
setLeadStopping(null);
|
|
263
340
|
}
|
|
264
341
|
}
|
|
265
342
|
async function finishStop(rec, durationMs, peers) {
|
|
@@ -271,6 +348,7 @@ async function finishStop(rec, durationMs, peers) {
|
|
|
271
348
|
setState(null);
|
|
272
349
|
setRedactionPolicy(null);
|
|
273
350
|
resetQueues();
|
|
351
|
+
void pruneBlobJournal(rec.sessionId);
|
|
274
352
|
notify();
|
|
275
353
|
throw new Error(`${reason || 'session rejected by the server'} — recording ended locally` +
|
|
276
354
|
(kept ? `; ${kept} undelivered item(s) discarded` : ''));
|
|
@@ -324,6 +402,8 @@ async function finishStop(rec, durationMs, peers) {
|
|
|
324
402
|
setRedactionPolicy(null);
|
|
325
403
|
resetQueues();
|
|
326
404
|
}
|
|
405
|
+
// Every image of it is the server's (or never will be): the journal lets go of the session.
|
|
406
|
+
void pruneBlobJournal(rec.sessionId);
|
|
327
407
|
notify();
|
|
328
408
|
return done;
|
|
329
409
|
}
|
|
@@ -22,5 +22,14 @@ export declare const annotateState: {
|
|
|
22
22
|
active: boolean;
|
|
23
23
|
};
|
|
24
24
|
export declare function setAnnotating(active: boolean): void;
|
|
25
|
+
/**
|
|
26
|
+
* ONE recorder (lead.ts): who else leads this document's recording while
|
|
27
|
+
* this recorder follows — `'extension'` or `'page'` (another recorder bundle
|
|
28
|
+
* on the page) — else null. A follower captures nothing: every lane, the
|
|
29
|
+
* rrweb stream and the flight recorder check it.
|
|
30
|
+
*/
|
|
31
|
+
export declare const leadState: {
|
|
32
|
+
following: 'page' | 'extension' | null;
|
|
33
|
+
};
|
|
25
34
|
export declare function subscribe(fn: () => void): () => void;
|
|
26
35
|
export declare function notify(): void;
|
package/build/recorder/state.js
CHANGED
|
@@ -30,6 +30,13 @@ export function setAnnotating(active) {
|
|
|
30
30
|
annotateState.active = active;
|
|
31
31
|
notify();
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* ONE recorder (lead.ts): who else leads this document's recording while
|
|
35
|
+
* this recorder follows — `'extension'` or `'page'` (another recorder bundle
|
|
36
|
+
* on the page) — else null. A follower captures nothing: every lane, the
|
|
37
|
+
* rrweb stream and the flight recorder check it.
|
|
38
|
+
*/
|
|
39
|
+
export const leadState = { following: null };
|
|
33
40
|
// -- change subscription (the HUD re-renders off this) -----------------------
|
|
34
41
|
const listeners = new Set();
|
|
35
42
|
export function subscribe(fn) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The blob journal (recorder attachments D4): the bytes of an attached image
|
|
3
|
+
* waiting for upload, kept in IndexedDB so a queued image survives a tab
|
|
4
|
+
* reload the way the KV store's event tail does — the KV store (localStorage,
|
|
5
|
+
* a few MiB) cannot hold image bytes. Keys are `<sessionId>/<document>.<n>`;
|
|
6
|
+
* the queue writes one before the image's event is journaled, reads it back
|
|
7
|
+
* to upload after a reload, and deletes it once the server acknowledged the
|
|
8
|
+
* image's event. Shared by every tab of the origin, like the KV store.
|
|
9
|
+
*
|
|
10
|
+
* Where IndexedDB is absent the journal is memory; where it refuses to open
|
|
11
|
+
* or write (a storage-disabled profile, some private modes, the quota) its
|
|
12
|
+
* calls reject and the queue keeps the bytes in memory. Either way the image
|
|
13
|
+
* still uploads from this document, only the reload guarantee is lost — and
|
|
14
|
+
* the recorder says so.
|
|
15
|
+
*/
|
|
16
|
+
export interface RecorderBlobStore {
|
|
17
|
+
/** Survives a reload (false for the memory fallback). */
|
|
18
|
+
readonly durable: boolean;
|
|
19
|
+
put(key: string, blob: Blob): Promise<void>;
|
|
20
|
+
/** null when the key was never written or is gone. */
|
|
21
|
+
get(key: string): Promise<Blob | null>;
|
|
22
|
+
delete(key: string): Promise<void>;
|
|
23
|
+
keys(): Promise<string[]>;
|
|
24
|
+
}
|
|
25
|
+
/** The active journal; lazily IndexedDB, else memory. */
|
|
26
|
+
export declare function getRecorderBlobStore(): RecorderBlobStore;
|
|
27
|
+
/** Install a journal (tests; a host with its own store). */
|
|
28
|
+
export declare function configureRecorderBlobStore(store: RecorderBlobStore): void;
|
|
29
|
+
/** In-memory journal — tests, and the non-durable fallback. */
|
|
30
|
+
export declare function memoryBlobStore(): RecorderBlobStore;
|
|
31
|
+
/** Test-only: forget the installed journal. */
|
|
32
|
+
export declare function __resetBlobStoreForTests(): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const DB = 'vitrinka.recorder.blobs';
|
|
2
|
+
const STORE = 'blobs';
|
|
3
|
+
let current = null;
|
|
4
|
+
/** The active journal; lazily IndexedDB, else memory. */
|
|
5
|
+
export function getRecorderBlobStore() {
|
|
6
|
+
if (!current)
|
|
7
|
+
current = typeof indexedDB === 'undefined' ? memoryBlobStore() : indexedDbBlobStore();
|
|
8
|
+
return current;
|
|
9
|
+
}
|
|
10
|
+
/** Install a journal (tests; a host with its own store). */
|
|
11
|
+
export function configureRecorderBlobStore(store) {
|
|
12
|
+
current = store;
|
|
13
|
+
}
|
|
14
|
+
/** In-memory journal — tests, and the non-durable fallback. */
|
|
15
|
+
export function memoryBlobStore() {
|
|
16
|
+
const m = new Map();
|
|
17
|
+
return {
|
|
18
|
+
durable: false,
|
|
19
|
+
put: async (k, b) => void m.set(k, b),
|
|
20
|
+
get: async (k) => m.get(k) ?? null,
|
|
21
|
+
delete: async (k) => void m.delete(k),
|
|
22
|
+
keys: async () => [...m.keys()],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function indexedDbBlobStore() {
|
|
26
|
+
let db;
|
|
27
|
+
const open = () => {
|
|
28
|
+
db ??= new Promise((resolve, reject) => {
|
|
29
|
+
const request = indexedDB.open(DB, 1);
|
|
30
|
+
request.onupgradeneeded = () => request.result.createObjectStore(STORE);
|
|
31
|
+
request.onerror = () => reject(request.error ?? new Error('vitrinka: blob journal did not open'));
|
|
32
|
+
request.onsuccess = () => {
|
|
33
|
+
const opened = request.result;
|
|
34
|
+
opened.onversionchange = () => {
|
|
35
|
+
opened.close();
|
|
36
|
+
db = undefined;
|
|
37
|
+
};
|
|
38
|
+
// Closed by the browser (site data cleared, a lost IndexedDB server): the next call reopens.
|
|
39
|
+
opened.onclose = () => {
|
|
40
|
+
db = undefined;
|
|
41
|
+
};
|
|
42
|
+
resolve(opened);
|
|
43
|
+
};
|
|
44
|
+
}).catch((error) => {
|
|
45
|
+
db = undefined;
|
|
46
|
+
throw error;
|
|
47
|
+
});
|
|
48
|
+
return db;
|
|
49
|
+
};
|
|
50
|
+
const run = async (mode, op) => {
|
|
51
|
+
const conn = open();
|
|
52
|
+
let tx;
|
|
53
|
+
try {
|
|
54
|
+
tx = (await conn).transaction(STORE, mode);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
// A connection that closed without a close event (Safari) refuses every transaction: reopen next time.
|
|
58
|
+
if (db === conn)
|
|
59
|
+
db = undefined;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
const request = op(tx.objectStore(STORE));
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
// A write counts once its transaction commits, not when the request succeeds.
|
|
65
|
+
tx.oncomplete = () => resolve(request.result);
|
|
66
|
+
tx.onabort = tx.onerror = () => reject(tx.error ?? request.error ?? new Error('vitrinka: blob journal transaction failed'));
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
durable: true,
|
|
71
|
+
put: async (k, b) => void (await run('readwrite', (s) => s.put(b, k))),
|
|
72
|
+
get: async (k) => {
|
|
73
|
+
const v = await run('readonly', (s) => s.get(k));
|
|
74
|
+
return v instanceof Blob ? v : null;
|
|
75
|
+
},
|
|
76
|
+
delete: async (k) => void (await run('readwrite', (s) => s.delete(k))),
|
|
77
|
+
keys: async () => (await run('readonly', (s) => s.getAllKeys())).filter((k) => typeof k === 'string'),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Test-only: forget the installed journal. */
|
|
81
|
+
export function __resetBlobStoreForTests() {
|
|
82
|
+
current = null;
|
|
83
|
+
}
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
* document, only the reload-survival guarantee is lost — and it says so once.
|
|
12
12
|
*/
|
|
13
13
|
import { withRecorderLock } from './lock';
|
|
14
|
-
// Keys land as `vitrinka.recorder.<key>`: rec · buffer · chunks ·
|
|
15
|
-
// recorder) and dock · prefs · me · recents (the HUD).
|
|
14
|
+
// Keys land as `vitrinka.recorder.<key>`: rec · buffer · chunks · images ·
|
|
15
|
+
// blobs · link (the recorder) and dock · prefs · me · recents (the HUD). An
|
|
16
|
+
// attached image's bytes live in the blob journal (./blobs, IndexedDB).
|
|
16
17
|
const PREFIX = 'vitrinka.recorder.';
|
|
17
18
|
let current = null;
|
|
18
19
|
let used = false;
|