pup-recorder 0.4.2 → 0.4.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/biome.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/latest/schema.json",
3
+ "root": false,
4
+ "formatter": { "indentStyle": "space", "indentWidth": 2, "lineWidth": 120 },
5
+ "javascript": { "formatter": { "quoteStyle": "double", "semicolons": "always", "trailingCommas": "all" } },
6
+ "linter": {
7
+ "rules": {
8
+ "complexity": { "useLiteralKeys": "off" },
9
+ "style": {
10
+ "noNonNullAssertion": "off",
11
+ "useBlockStatements": "error",
12
+ "useNamingConvention": {
13
+ "level": "error",
14
+ "options": {
15
+ "strictCase": false,
16
+ "conventions": [
17
+ { "selector": { "kind": "classProperty", "modifiers": ["private"] }, "match": "_(.+)" },
18
+ { "selector": { "kind": "typeProperty" }, "match": "__.+|[a-z][A-Za-z0-9]*|[a-z][a-z0-9]*(?:_[a-z0-9]+)*|[A-Z][A-Za-z0-9]*|[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*" },
19
+ { "selector": { "kind": "objectLiteralProperty" }, "formats": ["camelCase", "snake_case", "PascalCase", "CONSTANT_CASE"] },
20
+ { "selector": { "kind": "variable" }, "formats": ["camelCase", "snake_case", "PascalCase", "CONSTANT_CASE"] },
21
+ { "selector": { "kind": "enumMember" }, "formats": ["PascalCase", "CONSTANT_CASE"] }
22
+ ]
23
+ }
24
+ }
25
+ }
26
+ }
27
+ },
28
+ "files": { "includes": ["src/**/*.ts"] }
29
+ }
package/build.ts CHANGED
@@ -8,8 +8,11 @@ import { dependencies } from "./package.json";
8
8
  const require = createRequire(import.meta.url);
9
9
  const tsPath = require.resolve("@typescript/native-preview/package.json");
10
10
  const tsgo = join(tsPath, "..", "bin", "tsgo.js");
11
+ const biomePath = require.resolve("@biomejs/biome/package.json");
12
+ const biome = join(biomePath, "..", "bin", "biome");
11
13
 
12
14
  await $`${tsgo}`;
15
+ await $`${biome} check --write src`;
13
16
  await rm("dist", { recursive: true, force: true });
14
17
 
15
18
  const common: Options = {
@@ -38,8 +41,8 @@ await build({
38
41
  ...common,
39
42
  entry: [
40
43
  "src/app.ts", //
41
- "src/audio_preload.ts",
42
- "src/iframe_preload.ts",
44
+ "src/runtime/audio_preload.ts",
45
+ "src/runtime/iframe_preload.ts",
43
46
  ],
44
47
  format: "cjs",
45
48
  outDir: "dist",
@@ -3,33 +3,42 @@ import { AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
3
3
  import { AVColorRange } from 'node-av/constants';
4
4
  import { AVPixelFormat } from 'node-av/constants';
5
5
  import { BrowserWindow } from 'electron';
6
- import { ChildProcess } from 'child_process';
6
+ import { ChildProcess } from 'node:child_process';
7
7
  import { Codec } from 'node-av';
8
8
  import { CodecContext } from 'node-av';
9
- import { Debugger } from 'electron';
10
- import { EventEmitter } from 'events';
9
+ import type { Debugger } from 'electron';
10
+ import { Demuxer } from 'node-av/api';
11
+ import { EventEmitter } from 'node:events';
11
12
  import { FFAudioEncoder } from 'node-av/constants';
12
- import { FFVideoEncoder } from 'node-av/constants';
13
+ import type { FFVideoEncoder } from 'node-av/constants';
13
14
  import { FormatContext } from 'node-av';
14
15
  import { Frame } from 'node-av';
15
16
  import { HardwareContext } from 'node-av/api';
16
17
  import { HardwareFramesContext } from 'node-av';
17
18
  import type { NativeImage } from 'electron';
18
19
  import { Packet } from 'node-av';
19
- import { Size } from 'electron';
20
+ import type { Size } from 'electron';
20
21
  import { SoftwareScaleContext } from 'node-av';
21
- import { SpawnOptions } from 'child_process';
22
+ import { SpawnOptions } from 'node:child_process';
22
23
  import { Stream } from 'node-av';
23
- import { WebContents } from 'electron';
24
+ import type { WebContents } from 'electron';
24
25
  import type { WebFrameMain } from 'electron';
25
26
  import z from 'zod';
26
27
 
28
+ export declare function abortable<T>(p: Promise<T>, signal?: AbortSignal): Promise<T>;
29
+
27
30
  /** Insert emulation prevention bytes (00 00 03) for Annex B compliance. */
28
31
  export declare function addEmulationPrevention(nal: Buffer): Buffer;
29
32
 
30
33
  export declare function advance(hook: VideoHook, timestampMs: number): Promise<unknown>;
31
34
 
32
- export declare function advanceVideos(frame: WebFrameMain | undefined, timestampMs: number): Promise<void>;
35
+ export declare interface AdvanceOptions {
36
+ frame: WebFrameMain | undefined;
37
+ timestampMs: number;
38
+ signal?: AbortSignal;
39
+ }
40
+
41
+ export declare function advanceVideos({ frame, timestampMs, signal }: AdvanceOptions): Promise<void>;
33
42
 
34
43
  export declare function advanceVirtualTime(cdp: Debugger, budget: number): Promise<void>;
35
44
 
@@ -135,7 +144,7 @@ export declare function buildStegoHTML(targetURL: string, size: Size): string;
135
144
  export declare function buildUnifiedExtradata(opts: UnifiedExtradataOptions): Buffer;
136
145
 
137
146
  export declare interface CancelMsg {
138
- type: IpcMsgType.CANCEL;
147
+ type: IpcMsgType.Cancel;
139
148
  reason?: string;
140
149
  }
141
150
 
@@ -189,7 +198,7 @@ export declare class ConcurrencyLimiter {
189
198
  export declare type ConsoleCallback = (level: string, message: string) => void;
190
199
 
191
200
  export declare interface ConsoleMsg {
192
- type: IpcMsgType.CONSOLE;
201
+ type: IpcMsgType.Console;
193
202
  level: string;
194
203
  message: string;
195
204
  }
@@ -200,20 +209,29 @@ export declare function createStegoURL(src: string, size: Size): string;
200
209
 
201
210
  export declare function debounce<T extends (...args: unknown[]) => void>(fn: T, delay?: number): T;
202
211
 
212
+ export declare interface DecodedFrame {
213
+ idx: number;
214
+ buf: Buffer;
215
+ }
216
+
217
+ export declare function decodeFrames(src: string, meta: VideoMeta, signal: AbortSignal): AsyncGenerator<DecodedFrame>;
218
+
203
219
  export declare class DecodeSession {
204
220
  readonly meta: VideoMeta;
205
- private readonly src;
206
- private buf;
207
- private ready;
208
- private want;
209
- private done;
210
- private closed;
211
- private gen;
212
- private ctrl;
213
- private waiters;
214
- private resume;
215
- private restart;
216
- constructor(meta: VideoMeta, src: string);
221
+ private readonly _src;
222
+ private _buf;
223
+ private _ready;
224
+ private _want;
225
+ private _done;
226
+ private _closed;
227
+ private _gen;
228
+ private _ctrl;
229
+ private _waiters;
230
+ private _resume;
231
+ private _restart;
232
+ private readonly _leadFrames;
233
+ private readonly _keepCount;
234
+ constructor(meta: VideoMeta, _src: string);
217
235
  getFrame(idx: number): Promise<Buffer>;
218
236
  close(): void;
219
237
  private wait;
@@ -247,12 +265,16 @@ declare const DEFAULT_WIDTH = 1920;
247
265
  export { DEFAULT_WIDTH }
248
266
  export { DEFAULT_WIDTH as DEFAULT_WIDTH_alias_1 }
249
267
 
268
+ declare const DEFAULT_WINDOW_TIMEOUT = 10;
269
+ export { DEFAULT_WINDOW_TIMEOUT }
270
+ export { DEFAULT_WINDOW_TIMEOUT as DEFAULT_WINDOW_TIMEOUT_alias_1 }
271
+
250
272
  export declare const defaultRenderOptions: RenderOptions;
251
273
 
252
274
  export declare function disposeWindow(win: BrowserWindow): Promise<void>;
253
275
 
254
276
  export declare interface DoneMsg {
255
- type: IpcMsgType.DONE;
277
+ type: IpcMsgType.Done;
256
278
  payload: IpcDonePayload;
257
279
  }
258
280
 
@@ -310,7 +332,7 @@ export declare interface EncoderPipelineOptions {
310
332
  export declare type EnvParser<T> = (value: unknown) => T;
311
333
 
312
334
  export declare interface ErrorMsg {
313
- type: IpcMsgType.ERROR;
335
+ type: IpcMsgType.Error;
314
336
  error: string;
315
337
  }
316
338
 
@@ -339,7 +361,7 @@ export declare const FRAME_SYNC_MARKER_HEIGHT = 1;
339
361
  export declare const FRAME_SYNC_MARKER_WIDTH = 32;
340
362
 
341
363
  export declare class FrameCache {
342
- private caches;
364
+ private _caches;
343
365
  cacheOf(id: string): VideoCache;
344
366
  fetch(state: VideoState, idx: number): Promise<ImageBitmap | null>;
345
367
  prefetch(state: VideoState, fromIdx: number, count: number): void;
@@ -382,15 +404,12 @@ export declare class FrameDropStats {
382
404
  }
383
405
 
384
406
  export declare class FrameServer {
385
- private sessions;
386
- private srcs;
387
- private inFlightOpens;
388
- private closed;
407
+ private _sessions;
408
+ private _closed;
389
409
  open(opts: OpenOptions): Promise<VideoMeta>;
390
- private openInner;
391
410
  getFrame(id: string, idx: number): Promise<Buffer>;
392
411
  close(id: string): void;
393
- closeAll(): Promise<void>;
412
+ closeAll(): void;
394
413
  }
395
414
 
396
415
  export declare const frameServer: FrameServer;
@@ -445,12 +464,12 @@ export declare interface IpcEvents {
445
464
 
446
465
  export declare type IpcMsg = ConsoleMsg | ProgressMsg | DoneMsg | ErrorMsg | CancelMsg;
447
466
 
448
- export declare const enum IpcMsgType {
449
- CONSOLE = "console",
450
- PROGRESS = "progress",
451
- DONE = "done",
452
- ERROR = "error",
453
- CANCEL = "cancel"
467
+ export declare enum IpcMsgType {
468
+ Console = "console",
469
+ Progress = "progress",
470
+ Done = "done",
471
+ Error = "error",
472
+ Cancel = "cancel"
454
473
  }
455
474
 
456
475
  export declare class IpcReader extends EventEmitter<IpcEvents> {
@@ -579,7 +598,7 @@ export declare interface NetworkOptions {
579
598
 
580
599
  export declare function newVideoState(video: HTMLVideoElement, cv: HTMLCanvasElement): VideoState;
581
600
 
582
- declare function noerr<Fn extends (...args: any[]) => any, D>(fn: Fn, defaultValue: D): (...args: Parameters<Fn>) => ReturnType<Fn> | D;
601
+ declare function noerr<A extends unknown[], R, D>(fn: (...args: A) => R, defaultValue: D): (...args: A) => R | D;
583
602
  export { noerr }
584
603
  export { noerr as noerr_alias_1 }
585
604
 
@@ -606,6 +625,8 @@ export declare interface NvencHevcConfig {
606
625
  ppsHasLoopFilterAcrossSlicesFlag: boolean;
607
626
  }
608
627
 
628
+ export declare function openInput(src: string, signal?: AbortSignal): Promise<Demuxer>;
629
+
609
630
  export declare interface OpenOptions {
610
631
  src: string;
611
632
  fps: number;
@@ -671,6 +692,8 @@ export declare interface ProbeResult {
671
692
  width: number;
672
693
  height: number;
673
694
  duration: number;
695
+ /** PTS (s) of the first decodable frame; a corrupt/empty leading run is held on it, like Chrome. */
696
+ leadGap: number;
674
697
  }
675
698
 
676
699
  export declare interface ProcessHandle {
@@ -705,7 +728,7 @@ export { ProgressCallback }
705
728
  export { ProgressCallback as ProgressCallback_alias_1 }
706
729
 
707
730
  export declare interface ProgressMsg {
708
- type: IpcMsgType.PROGRESS;
731
+ type: IpcMsgType.Progress;
709
732
  value: number;
710
733
  }
711
734
 
@@ -745,7 +768,7 @@ export declare function removeEmulationPrevention(data: Buffer): Buffer;
745
768
 
746
769
  export declare function render(options: IPCRenderOptions): Promise<IpcDonePayload>;
747
770
 
748
- declare type RenderOptions = z.infer<typeof RenderSchema>;
771
+ declare type RenderOptions = z.infer<typeof renderSchema>;
749
772
  export { RenderOptions }
750
773
  export { RenderOptions as RenderOptions_alias_1 }
751
774
 
@@ -758,7 +781,7 @@ declare interface RenderResult {
758
781
  export { RenderResult }
759
782
  export { RenderResult as RenderResult_alias_1 }
760
783
 
761
- export declare const RenderSchema: z.ZodObject<{
784
+ export declare const renderSchema: z.ZodObject<{
762
785
  duration: z.ZodNumber;
763
786
  width: z.ZodNumber;
764
787
  height: z.ZodNumber;
@@ -770,11 +793,12 @@ export declare const RenderSchema: z.ZodObject<{
770
793
  disableGpu: z.ZodBoolean;
771
794
  disableHwCodec: z.ZodBoolean;
772
795
  windowTolerant: z.ZodBoolean;
796
+ windowTimeout: z.ZodNumber;
773
797
  }, z.core.$strip>;
774
798
 
775
799
  export declare function resizeDrawable(cdp: Debugger, size: Size): Promise<void>;
776
800
 
777
- declare interface RetryOptions<Args extends any[], Ret> {
801
+ declare interface RetryOptions<Args extends unknown[], Ret> {
778
802
  fn: (...args: Args) => Promise<Ret>;
779
803
  maxAttempts?: number;
780
804
  timeout?: number;
@@ -844,15 +868,6 @@ export { sleep as sleep_alias_1 }
844
868
  /** Split Annex B bitstream into NAL units. */
845
869
  export declare function splitNalUnits(bitstream: Buffer): NalUnit[];
846
870
 
847
- export declare class SrcCache {
848
- private inFlight;
849
- private ctrl;
850
- localize(src: string): Promise<string>;
851
- abort(): void;
852
- clear(): Promise<void>;
853
- private download;
854
- }
855
-
856
871
  export declare function startElectronCrashReporter(): void;
857
872
 
858
873
  export declare function startStego(cdp: Debugger): Promise<unknown>;
@@ -867,7 +882,7 @@ export declare function syncOverlay(video: HTMLVideoElement, cv: HTMLCanvasEleme
867
882
 
868
883
  export declare const TAG = "[VideoHook]";
869
884
 
870
- export declare function tick(frame: WebFrameMain | undefined, timestampMs: number): Promise<void>;
885
+ export declare function tick(args: AdvanceOptions): Promise<void>;
871
886
 
872
887
  export declare const TICK_SYMBOL = "__pup_tick__";
873
888
 
@@ -888,7 +903,7 @@ export declare interface UnifiedExtradataOptions {
888
903
 
889
904
  export declare function unsetInterceptor(window: BrowserWindow): void;
890
905
 
891
- declare function useRetry<Args extends any[], Ret>({ fn, maxAttempts, timeout, signal }: RetryOptions<Args, Ret>): (...args: Args) => Promise<Ret>;
906
+ declare function useRetry<Args extends unknown[], Ret>({ fn, maxAttempts, timeout, signal, }: RetryOptions<Args, Ret>): (...args: Args) => Promise<Ret>;
892
907
  export { useRetry }
893
908
  export { useRetry as useRetry_alias_1 }
894
909
 
@@ -951,12 +966,14 @@ export declare interface VideoFrameMeta {
951
966
  export declare class VideoHook {
952
967
  readonly sessions: WeakMap<HTMLVideoElement, VideoState>;
953
968
  readonly attaching: WeakMap<HTMLVideoElement, Promise<VideoState | null>>;
969
+ readonly opening: Set<Promise<unknown>>;
954
970
  readonly cache: FrameCache;
955
971
  rvfcSeq: number;
956
972
  currMs: number;
957
- private lastSnapshot;
973
+ private _lastSnapshot;
958
974
  install(): void;
959
975
  attach(video: HTMLVideoElement, native?: boolean): Promise<VideoState | null>;
976
+ ready(): Promise<void>;
960
977
  resume(video: HTMLVideoElement, state: VideoState): void;
961
978
  detach(video: HTMLVideoElement): void;
962
979
  onSrcChange(video: HTMLVideoElement): void;
@@ -974,6 +991,8 @@ export declare interface VideoMeta {
974
991
  frameHeight: number;
975
992
  fps: number;
976
993
  duration: number;
994
+ /** Seconds of corrupt/empty leading content held on the first decodable frame. */
995
+ leadGap: number;
977
996
  }
978
997
 
979
998
  export declare interface VideoMeta_alias_1 {