pup-recorder 0.1.14 → 0.1.16

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/build.ts CHANGED
@@ -24,7 +24,7 @@ const common: Options = {
24
24
  minify: true,
25
25
  treeshake: true,
26
26
  banner: { js: `import "source-map-support/register.js";` },
27
- loader: { ".bin": "binary" },
27
+ loader: { ".zip": "binary" },
28
28
  };
29
29
 
30
30
  await Promise.all([
package/build_rust.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  // Created by Autokaka (qq1909698494@gmail.com) on 2026/02/10.
2
2
 
3
3
  import { $ } from "bun";
4
- import { copyFile, mkdir, writeFile } from "fs/promises";
4
+ import { zipSync } from "fflate";
5
+ import { mkdir, readFile, writeFile } from "fs/promises";
5
6
  import { join } from "path";
6
7
 
7
8
  function getTriple(platform: string, arch: string) {
@@ -27,38 +28,39 @@ function getArtifactName(platform: string) {
27
28
  return null;
28
29
  }
29
30
 
30
- async function copyArtifact(platform: string, arch: string, dir: string) {
31
- const libName = getArtifactName(platform);
32
- if (!libName) return;
33
- const src = join(dir, libName);
34
- const destDir = join("rust");
35
- const dest = join(destDir, `${platform}-${arch}.bin`);
36
- const dts = `declare const sth: unknown;\nexport = sth;\n`;
37
- await mkdir(destDir, { recursive: true });
38
- await copyFile(src, dest);
39
- await writeFile(`${dest}.d.ts`, dts);
40
- }
31
+ const PLATFORMS = ["darwin", "linux", "win32"];
32
+ const ARCHS = ["x64", "arm64"];
33
+ const RUST_DIR = "rust";
41
34
 
42
- async function cargoBuild(platform: string, arch: string) {
35
+ async function cargoBuild(platform: string, arch: string): Promise<[string, Uint8Array] | undefined> {
43
36
  const triple = getTriple(platform, arch);
44
- if (triple) {
45
- if (platform === "win32") {
46
- await $`cargo xwin build --release --quiet --target ${triple}`;
47
- } else {
48
- await $`cargo zigbuild --release --quiet --target ${triple}`;
49
- }
50
- await copyArtifact(platform, arch, `target/${triple}/release`);
37
+ const libName = getArtifactName(platform);
38
+ if (!triple || !libName) return;
39
+
40
+ if (platform === "win32") {
41
+ await $`cargo xwin build --release --quiet --target ${triple}`;
42
+ } else {
43
+ await $`cargo zigbuild --release --quiet --target ${triple}`;
51
44
  }
52
- }
53
45
 
54
- const PLATFORMS = ["darwin", "linux", "win32"];
55
- const ARCHS = ["x64", "arm64"];
46
+ const data = await readFile(join(`target/${triple}/release`, libName));
47
+ return [`${platform}-${arch}.node`, new Uint8Array(data)];
48
+ }
56
49
 
57
50
  export async function buildRust() {
58
51
  await $`cargo install --quiet cargo-zigbuild cargo-xwin`;
52
+
53
+ const entries: [string, Uint8Array][] = [];
59
54
  for (const platform of PLATFORMS) {
60
55
  for (const arch of ARCHS) {
61
- await cargoBuild(platform, arch);
56
+ const entry = await cargoBuild(platform, arch);
57
+ if (entry) entries.push(entry);
62
58
  }
63
59
  }
60
+
61
+ await mkdir(RUST_DIR, { recursive: true });
62
+
63
+ const zip = zipSync(Object.fromEntries(entries));
64
+ await writeFile(join(RUST_DIR, "native.zip"), zip);
65
+ await writeFile(join(RUST_DIR, "native.zip.d.ts"), `declare const data: Uint8Array;\nexport default data;\n`);
64
66
  }
@@ -3,12 +3,14 @@ import { ChildProcess } from 'child_process';
3
3
  import type { Debugger } from 'electron';
4
4
  import type { EncodedAudioChunk as EncodedAudioChunk_2 } from '@napi-rs/webcodecs';
5
5
  import type { EncodedAudioChunkMetadataJs } from '@napi-rs/webcodecs';
6
+ import { EncodedPacket } from 'mediabunny';
6
7
  import type { EncodedVideoChunk as EncodedVideoChunk_2 } from '@napi-rs/webcodecs';
7
8
  import type { EncodedVideoChunkMetadataJs } from '@napi-rs/webcodecs';
8
9
  import { IsobmffOutputFormat } from 'mediabunny';
9
10
  import type { NativeImage } from 'electron';
10
11
  import { Size } from 'electron';
11
12
  import { SpawnOptions } from 'child_process';
13
+ import { StreamTarget } from 'mediabunny';
12
14
  import z from 'zod';
13
15
 
14
16
  declare class AbortLink {
@@ -45,15 +47,42 @@ export declare interface AudioCapture {
45
47
  teardown(): Promise<void>;
46
48
  }
47
49
 
50
+ declare interface AudioInit {
51
+ sampleRate: number;
52
+ numberOfChannels: number;
53
+ description?: Uint8Array;
54
+ }
55
+ export { AudioInit }
56
+ export { AudioInit as AudioInit_alias_1 }
57
+
48
58
  export declare const basedir: string;
49
59
 
50
60
  export declare interface BgraConverter {
51
- new (width: number, height: number): BgraConverter;
61
+ new (width: number, height: number, numThreads?: number): BgraConverter;
52
62
  convert(bgra: Buffer): Promise<Buffer>;
53
63
  }
54
64
 
55
65
  export declare const BgraConverter: BgraConverter;
56
66
 
67
+ declare interface BufferedAudio {
68
+ data: Uint8Array;
69
+ type: EncodedAudioChunk_2["type"];
70
+ timestampS: number;
71
+ durationS: number;
72
+ }
73
+ export { BufferedAudio }
74
+ export { BufferedAudio as BufferedAudio_alias_1 }
75
+
76
+ declare interface BufferedVideo {
77
+ data: Uint8Array;
78
+ alphaSideData?: Uint8Array;
79
+ type: EncodedVideoChunk_2["type"];
80
+ timestampS: number;
81
+ durationS: number;
82
+ }
83
+ export { BufferedVideo }
84
+ export { BufferedVideo as BufferedVideo_alias_1 }
85
+
57
86
  export declare function buildRust(): Promise<void>;
58
87
 
59
88
  export declare function buildWrapperHTML(targetURL: string, size: Size): string;
@@ -80,6 +109,14 @@ declare class ConcurrencyLimiter {
80
109
  export { ConcurrencyLimiter }
81
110
  export { ConcurrencyLimiter as ConcurrencyLimiter_alias_1 }
82
111
 
112
+ declare const createMovMuxer: (opts: MuxerOptions) => HEVCIsobmffMuxer;
113
+ export { createMovMuxer }
114
+ export { createMovMuxer as createMovMuxer_alias_1 }
115
+
116
+ declare const createMp4Muxer: (opts: MuxerOptions) => HEVCIsobmffMuxer;
117
+ export { createMp4Muxer }
118
+ export { createMp4Muxer as createMp4Muxer_alias_1 }
119
+
83
120
  export declare function decodeTimestamp(bitmap: Buffer, size: Size): number | undefined;
84
121
 
85
122
  declare const DEFAULT_DURATION = 5;
@@ -111,12 +148,12 @@ export declare class EncoderPipeline {
111
148
  private readonly _entries;
112
149
  private readonly _converter;
113
150
  private _frameIndex;
114
- constructor({ width, height, fps, formats }: EncoderPipelineOptions);
151
+ constructor({ width, height, fps, formats, outDir }: EncoderPipelineOptions);
115
152
  setupAudio(sampleRate: number): void;
116
153
  encodeFrame(bgraBuffer: Buffer, timestampUs: number): Promise<void>;
117
154
  encodeAudio(interleavedFloat32Buffer: Buffer, sampleRate: number): void;
118
155
  flush(): Promise<void>;
119
- finalize(outDir: string): Promise<Partial<Record<VideoFormat, string>>>;
156
+ finalize(): Promise<Partial<Record<VideoFormat, string>>>;
120
157
  }
121
158
 
122
159
  export declare interface EncoderPipelineOptions {
@@ -124,6 +161,7 @@ export declare interface EncoderPipelineOptions {
124
161
  height: number;
125
162
  fps: number;
126
163
  formats: VideoFormat[];
164
+ outDir: string;
127
165
  }
128
166
 
129
167
  declare type EnvParser<T> = (value: unknown) => T;
@@ -138,33 +176,11 @@ export declare const FRAME_SYNC_MARKER_HEIGHT = 1;
138
176
 
139
177
  export declare const FRAME_SYNC_MARKER_WIDTH = 32;
140
178
 
141
- declare class HEVCIsobmffMuxer implements MediaMuxer {
142
- private readonly _width;
143
- private readonly _height;
144
- private readonly _format;
145
- private _videoChunks;
146
- private _audioChunks;
147
- private _videoDesc?;
148
- private _audioInit?;
149
- constructor(width: number, height: number, format: IsobmffOutputFormat);
150
- addVideoChunk(chunk: EncodedVideoChunk_2, meta?: EncodedVideoChunkMetadataJs): void;
151
- addAudioChunk(chunk: EncodedAudioChunk_2, meta?: EncodedAudioChunkMetadataJs): void;
152
- finalize(): Promise<Uint8Array>;
179
+ declare class HEVCIsobmffMuxer extends MediaMuxer {
180
+ private readonly format;
181
+ constructor(opts: MuxerOptions, format: IsobmffOutputFormat);
182
+ finalize(): Promise<string>;
153
183
  }
154
- export { HEVCIsobmffMuxer }
155
- export { HEVCIsobmffMuxer as HEVCIsobmffMuxer_alias_1 }
156
-
157
- declare class HEVCMovMuxer extends HEVCIsobmffMuxer {
158
- constructor(width: number, height: number);
159
- }
160
- export { HEVCMovMuxer }
161
- export { HEVCMovMuxer as HEVCMovMuxer_alias_1 }
162
-
163
- declare class HEVCMp4Muxer extends HEVCIsobmffMuxer {
164
- constructor(width: number, height: number);
165
- }
166
- export { HEVCMp4Muxer }
167
- export { HEVCMp4Muxer as HEVCMp4Muxer_alias_1 }
168
184
 
169
185
  export declare function isEmpty(image: NativeImage): boolean;
170
186
 
@@ -219,14 +235,29 @@ export { LoggerLike as LoggerLike_alias_1 }
219
235
 
220
236
  export declare function makeCLI(name: string, callback: CLICallback): Promise<void>;
221
237
 
222
- declare interface MediaMuxer {
238
+ declare abstract class MediaMuxer {
239
+ protected readonly opts: MuxerOptions;
240
+ protected videoChunks: BufferedVideo[];
241
+ protected audioChunks: BufferedAudio[];
242
+ protected videoDesc?: Uint8Array;
243
+ protected audioInit?: AudioInit;
244
+ constructor(opts: MuxerOptions);
223
245
  addVideoChunk(chunk: EncodedVideoChunk_2, meta?: EncodedVideoChunkMetadataJs): void;
224
246
  addAudioChunk(chunk: EncodedAudioChunk_2, meta?: EncodedAudioChunkMetadataJs): void;
225
- finalize(): Promise<Uint8Array>;
247
+ abstract finalize(): Promise<string>;
226
248
  }
227
249
  export { MediaMuxer }
228
250
  export { MediaMuxer as MediaMuxer_alias_1 }
229
251
 
252
+ declare interface MuxerOptions {
253
+ width: number;
254
+ height: number;
255
+ fps: number;
256
+ outPath: string;
257
+ }
258
+ export { MuxerOptions }
259
+ export { MuxerOptions as MuxerOptions_alias_1 }
260
+
230
261
  export declare interface NetworkOptions {
231
262
  source: string;
232
263
  window: BrowserWindow;
@@ -237,6 +268,10 @@ declare function noerr<Fn extends (...args: any[]) => any, D>(fn: Fn, defaultVal
237
268
  export { noerr }
238
269
  export { noerr as noerr_alias_1 }
239
270
 
271
+ declare const openFileStreamTarget: (path: string) => Promise<StreamTarget>;
272
+ export { openFileStreamTarget }
273
+ export { openFileStreamTarget as openFileStreamTarget_alias_1 }
274
+
240
275
  declare function pargs(): string[];
241
276
  export { pargs }
242
277
  export { pargs as pargs_alias_1 }
@@ -280,10 +315,6 @@ declare const pupDisableGPU: boolean;
280
315
  export { pupDisableGPU }
281
316
  export { pupDisableGPU as pupDisableGPU_alias_1 }
282
317
 
283
- declare const pupFFmpegPath: string;
284
- export { pupFFmpegPath }
285
- export { pupFFmpegPath as pupFFmpegPath_alias_1 }
286
-
287
318
  declare const pupLogLevel: number;
288
319
  export { pupLogLevel }
289
320
  export { pupLogLevel as pupLogLevel_alias_1 }
@@ -350,7 +381,7 @@ export { RetryOptions as RetryOptions_alias_1 }
350
381
 
351
382
  export declare function runElectronApp(size: Size, args: unknown[]): Promise<ProcessHandle>;
352
383
 
353
- export declare function setInterceptor({ source, window, useInnerProxy, }: NetworkOptions): void;
384
+ export declare function setInterceptor({ source, window, useInnerProxy }: NetworkOptions): void;
354
385
 
355
386
  export declare function setupAudioCapture(pipeline: EncoderPipeline): Promise<AudioCapture>;
356
387
 
@@ -364,9 +395,13 @@ export declare function startSync(cdp: Debugger): Promise<any>;
364
395
 
365
396
  export declare function stopSync(cdp: Debugger): Promise<any>;
366
397
 
398
+ declare const toPacket: ({ data, type, timestampS, durationS }: BufferedVideo | BufferedAudio) => EncodedPacket;
399
+ export { toPacket }
400
+ export { toPacket as toPacket_alias_1 }
401
+
367
402
  export declare function unsetInterceptor(window: BrowserWindow): void;
368
403
 
369
- declare function useRetry<Args extends any[], Ret>({ fn, maxAttempts, timeout, }: RetryOptions<Args, Ret>): (...args: Args) => Promise<Ret>;
404
+ declare function useRetry<Args extends any[], Ret>({ fn, maxAttempts, timeout }: RetryOptions<Args, Ret>): (...args: Args) => Promise<Ret>;
370
405
  export { useRetry }
371
406
  export { useRetry as useRetry_alias_1 }
372
407
 
@@ -387,17 +422,8 @@ declare type VideoFormat = (typeof VIDEO_FORMATS)[number];
387
422
  export { VideoFormat }
388
423
  export { VideoFormat as VideoFormat_alias_1 }
389
424
 
390
- declare class Vp9WebMMuxer implements MediaMuxer {
391
- private readonly _width;
392
- private readonly _height;
393
- private _videoChunks;
394
- private _audioChunks;
395
- private _videoDesc?;
396
- private _audioInit?;
397
- constructor(width: number, height: number);
398
- addVideoChunk(chunk: EncodedVideoChunk_2, meta?: EncodedVideoChunkMetadataJs): void;
399
- addAudioChunk(chunk: EncodedAudioChunk_2, meta?: EncodedAudioChunkMetadataJs): void;
400
- finalize(): Promise<Uint8Array>;
425
+ declare class Vp9WebMMuxer extends MediaMuxer {
426
+ finalize(): Promise<string>;
401
427
  }
402
428
  export { Vp9WebMMuxer }
403
429
  export { Vp9WebMMuxer as Vp9WebMMuxer_alias_1 }