@kymoscope/sdk 0.8.3 → 0.10.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/dist/importers-2iwVi4cq.js +5 -0
- package/dist/{keys-Iv24Wam2.js → keys-DmtCD10T.js} +1 -1
- package/dist/kymoscope-embed.js +71 -71
- package/dist/kymoscope-sdk.js +89 -85
- package/dist/styles/charts.css +3 -0
- package/dist/types/charts/CameraPanel.d.ts +1 -1
- package/dist/types/charts/ChartBody.d.ts +6 -2
- package/dist/types/charts/runtime.d.ts +1 -1
- package/dist/types/engine/types.d.ts +2 -0
- package/dist/types/index.d.ts +5 -2
- package/dist/types/lib/live/cameraSender.d.ts +17 -6
- package/dist/types/lib/live/publisher.d.ts +78 -7
- package/dist/types/lib/live/types.d.ts +7 -0
- package/dist/types/lib/live/videoTrack.d.ts +8 -0
- package/dist/types/lib/recordings/split.d.ts +10 -0
- package/dist/types/lib/recordings/writer.d.ts +187 -0
- package/dist/types/lib/render/chartFonts.d.ts +2 -0
- package/package.json +4 -1
- package/dist/importers-BVYsv8Vy.js +0 -5
package/dist/styles/charts.css
CHANGED
|
@@ -315,6 +315,9 @@
|
|
|
315
315
|
|
|
316
316
|
.kymo-camera__empty p { margin: 0; }
|
|
317
317
|
|
|
318
|
+
/* Over the canvas: the last frame never shows through (No signal). */
|
|
319
|
+
.kymo-camera__empty--cover { background: var(--chart-bg); }
|
|
320
|
+
|
|
318
321
|
.kymo-camera__empty-icon {
|
|
319
322
|
width: 30px;
|
|
320
323
|
height: 30px;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CameraPanelSettings } from '../lib/panelChartSettings';
|
|
2
|
-
import type
|
|
2
|
+
import { type LiveConnection } from '../lib/live/types';
|
|
3
3
|
import { type VideoSource } from '../lib/live/videoTrack';
|
|
4
4
|
import type { LoadedDataset } from '../types/loadedDataset';
|
|
5
5
|
/** The worksheet's shared chart cursor (engine.view.cursorX), in X data units. */
|
|
@@ -13,7 +13,8 @@ import type { LiveZoomBus } from '../lib/render/liveZoomBus';
|
|
|
13
13
|
import { type WorksheetData } from './useWorksheetData';
|
|
14
14
|
import type { LiveConnection } from '../lib/live/types';
|
|
15
15
|
import type { LoadedDataset } from '../types/loadedDataset';
|
|
16
|
-
|
|
16
|
+
/** 'no-data': nothing loaded; 'empty': nothing chosen or nothing to draw; 'missing': a chosen channel isn't in this data; 'ready'. */
|
|
17
|
+
export type ChartStatus = 'no-data' | 'empty' | 'missing' | 'ready';
|
|
17
18
|
export interface ContextMenuEvent {
|
|
18
19
|
clientX: number;
|
|
19
20
|
clientY: number;
|
|
@@ -56,7 +57,10 @@ export interface ChartBodyProps {
|
|
|
56
57
|
onContextMenu: (e: ContextMenuEvent) => void;
|
|
57
58
|
xyzRef?: Ref<XYZMeshChartHandle>;
|
|
58
59
|
}
|
|
59
|
-
/**
|
|
60
|
+
/** Every column a chart's settings pick (series, slots, lists); helper fields such as the multiband's add picker don't count. */
|
|
61
|
+
export declare function chosenColumns(settings: PanelChartSettings | undefined): string[];
|
|
62
|
+
/** Renders the chart and reports whether it had anything to draw: an empty chart whose chosen
|
|
63
|
+
* channels aren't all in this data says so ('missing'), the same for every kind. */
|
|
60
64
|
export declare function renderChart(p: ChartBodyProps): {
|
|
61
65
|
status: ChartStatus;
|
|
62
66
|
node: ReactNode;
|
|
@@ -33,7 +33,7 @@ export interface ChartViewEvents extends Record<string, unknown> {
|
|
|
33
33
|
}
|
|
34
34
|
export interface ChartView {
|
|
35
35
|
readonly chartId: string;
|
|
36
|
-
/** Current status: 'no-data' (nothing plotted), 'empty' (
|
|
36
|
+
/** Current status: 'no-data' (nothing plotted), 'empty' (nothing chosen or nothing to draw), 'missing' (a chosen channel isn't in this data), 'ready'. */
|
|
37
37
|
status(): ChartStatus | null;
|
|
38
38
|
on<K extends keyof ChartViewEvents>(event: K, cb: (payload: ChartViewEvents[K]) => void): () => void;
|
|
39
39
|
/**
|
|
@@ -175,6 +175,8 @@ export interface LiveConnectionInfo {
|
|
|
175
175
|
customColor: boolean;
|
|
176
176
|
/** When a recording is running: its start time (ms since epoch), else null. */
|
|
177
177
|
recordingSince: number | null;
|
|
178
|
+
/** The plan-limit banner it was opened with (e.g. "Video limit reached this month"), else null. */
|
|
179
|
+
limitNotice?: string | null;
|
|
178
180
|
/** Its columns as of the last structural change (the time column first). */
|
|
179
181
|
channels: string[];
|
|
180
182
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -59,14 +59,17 @@ export type { FunctionDoc } from './lib/mathChannels';
|
|
|
59
59
|
export { buildExportBlob as buildMathChannelsBlob, parseImportFile as parseMathChannelsFile } from './lib/mathChannels/io';
|
|
60
60
|
export type { LiveRelayConfig } from './lib/live/stream';
|
|
61
61
|
export type { LiveStreamDescriptor, LiveStreamOptions, LocalLiveStream, StreamKeyProvider } from './lib/live/types';
|
|
62
|
+
export { VIDEO_LIMIT_NOTICE } from './lib/live/types';
|
|
62
63
|
export type { LiveColumnsBlock, LiveMessage } from './lib/live/buffer';
|
|
63
64
|
export { LIVE_TIME_COLUMN } from './lib/live/buffer';
|
|
64
65
|
export { openMessage, sealMessage, KIND_VIDEO } from './lib/live/wire';
|
|
65
66
|
export { encodeVideo, decodeVideo, fragmentVideo, VIDEO_MAX_FRAGMENT, type VideoMessage } from './lib/live/videoWire';
|
|
66
67
|
export type { VideoSource, EncodedUnit, VideoTrackInfo } from './lib/live/videoTrack';
|
|
67
68
|
export { RecordedVideoSource, type RecordedVideoSourceOptions } from './lib/recordings/videoSource';
|
|
68
|
-
export { LivePublisher, type PublisherDeps, type PublisherOptions, type PublisherState, type PublisherStatus } from './lib/live/publisher';
|
|
69
|
-
export { CameraSender,
|
|
69
|
+
export { LivePublisher, fetchUsage, liveBytesPerSec, RegistryError, type CameraQuality, type LiveProfile, type LiveUsage, type PublisherDeps, type PublisherOptions, type PublisherState, type PublisherStatus } from './lib/live/publisher';
|
|
70
|
+
export { CameraSender, CAMERA_QUALITIES, LOW_PRESET, type CameraPreset, type CameraStats, type CameraLayerStats, type CameraSenderDeps, type CameraRecorder } from './lib/live/cameraSender';
|
|
71
|
+
export { BrowserRecorder, bufferLabel, type BrowserRecorderOptions, type Destination, type OwnStorage, type RecorderStatus } from './lib/recordings/writer';
|
|
72
|
+
export { SPLIT_STEPS, defaultSplit, formatSplit, parseSplit } from './lib/recordings/split';
|
|
70
73
|
export type { RecordingKey } from './lib/recordings/keys';
|
|
71
74
|
export { recordingKeyAad, recordingKeySealAad } from './lib/recordings/keys';
|
|
72
75
|
export { parseKrc, parseKrcHeader, KRC_HEADER_BYTES } from './lib/recordings/krc';
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import type { LivePublisher } from './publisher';
|
|
1
|
+
import type { CameraQuality, LivePublisher } from './publisher';
|
|
2
|
+
export type { CameraQuality };
|
|
2
3
|
export interface CameraPreset {
|
|
3
4
|
width: number;
|
|
4
5
|
height: number;
|
|
5
6
|
fps: number;
|
|
6
7
|
kbps: number;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
/** The frame size of each declarable quality (the getUserMedia ideal and the encoder's size). */
|
|
10
|
+
export declare const CAMERA_QUALITIES: Record<CameraQuality, {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
}>;
|
|
9
14
|
/** The low layer's default: what small panels and camera walls draw. */
|
|
10
15
|
export declare const LOW_PRESET: CameraPreset;
|
|
11
16
|
export interface CameraLayerStats {
|
|
@@ -31,7 +36,14 @@ export interface CameraSenderDeps {
|
|
|
31
36
|
/** The low layer's downscale (test seam); defaults to drawing onto an OffscreenCanvas. The caller closes the result. */
|
|
32
37
|
scale?: (frame: VideoFrame, width: number, height: number) => VideoFrame;
|
|
33
38
|
}
|
|
34
|
-
type Publisher = Pick<LivePublisher, 'send' | 'viewers' | 'onViewers' | '
|
|
39
|
+
type Publisher = Pick<LivePublisher, 'send' | 'viewers' | 'onViewers' | 'bitrateKbps' | 'profile'> & Partial<Pick<LivePublisher, 'seal' | 'sendSealed'>>;
|
|
40
|
+
/** What a recording camera feeds (BrowserRecorder). */
|
|
41
|
+
export interface CameraRecorder {
|
|
42
|
+
/** Frames are wanted (its data stream records): encode even with no viewers. */
|
|
43
|
+
wants(): boolean;
|
|
44
|
+
/** One sealed message at the frame's capture time (ms epoch); `keyframe`: it starts a keyframe. */
|
|
45
|
+
add(sealed: Uint8Array, tMs: number, keyframe: boolean): void;
|
|
46
|
+
}
|
|
35
47
|
export declare class CameraSender {
|
|
36
48
|
private readonly high;
|
|
37
49
|
private readonly lowOpt;
|
|
@@ -46,13 +58,13 @@ export declare class CameraSender {
|
|
|
46
58
|
private stopped;
|
|
47
59
|
private readonly statsFns;
|
|
48
60
|
private lastStats;
|
|
49
|
-
constructor(publisher: Publisher, opts
|
|
50
|
-
preset: CameraPreset;
|
|
61
|
+
constructor(publisher: Publisher, opts?: {
|
|
51
62
|
keyframeS?: number;
|
|
52
63
|
low?: {
|
|
53
64
|
publisher: Publisher;
|
|
54
65
|
preset?: CameraPreset;
|
|
55
66
|
};
|
|
67
|
+
recorder?: CameraRecorder;
|
|
56
68
|
}, deps?: CameraSenderDeps);
|
|
57
69
|
/** Encode frames from `track` (a getUserMedia video track). Resolves once the encoder is configured;
|
|
58
70
|
* frames then flow until stop(). Throws KymoscopeError('camera_codec_unsupported'). A low layer this
|
|
@@ -67,4 +79,3 @@ export declare class CameraSender {
|
|
|
67
79
|
/** Stop encoding. The publishers and the track belong to the caller and keep running. */
|
|
68
80
|
stop(): void;
|
|
69
81
|
}
|
|
70
|
-
export {};
|
|
@@ -42,6 +42,34 @@ export interface PublisherDeps {
|
|
|
42
42
|
save(s: PublisherState): Promise<void>;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
+
export type CameraQuality = '360p' | '480p' | '720p' | '1080p';
|
|
46
|
+
/** What the stream declares before it starts (spec 2026-11-07 declared streams); the server admits or refuses it
|
|
47
|
+
* against the plan. A data stream: `mode` plus `hz` and `channels` (or `sources`, one {hz, channels} per source) and
|
|
48
|
+
* `bytes_per_sec`, the bytes a second it really sends (see liveBytesPerSec): the server admits, and the relay limits
|
|
49
|
+
* the stream, at the larger of it and its own formula. A camera: `mode` plus `quality` and `fps` (1–60); a low layer
|
|
50
|
+
* declares its high camera's profile. */
|
|
51
|
+
export interface LiveProfile {
|
|
52
|
+
mode: 'live' | 'record';
|
|
53
|
+
/** On the wire only (set from splitEvery). */
|
|
54
|
+
split_every?: number;
|
|
55
|
+
hz?: number;
|
|
56
|
+
channels?: number;
|
|
57
|
+
sources?: {
|
|
58
|
+
hz: number;
|
|
59
|
+
channels: number;
|
|
60
|
+
}[];
|
|
61
|
+
/** A data stream's wire bytes a second (required for kind 'data'; finite, > 0). */
|
|
62
|
+
bytes_per_sec?: number;
|
|
63
|
+
quality?: CameraQuality;
|
|
64
|
+
fps?: number;
|
|
65
|
+
/** A data `record` stream's file period: '1m' … '24h' or its seconds (lib/recordings/split.ts); default from
|
|
66
|
+
* `bytes_per_sec` (files of about 150 MB). Sent as `split_every`. The SDK records only cameras (BrowserRecorder). */
|
|
67
|
+
splitEvery?: string | number;
|
|
68
|
+
}
|
|
69
|
+
/** A data stream's `bytes_per_sec`: `messagesPerSec` messages a second of `plaintextBytes` each (one representative
|
|
70
|
+
* message's plaintext as handed to send(), with the samples one message carries), sealed and framed as the publisher
|
|
71
|
+
* sends them. */
|
|
72
|
+
export declare function liveBytesPerSec(plaintextBytes: number, messagesPerSec: number): number;
|
|
45
73
|
export interface PublisherOptions {
|
|
46
74
|
supabaseUrl: string;
|
|
47
75
|
apiKey: string;
|
|
@@ -58,6 +86,13 @@ export interface PublisherOptions {
|
|
|
58
86
|
* stream id (same parent). Both or neither. */
|
|
59
87
|
layer?: 'low';
|
|
60
88
|
lowOf?: string;
|
|
89
|
+
/** Required: what this stream sends (see LiveProfile). */
|
|
90
|
+
profile: LiveProfile;
|
|
91
|
+
/** A heartbeat's notice (a degradation or a quota warning), once per notice until a beat comes without it. */
|
|
92
|
+
onNotice?: (n: {
|
|
93
|
+
code: string;
|
|
94
|
+
message: string;
|
|
95
|
+
}) => void;
|
|
61
96
|
}
|
|
62
97
|
export type PublisherStatus = {
|
|
63
98
|
phase: 'registering';
|
|
@@ -73,6 +108,26 @@ export type PublisherStatus = {
|
|
|
73
108
|
code: string;
|
|
74
109
|
message: string;
|
|
75
110
|
};
|
|
111
|
+
/** A stream-token / stream-publisher call that failed: HTTP status (0: network) and the server's {error, message}. */
|
|
112
|
+
export declare class RegistryError extends Error {
|
|
113
|
+
status: number;
|
|
114
|
+
code: string;
|
|
115
|
+
detail: string;
|
|
116
|
+
constructor(status: number, code: string, message: string);
|
|
117
|
+
}
|
|
118
|
+
/** What the API key's account may still use: each limit (null: unlimited) and this month's usage. */
|
|
119
|
+
export interface LiveUsage {
|
|
120
|
+
limits: Record<string, number | null>;
|
|
121
|
+
usage: {
|
|
122
|
+
liveKbps: number;
|
|
123
|
+
cameraSeconds: number;
|
|
124
|
+
dataBytes: number;
|
|
125
|
+
videoBytes: number;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** The plan's limits and what is used, before starting anything (stream-publisher `usage`). Rejects with the
|
|
129
|
+
* server's {status, code, detail} (status 0: network). */
|
|
130
|
+
export declare function fetchUsage(supabaseUrl: string, apiKey: string, f?: typeof fetch): Promise<LiveUsage>;
|
|
76
131
|
export declare class LivePublisher {
|
|
77
132
|
private readonly opts;
|
|
78
133
|
private readonly deps;
|
|
@@ -82,9 +137,6 @@ export declare class LivePublisher {
|
|
|
82
137
|
private readonly password;
|
|
83
138
|
private token;
|
|
84
139
|
private ticket;
|
|
85
|
-
/** The current ticket says rec (the reply's `recording`); `authRec`: the one the open socket authenticated with. */
|
|
86
|
-
private ticketRec;
|
|
87
|
-
private authRec;
|
|
88
140
|
private relayUrl;
|
|
89
141
|
private apiKeyId;
|
|
90
142
|
private projectId;
|
|
@@ -119,6 +171,10 @@ export declare class LivePublisher {
|
|
|
119
171
|
private readonly statusFns;
|
|
120
172
|
private readonly viewerFns;
|
|
121
173
|
private lastStatus;
|
|
174
|
+
private readonly wire;
|
|
175
|
+
private usage;
|
|
176
|
+
private bitrate;
|
|
177
|
+
private noticeCode;
|
|
122
178
|
constructor(opts: PublisherOptions, deps: PublisherDeps);
|
|
123
179
|
/** The registered stream id (null until start() registers). */
|
|
124
180
|
get streamId(): string | null;
|
|
@@ -129,6 +185,12 @@ export declare class LivePublisher {
|
|
|
129
185
|
maxBytesPerSec: number;
|
|
130
186
|
maxMessageBytes: number;
|
|
131
187
|
};
|
|
188
|
+
/** The register reply's usage line (what was admitted and what is left), for the sender to show; null before. */
|
|
189
|
+
get usageMessage(): string | null;
|
|
190
|
+
/** A camera's bitrate in kbit/s, chosen by the server for its declared quality and fps; null before register. */
|
|
191
|
+
get bitrateKbps(): number | null;
|
|
192
|
+
/** The declared profile as sent to the server (normalised, frozen). */
|
|
193
|
+
get profile(): Readonly<LiveProfile>;
|
|
132
194
|
onStatus(fn: (s: PublisherStatus) => void): () => void;
|
|
133
195
|
onViewers(fn: (n: number) => void): () => void;
|
|
134
196
|
/** Mint, register (reusing a persisted stream id and salt), open the socket, heartbeat. Rejects when
|
|
@@ -137,15 +199,25 @@ export declare class LivePublisher {
|
|
|
137
199
|
/** Seal with the current stream key (the key id of its epoch when e2ee) and send; false if not sent
|
|
138
200
|
* (no key yet, socket down, stopped). */
|
|
139
201
|
send(kind: number, plaintext: Uint8Array): Promise<boolean>;
|
|
140
|
-
/**
|
|
202
|
+
/** The sealed message send() would publish (what a recorder keeps), or null without a stream key yet. */
|
|
203
|
+
seal(kind: number, plaintext: Uint8Array): Promise<Uint8Array<ArrayBuffer> | null>;
|
|
204
|
+
/** Publish an already sealed message; false when the socket is down. */
|
|
205
|
+
sendSealed(message: Uint8Array<ArrayBuffer>): boolean;
|
|
206
|
+
/** One recording-upload call with this stream's `pt.` token (supabase/functions/recording-upload/CONTRACT.md):
|
|
207
|
+
* what a BrowserRecorder needs. Rejects with a RegistryError. */
|
|
208
|
+
recordingUpload(body: Record<string, unknown>): Promise<any>;
|
|
209
|
+
/** Close the socket and stop the timers. The stream stays registered (never deleted here), offline at once: what
|
|
210
|
+
* it declared stops counting against the live limits now, not when the live window runs out. */
|
|
141
211
|
stop(): void;
|
|
142
212
|
private post;
|
|
143
213
|
private mint;
|
|
144
214
|
private call;
|
|
145
215
|
private register;
|
|
216
|
+
private admitted;
|
|
217
|
+
private notice;
|
|
146
218
|
private senderDevice;
|
|
147
219
|
/** Token refresh, then the heartbeat (each new ticket also refreshes the socket). 401/403 stop the
|
|
148
|
-
* publisher (revoked key, plan, stale_epoch); anything else is retried on the next interval. */
|
|
220
|
+
* publisher (revoked key, plan, stale_epoch, a camera's video_hours_exhausted); anything else is retried on the next interval. */
|
|
149
221
|
private housekeeping;
|
|
150
222
|
/** Seal the stream key to the owner's browsers that lack it (password streams), at most 50 per call. */
|
|
151
223
|
private wrapFor;
|
|
@@ -158,8 +230,7 @@ export declare class LivePublisher {
|
|
|
158
230
|
private disconnect;
|
|
159
231
|
/** Reconnect: at once after a stable connection, else after the backoff (1 s doubling to 10 s). */
|
|
160
232
|
private dropped;
|
|
161
|
-
/** Use `ticket` from now on; re-authenticate the open socket in-band when due
|
|
162
|
-
* says rec and the socket's ticket didn't. */
|
|
233
|
+
/** Use `ticket` from now on; re-authenticate the open socket in-band when due. */
|
|
163
234
|
private setTicket;
|
|
164
235
|
private setViewers;
|
|
165
236
|
private refuse;
|
|
@@ -5,6 +5,9 @@ import type { LiveDataSource } from '../data/liveDataSource';
|
|
|
5
5
|
import type { Dataset } from '../parseDataset';
|
|
6
6
|
import type { VideoTrack } from './videoTrack';
|
|
7
7
|
import type { ClockMap } from './clockMap';
|
|
8
|
+
/** A camera's limit_notice once this month's video hours are used up (stream-publisher degrade.ts VIDEO_BANNER): the
|
|
9
|
+
* camera stopped, so its panel shows this instead of video. Any other notice (storage full) leaves the video playing. */
|
|
10
|
+
export declare const VIDEO_LIMIT_NOTICE = "Video limit reached this month";
|
|
8
11
|
/** What a viewer needs to join an encrypted relay stream (from the stream registry). */
|
|
9
12
|
export interface LiveStreamDescriptor {
|
|
10
13
|
id: string;
|
|
@@ -29,6 +32,8 @@ export interface LiveStreamDescriptor {
|
|
|
29
32
|
parent_stream_id?: string | null;
|
|
30
33
|
/** A camera's low layer (360p, for small panels and walls): its high camera's id; null/absent otherwise. */
|
|
31
34
|
low_of_stream_id?: string | null;
|
|
35
|
+
/** Set while a plan limit holds the stream back (e.g. "Video limit reached this month"); null/absent otherwise. */
|
|
36
|
+
limit_notice?: string | null;
|
|
32
37
|
}
|
|
33
38
|
/**
|
|
34
39
|
* The keys of a stream in an end-to-end encrypted project: frames name their key id
|
|
@@ -88,4 +93,6 @@ export interface LiveConnection {
|
|
|
88
93
|
error: string | null;
|
|
89
94
|
/** When a recording is running: its start time (ms since epoch). */
|
|
90
95
|
recordingSince: number | null;
|
|
96
|
+
/** The plan-limit banner it was opened with (LiveStreamDescriptor.limit_notice); a Camera panel shows it. */
|
|
97
|
+
limitNotice?: string | null;
|
|
91
98
|
}
|
|
@@ -15,7 +15,15 @@ export interface VideoTrackInfo {
|
|
|
15
15
|
lagMs: number | null;
|
|
16
16
|
units: number;
|
|
17
17
|
bytes: number;
|
|
18
|
+
/** Live: when the newest unit arrived (local ms), null before the first. */
|
|
19
|
+
arrivedAt?: number | null;
|
|
20
|
+
/** Live: the usual time between arriving units (median of the recent ones, ms), null with fewer than two. */
|
|
21
|
+
gapMs?: number | null;
|
|
18
22
|
}
|
|
23
|
+
/** No unit for this long means the sender stopped (the game stopped, the camera went away): never less than 3 s,
|
|
24
|
+
* and four of the camera's usual gaps for a slow one. */
|
|
25
|
+
export declare const NO_SIGNAL_MIN_MS = 3000;
|
|
26
|
+
export declare function noSignalAfterMs(gapMs: number | null | undefined): number;
|
|
19
27
|
/**
|
|
20
28
|
* A camera's video as the Camera panel plays it: a live camera connection's ring (kind 'live'), or a camera
|
|
21
29
|
* recorded with a cloud recording (kind 'recorded', RecordedVideoSource). Listed by engine.video.sources().
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const SPLIT_STEPS: readonly [60, 300, 900, 1800, 3600, 7200, 14400, 28800, 43200, 86400];
|
|
2
|
+
/** Only a guide for the default period: files are never cut by size (time rules, the user decided 2026-11-09). */
|
|
3
|
+
export declare const FILE_TARGET_BYTES: number;
|
|
4
|
+
/** '1h' / '15m' / 3600 → seconds, or null when it isn't a step. */
|
|
5
|
+
export declare function parseSplit(v: unknown): number | null;
|
|
6
|
+
export declare const formatSplit: (s: number) => string;
|
|
7
|
+
/** The longest step whose file stays under the target at `bytesPerSec`; 1 min when none does. */
|
|
8
|
+
export declare function defaultSplit(bytesPerSec: number): number;
|
|
9
|
+
/** The next cut after `tMs` (strictly later), aligned to the sender's local clock (`utcOffsetS`, e.g. +3600). */
|
|
10
|
+
export declare function nextCut(tMs: number, periodS: number, utcOffsetS: number): number;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
export declare const CHUNK_MS = 60000;
|
|
2
|
+
export declare const CHUNK_MAX_BYTES: number;
|
|
3
|
+
export declare const PARENT_POLL_MS = 10000;
|
|
4
|
+
export declare const FAST_POLL_MS = 2000;
|
|
5
|
+
export declare const PARENT_GONE_MS = 30000;
|
|
6
|
+
/** The wait after a failed upload pass: 2 s, doubling, at most 60 s. */
|
|
7
|
+
export declare const backoff: (ms: number) => number;
|
|
8
|
+
export declare const bufferLabel: (mb: number) => string;
|
|
9
|
+
/** The parts of the File System Access handles the recorder uses (OPFS, a picked folder, or a fake in tests). */
|
|
10
|
+
export interface RecFile {
|
|
11
|
+
kind: 'file';
|
|
12
|
+
getFile(): Promise<Blob>;
|
|
13
|
+
createWritable(): Promise<{
|
|
14
|
+
write(b: BufferSource | Blob | string): Promise<void>;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
export interface RecDir {
|
|
19
|
+
kind: 'directory';
|
|
20
|
+
getDirectoryHandle(name: string, o?: {
|
|
21
|
+
create?: boolean;
|
|
22
|
+
}): Promise<RecDir>;
|
|
23
|
+
getFileHandle(name: string, o?: {
|
|
24
|
+
create?: boolean;
|
|
25
|
+
}): Promise<RecFile>;
|
|
26
|
+
removeEntry(name: string, o?: {
|
|
27
|
+
recursive?: boolean;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
entries(): AsyncIterable<[string, RecDir | RecFile]>;
|
|
30
|
+
}
|
|
31
|
+
/** The project's own storage, reached from this browser (the server only says which one: the keys stay here). */
|
|
32
|
+
export interface OwnStorage {
|
|
33
|
+
/** A folder the user picked (File System Access: Chrome and Edge). */
|
|
34
|
+
folder?: RecDir | FileSystemDirectoryHandle;
|
|
35
|
+
/** S3 or compatible (MinIO, R2…): the bucket must allow PUT from this page's origin (CORS). */
|
|
36
|
+
s3?: {
|
|
37
|
+
endpoint: string;
|
|
38
|
+
region?: string;
|
|
39
|
+
bucket: string;
|
|
40
|
+
prefix?: string;
|
|
41
|
+
accessKeyId: string;
|
|
42
|
+
secretAccessKey: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export interface Destination {
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
kind: 's3' | 'folder';
|
|
49
|
+
}
|
|
50
|
+
export type RecorderStatus = {
|
|
51
|
+
type: 'destination';
|
|
52
|
+
name: string;
|
|
53
|
+
splitEvery: number | null;
|
|
54
|
+
message: string;
|
|
55
|
+
} | {
|
|
56
|
+
type: 'storage_needed';
|
|
57
|
+
destination: Destination;
|
|
58
|
+
message: string;
|
|
59
|
+
} | {
|
|
60
|
+
type: 'refused' | 'buffer_full' | 'chunk_dropped' | 'storage_error' | 'disk_error';
|
|
61
|
+
message: string;
|
|
62
|
+
reason?: string;
|
|
63
|
+
};
|
|
64
|
+
export interface BrowserRecorderOptions {
|
|
65
|
+
/** The camera's stream id. */
|
|
66
|
+
streamId: string;
|
|
67
|
+
/** The data stream the camera belongs to: its files are cut with that stream's recordings. */
|
|
68
|
+
parentStreamId: string;
|
|
69
|
+
/** recording-upload (LivePublisher.recordingUpload); rejects with {status, code} (RegistryError). */
|
|
70
|
+
call: (body: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
71
|
+
/** Local space for chunks not stored yet (default 2048). */
|
|
72
|
+
bufferMaxMB?: number;
|
|
73
|
+
storage?: OwnStorage | null;
|
|
74
|
+
/** Own storage only: how long it keeps the files. */
|
|
75
|
+
retentionDays?: number;
|
|
76
|
+
onStatus?: (s: RecorderStatus) => void;
|
|
77
|
+
/** Test seams. */
|
|
78
|
+
root?: () => Promise<RecDir>;
|
|
79
|
+
fetch?: typeof fetch;
|
|
80
|
+
now?: () => number;
|
|
81
|
+
/** Web Locks (navigator.locks); null: this page is the only uploader. */
|
|
82
|
+
locks?: LockManager | null;
|
|
83
|
+
/** Start the upload loop (default true; tests drive uploadPending/pollParent themselves). */
|
|
84
|
+
autostart?: boolean;
|
|
85
|
+
}
|
|
86
|
+
/** A message without any URL's query string (a presigned S3 URL's signature never reaches a log). */
|
|
87
|
+
export declare const redactUrls: (s: string) => string;
|
|
88
|
+
export declare class BrowserRecorder {
|
|
89
|
+
readonly streamId: string;
|
|
90
|
+
readonly parentStreamId: string;
|
|
91
|
+
readonly bufferMaxMB: number;
|
|
92
|
+
/** Chunks a full buffer dropped before they were stored. */
|
|
93
|
+
dropped: number;
|
|
94
|
+
/** Bytes in the buffer at the last count. */
|
|
95
|
+
usedBytes: number;
|
|
96
|
+
private storage;
|
|
97
|
+
private readonly opts;
|
|
98
|
+
private readonly now;
|
|
99
|
+
private readonly fetch;
|
|
100
|
+
private readonly locks;
|
|
101
|
+
private rootDir;
|
|
102
|
+
/** The data stream's open recording (null: none; undefined: not asked yet), and when it was last asked. */
|
|
103
|
+
private parent;
|
|
104
|
+
private polledAt;
|
|
105
|
+
private polling;
|
|
106
|
+
/** When the data stream's recording is expected to be cut (its period's next clock cut), and since when the server
|
|
107
|
+
* has said it has none open. */
|
|
108
|
+
private cutAt;
|
|
109
|
+
private noneSince;
|
|
110
|
+
private file;
|
|
111
|
+
private chunk;
|
|
112
|
+
private continues;
|
|
113
|
+
/** The last ended file, and the files refused, gone or whose last chunk a full buffer dropped (in memory). */
|
|
114
|
+
private prev;
|
|
115
|
+
private readonly lost;
|
|
116
|
+
/** Disk writes in order (opening a file, its chunks, its end). */
|
|
117
|
+
private io;
|
|
118
|
+
/** Files this recorder still writes: never closed on the server until their end is on disk. */
|
|
119
|
+
private readonly writing;
|
|
120
|
+
private readonly held;
|
|
121
|
+
private readonly opened;
|
|
122
|
+
private readonly blocked;
|
|
123
|
+
private readonly wait;
|
|
124
|
+
private readonly said;
|
|
125
|
+
private fullSaid;
|
|
126
|
+
private refusedUntil;
|
|
127
|
+
private closing;
|
|
128
|
+
private stopped;
|
|
129
|
+
private wake;
|
|
130
|
+
private loop;
|
|
131
|
+
constructor(opts: BrowserRecorderOptions);
|
|
132
|
+
/** Whether frames are wanted now: a file is open or the data stream records (the camera encodes for it). */
|
|
133
|
+
wants(): boolean;
|
|
134
|
+
/** The data stream's file period in seconds (from `current`), null until known. */
|
|
135
|
+
splitEvery: number | null;
|
|
136
|
+
/** The open file's recording id, or null. */
|
|
137
|
+
get currentId(): string | null;
|
|
138
|
+
/** The project's own storage became reachable (the page picked its folder): the files waiting for it go. */
|
|
139
|
+
setStorage(storage: OwnStorage | null): void;
|
|
140
|
+
/** One sealed message at `tMs` (the frame's capture time, ms since epoch). `keyframe`: it starts a keyframe; files
|
|
141
|
+
* open and end only there. */
|
|
142
|
+
add(sealed: Uint8Array, tMs: number, keyframe: boolean): void;
|
|
143
|
+
/** Close a chunk open for CHUNK_MS (the loop calls it every second). */
|
|
144
|
+
tick(): void;
|
|
145
|
+
/** End the current file now (the camera stops); the next file doesn't continue it. */
|
|
146
|
+
stop(): void;
|
|
147
|
+
/** Ask the server for the data stream's open recording (a failure keeps what was known). */
|
|
148
|
+
pollParent(): Promise<void>;
|
|
149
|
+
/** Ask again: every PARENT_POLL_MS; right after the expected cut and every FAST_POLL_MS for a minute past it; and
|
|
150
|
+
* every FAST_POLL_MS while a file is open but the server says none (a cut's gap, or a stop). */
|
|
151
|
+
private pollDue;
|
|
152
|
+
private root;
|
|
153
|
+
/** Run a disk write after the ones before it; a failure is said once and never stops live. */
|
|
154
|
+
private queue;
|
|
155
|
+
private openFile;
|
|
156
|
+
private endFile;
|
|
157
|
+
private flush;
|
|
158
|
+
/** Every file under rec/ counts (one budget for every stream); past it the oldest chunks go. */
|
|
159
|
+
private enforceMax;
|
|
160
|
+
private status;
|
|
161
|
+
private say;
|
|
162
|
+
/** Whether this recorder uploads folder `id`: its own, or a leftover no running recorder holds (a leftover without
|
|
163
|
+
* meta is removed). */
|
|
164
|
+
private claim;
|
|
165
|
+
private release;
|
|
166
|
+
/** [id, meta, dir] of the folders this recorder uploads, oldest first. */
|
|
167
|
+
private files;
|
|
168
|
+
/** Drop a file's chunks here (refused or gone on the server: lost, so the next file continues nothing; or stored
|
|
169
|
+
* and closed); the current one ends. */
|
|
170
|
+
private forget;
|
|
171
|
+
/** The file's destination once opened; null when it was refused (dropped) or can't go yet (kept). */
|
|
172
|
+
private open;
|
|
173
|
+
private put;
|
|
174
|
+
private writeOwn;
|
|
175
|
+
private dropChunk;
|
|
176
|
+
private uploadChunk;
|
|
177
|
+
/** The server lost a file it had opened (404): the chunks still here go under a new recording id, continuing
|
|
178
|
+
* nothing (the current file ends first). False when none are left (the file is forgotten as before). */
|
|
179
|
+
private reopen;
|
|
180
|
+
/** One pass over the files this recorder uploads, oldest first. True when nothing is left to upload (files waiting
|
|
181
|
+
* for their storage aside). Rejects on a failure worth retrying (the caller backs off). */
|
|
182
|
+
uploadPending(): Promise<boolean>;
|
|
183
|
+
private run;
|
|
184
|
+
/** End the current file and give the uploader up to `timeoutMs` to store what is left; the rest stays in the buffer
|
|
185
|
+
* and goes out the next time a camera records on this browser. */
|
|
186
|
+
close(timeoutMs?: number): Promise<void>;
|
|
187
|
+
}
|
|
@@ -8,3 +8,5 @@ export declare const chartFonts: {
|
|
|
8
8
|
sans: string;
|
|
9
9
|
mono: string;
|
|
10
10
|
};
|
|
11
|
+
/** The one text every chart draws when it has nothing to show in its view, centred on the canvas, in the current fill colour. */
|
|
12
|
+
export declare function drawNoData(ctx: CanvasRenderingContext2D): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kymoscope/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "The Kymoscope data engine and charts for the browser: import large measurement files, plot them, stream live data end-to-end encrypted.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"homepage": "https://kymoscope.com/docs/introduction",
|
|
@@ -64,6 +64,9 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"aws4fetch": "1.0.20"
|
|
69
|
+
},
|
|
67
70
|
"main": "./dist/kymoscope-sdk.js",
|
|
68
71
|
"module": "./dist/kymoscope-sdk.js",
|
|
69
72
|
"types": "./dist/types/index.d.ts"
|