@tmhs/screencast-mcp 0.49.0 → 0.50.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.
Files changed (133) hide show
  1. package/README.md +13 -8
  2. package/dist/index.js +550 -106
  3. package/dist/wgcRecorder.js +15 -139
  4. package/package.json +8 -4
  5. package/assets/.gitkeep +0 -0
  6. package/assets/icon.png +0 -0
  7. package/dist/cli.js +0 -516
  8. package/dist/context.js +0 -50
  9. package/dist/prompts.js +0 -95
  10. package/dist/resources.js +0 -93
  11. package/dist/server.js +0 -174
  12. package/dist/setup.js +0 -438
  13. package/dist/tools/addMarker.js +0 -93
  14. package/dist/tools/assembleHighlights.js +0 -69
  15. package/dist/tools/backdrop.js +0 -89
  16. package/dist/tools/bugReport.js +0 -266
  17. package/dist/tools/burnSubtitles.js +0 -56
  18. package/dist/tools/callout.js +0 -103
  19. package/dist/tools/chapters.js +0 -156
  20. package/dist/tools/clip.js +0 -52
  21. package/dist/tools/compress.js +0 -51
  22. package/dist/tools/concat.js +0 -67
  23. package/dist/tools/contactSheet.js +0 -135
  24. package/dist/tools/convert.js +0 -46
  25. package/dist/tools/crop.js +0 -43
  26. package/dist/tools/cursor.js +0 -87
  27. package/dist/tools/cutByTranscript.js +0 -86
  28. package/dist/tools/cutIdle.js +0 -84
  29. package/dist/tools/deleteRecording.js +0 -119
  30. package/dist/tools/denoise.js +0 -60
  31. package/dist/tools/doctor.js +0 -146
  32. package/dist/tools/exportGif.js +0 -57
  33. package/dist/tools/exportPreset.js +0 -48
  34. package/dist/tools/extractAudio.js +0 -65
  35. package/dist/tools/findText.js +0 -196
  36. package/dist/tools/getMediaInfo.js +0 -36
  37. package/dist/tools/getSession.js +0 -40
  38. package/dist/tools/indexRecording.js +0 -195
  39. package/dist/tools/keystrokeOverlay.js +0 -131
  40. package/dist/tools/listAudioDevices.js +0 -35
  41. package/dist/tools/listSessions.js +0 -28
  42. package/dist/tools/listTargets.js +0 -76
  43. package/dist/tools/listVideoDevices.js +0 -26
  44. package/dist/tools/musicBed.js +0 -55
  45. package/dist/tools/narrate.js +0 -86
  46. package/dist/tools/normalizeAudio.js +0 -60
  47. package/dist/tools/overlay.js +0 -62
  48. package/dist/tools/pauseRecording.js +0 -44
  49. package/dist/tools/pipeline.js +0 -400
  50. package/dist/tools/readEvents.js +0 -98
  51. package/dist/tools/redactRegion.js +0 -70
  52. package/dist/tools/reframe.js +0 -46
  53. package/dist/tools/resumeRecording.js +0 -46
  54. package/dist/tools/reviewRecording.js +0 -163
  55. package/dist/tools/sampleFrames.js +0 -200
  56. package/dist/tools/saveReplay.js +0 -90
  57. package/dist/tools/scale.js +0 -44
  58. package/dist/tools/screenDiff.js +0 -86
  59. package/dist/tools/screenshot.js +0 -76
  60. package/dist/tools/searchRecording.js +0 -79
  61. package/dist/tools/speed.js +0 -46
  62. package/dist/tools/startRecording.js +0 -398
  63. package/dist/tools/stepGuide.js +0 -250
  64. package/dist/tools/stopRecording.js +0 -132
  65. package/dist/tools/titleCard.js +0 -67
  66. package/dist/tools/transcribe.js +0 -66
  67. package/dist/tools/trim.js +0 -57
  68. package/dist/tools/waitForChange.js +0 -128
  69. package/dist/tools/xfadeTransition.js +0 -58
  70. package/dist/tools/zoom.js +0 -149
  71. package/dist/utils/anim.js +0 -54
  72. package/dist/utils/animExport.js +0 -56
  73. package/dist/utils/argPaths.js +0 -39
  74. package/dist/utils/audio.js +0 -113
  75. package/dist/utils/audioDevices.js +0 -107
  76. package/dist/utils/backdrop.js +0 -151
  77. package/dist/utils/bugReport.js +0 -172
  78. package/dist/utils/callout.js +0 -90
  79. package/dist/utils/calloutAssets.js +0 -42
  80. package/dist/utils/capabilities.js +0 -96
  81. package/dist/utils/captions.js +0 -103
  82. package/dist/utils/chapters.js +0 -227
  83. package/dist/utils/consent.js +0 -29
  84. package/dist/utils/cursor.js +0 -317
  85. package/dist/utils/diff.js +0 -184
  86. package/dist/utils/errors.js +0 -29
  87. package/dist/utils/events.js +0 -403
  88. package/dist/utils/expr.js +0 -11
  89. package/dist/utils/ffmpeg.js +0 -285
  90. package/dist/utils/fontCoverage.js +0 -177
  91. package/dist/utils/fonts.js +0 -154
  92. package/dist/utils/gpu.js +0 -219
  93. package/dist/utils/idle.js +0 -91
  94. package/dist/utils/images.js +0 -38
  95. package/dist/utils/jobs.js +0 -129
  96. package/dist/utils/keystrokes.js +0 -155
  97. package/dist/utils/lifecycle.js +0 -233
  98. package/dist/utils/logging.js +0 -75
  99. package/dist/utils/media.js +0 -574
  100. package/dist/utils/monitors.js +0 -124
  101. package/dist/utils/narrate.js +0 -233
  102. package/dist/utils/ocr.js +0 -222
  103. package/dist/utils/ocrScan.js +0 -91
  104. package/dist/utils/paths.js +0 -155
  105. package/dist/utils/pause.js +0 -190
  106. package/dist/utils/pipeline.js +0 -361
  107. package/dist/utils/player.js +0 -85
  108. package/dist/utils/pool.js +0 -29
  109. package/dist/utils/produce.js +0 -298
  110. package/dist/utils/recipes.js +0 -71
  111. package/dist/utils/recorder.js +0 -173
  112. package/dist/utils/recordingFiles.js +0 -32
  113. package/dist/utils/recordingIndex.js +0 -312
  114. package/dist/utils/replay.js +0 -283
  115. package/dist/utils/resolveTarget.js +0 -25
  116. package/dist/utils/retention.js +0 -48
  117. package/dist/utils/roots.js +0 -43
  118. package/dist/utils/sessions.js +0 -499
  119. package/dist/utils/sheet.js +0 -59
  120. package/dist/utils/stepGuide.js +0 -231
  121. package/dist/utils/steps.js +0 -88
  122. package/dist/utils/still.js +0 -38
  123. package/dist/utils/targetList.js +0 -64
  124. package/dist/utils/targets.js +0 -265
  125. package/dist/utils/timeline.js +0 -85
  126. package/dist/utils/toolSpec.js +0 -31
  127. package/dist/utils/toolsets.js +0 -134
  128. package/dist/utils/transcriptCut.js +0 -149
  129. package/dist/utils/validate.js +0 -23
  130. package/dist/utils/waitLoop.js +0 -50
  131. package/dist/utils/wgc.js +0 -84
  132. package/dist/utils/windows.js +0 -192
  133. package/dist/utils/zoom.js +0 -234
@@ -1,43 +0,0 @@
1
- import { fileURLToPath } from "node:url";
2
- import { RootsListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js";
3
- import { setClientRoots } from "./paths.js";
4
- import { errorMessage } from "./errors.js";
5
- export function rootDirs(roots) {
6
- const dirs = [];
7
- for (const { uri } of roots) {
8
- if (!uri.startsWith("file:"))
9
- continue;
10
- try {
11
- dirs.push(fileURLToPath(uri));
12
- }
13
- catch {
14
- }
15
- }
16
- return dirs;
17
- }
18
- export function trackClientRoots(server) {
19
- const low = server.server;
20
- const refresh = async (initial) => {
21
- if (!low.getClientCapabilities()?.roots) {
22
- setClientRoots(null);
23
- return;
24
- }
25
- if (initial)
26
- setClientRoots("pending");
27
- try {
28
- const { roots } = await low.listRoots();
29
- setClientRoots(rootDirs(roots));
30
- }
31
- catch (err) {
32
- if (initial)
33
- setClientRoots([]);
34
- process.stderr.write(`roots/list failed: ${errorMessage(err)}\n`);
35
- }
36
- };
37
- const previous = low.oninitialized;
38
- low.oninitialized = () => {
39
- previous?.();
40
- void refresh(true);
41
- };
42
- low.setNotificationHandler(RootsListChangedNotificationSchema, () => refresh(false));
43
- }
@@ -1,499 +0,0 @@
1
- import { spawnSync } from "node:child_process";
2
- import { readFileSync, writeFileSync, renameSync, existsSync, copyFileSync, openSync, closeSync, unlinkSync, statSync, linkSync, } from "node:fs";
3
- import { basename } from "node:path";
4
- import { errorMessage, ScreencastError } from "./errors.js";
5
- import { WGC_WINDOW_CLOSED_EXIT } from "./wgc.js";
6
- export const MAX_FINISHED_RECORDS = 100;
7
- export function isLive(status) {
8
- return status === "recording" || status === "paused";
9
- }
10
- export function classifyOrphan(record, alive) {
11
- if (record.status === "paused")
12
- return { status: "stopped", reaped: false };
13
- if (record.status !== "recording") {
14
- return { status: record.status, reaped: false };
15
- }
16
- return alive
17
- ? { status: "orphaned", reaped: true }
18
- : { status: "stopped", reaped: false };
19
- }
20
- export function isForeignLiveRecording(record, currentServerPid, ownerAlive) {
21
- return (isLive(record.status) &&
22
- record.serverPid !== undefined &&
23
- record.serverPid !== currentServerPid &&
24
- ownerAlive);
25
- }
26
- export function foreignStopRefusal(record, currentServerPid, ownerIsAlive) {
27
- if (record.backend === "wgc" || !isForeignLiveRecording(record, currentServerPid, ownerIsAlive))
28
- return null;
29
- return (`Recording ${record.id} belongs to another running screencast-mcp instance (pid ${record.serverPid}). ` +
30
- "Stop it from the client connected to that instance; closing that instance also finalizes it.");
31
- }
32
- export function ownerAlive(record, cache = new Map()) {
33
- const pid = record.serverPid;
34
- if (pid === undefined || pid === process.pid || !isAlive(pid))
35
- return false;
36
- if (!cache.has(pid))
37
- cache.set(pid, processInfo(pid));
38
- return isSameServer(record, cache.get(pid) ?? null);
39
- }
40
- export function serverIdentity() {
41
- return {
42
- serverPid: process.pid,
43
- serverStartedAt: new Date(Date.now() - process.uptime() * 1000).toISOString(),
44
- serverImage: basename(process.execPath).toLowerCase(),
45
- };
46
- }
47
- export const OWNER_START_SLACK_MS = 5_000;
48
- export function isSameServer(record, running) {
49
- if (!running)
50
- return true;
51
- if (record.serverImage && running.image.toLowerCase() !== record.serverImage.toLowerCase())
52
- return false;
53
- const ref = Date.parse(record.serverStartedAt ?? record.startedAt);
54
- return !(Number.isFinite(ref) && running.startMs > ref + OWNER_START_SLACK_MS);
55
- }
56
- export function parseProcessInfo(stdout) {
57
- const m = /^(.+)\|(\d+)\s*$/m.exec(stdout.trim());
58
- return m?.[1] && m[2] ? { image: m[1].trim(), startMs: Number(m[2]) } : null;
59
- }
60
- export function processInfo(pid) {
61
- if (process.platform !== "win32" || !Number.isInteger(pid) || pid <= 0)
62
- return null;
63
- const script = `$p = Get-CimInstance Win32_Process -Filter "ProcessId=${pid}"; ` +
64
- `if ($p) { "{0}|{1}" -f $p.Name, ([DateTimeOffset]$p.CreationDate).ToUnixTimeMilliseconds() }`;
65
- const res = spawnSync("powershell", ["-NoProfile", "-NonInteractive", "-Command", script], {
66
- encoding: "utf8",
67
- windowsHide: true,
68
- timeout: 10_000,
69
- killSignal: "SIGKILL",
70
- });
71
- return res.status === 0 && res.stdout ? parseProcessInfo(res.stdout) : null;
72
- }
73
- export function isAlive(pid) {
74
- if (pid === null || !Number.isInteger(pid) || pid <= 0)
75
- return false;
76
- try {
77
- process.kill(pid, 0);
78
- return true;
79
- }
80
- catch (err) {
81
- return err.code === "EPERM";
82
- }
83
- }
84
- export function expectedImage(record) {
85
- return record.processImage ?? (record.backend === "wgc" ? "node.exe" : "ffmpeg.exe");
86
- }
87
- export function tasklistHasImage(stdout, image) {
88
- const first = stdout.split(/\r?\n/)[0] ?? "";
89
- return first.toLowerCase().startsWith(`"${image.toLowerCase()}"`);
90
- }
91
- export function isRecorderProcess(pid, image) {
92
- if (pid === null || process.platform !== "win32")
93
- return false;
94
- const res = spawnSync("tasklist", ["/FI", `PID eq ${pid}`, "/FO", "CSV", "/NH"], { encoding: "utf8", windowsHide: true });
95
- if (res.status !== 0 || !res.stdout)
96
- return false;
97
- return tasklistHasImage(res.stdout, image);
98
- }
99
- export function isSameRecorder(record, running) {
100
- if (!running)
101
- return true;
102
- if (running.image.toLowerCase() !== expectedImage(record).toLowerCase())
103
- return false;
104
- const ref = record.pidSpawnedAt;
105
- return !(typeof ref === "number" && Number.isFinite(ref) && running.startMs > ref + OWNER_START_SLACK_MS);
106
- }
107
- export function isOwnRecorder(record) {
108
- if (record.pid === null || !isRecorderProcess(record.pid, expectedImage(record)))
109
- return false;
110
- return record.pidSpawnedAt === undefined || isSameRecorder(record, processInfo(record.pid));
111
- }
112
- export function classifyUnrequestedExit(opts) {
113
- const { code, backend, maxDurationSec, elapsedMs } = opts;
114
- if (backend === "wgc" && code === WGC_WINDOW_CLOSED_EXIT)
115
- return { status: "stopped", endReason: "window_closed" };
116
- if (code !== 0 && code !== null)
117
- return { status: "failed", endReason: "crashed" };
118
- const capReached = maxDurationSec > 0 && elapsedMs >= maxDurationSec * 1000 - 2000;
119
- return { status: "stopped", endReason: capReached ? "max_duration" : "stopped" };
120
- }
121
- export function killPid(pid) {
122
- if (process.platform === "win32") {
123
- spawnSync("taskkill", ["/PID", String(pid), "/T", "/F"], {
124
- stdio: "ignore",
125
- windowsHide: true,
126
- });
127
- }
128
- else {
129
- try {
130
- process.kill(pid, "SIGKILL");
131
- }
132
- catch {
133
- }
134
- }
135
- }
136
- export function pruneRecords(records) {
137
- const active = records.filter((r) => isLive(r.status));
138
- const finished = records
139
- .filter((r) => !isLive(r.status))
140
- .sort((a, b) => (a.startedAt < b.startedAt ? 1 : -1))
141
- .slice(0, MAX_FINISHED_RECORDS);
142
- return [...active, ...finished];
143
- }
144
- export const LOCK_STALE_MS = 30_000;
145
- export const LOCK_WAIT_MS = 15_000;
146
- export function isLockStale(holder, now, holderAlive) {
147
- if (!holder || typeof holder.at !== "number")
148
- return true;
149
- if (now - holder.at > LOCK_STALE_MS)
150
- return true;
151
- return typeof holder.pid === "number" && !holderAlive;
152
- }
153
- function sleepSync(ms) {
154
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
155
- }
156
- function renameWithRetry(from, to) {
157
- const deadline = Date.now() + 1_000;
158
- for (;;) {
159
- try {
160
- renameSync(from, to);
161
- return;
162
- }
163
- catch (err) {
164
- const code = err.code;
165
- if ((code !== "EPERM" && code !== "EBUSY" && code !== "EACCES") || Date.now() >= deadline)
166
- throw err;
167
- sleepSync(15);
168
- }
169
- }
170
- }
171
- export function breakStaleLock(lock, raw) {
172
- const aside = `${lock}.${process.pid}.${Date.now()}.stale`;
173
- try {
174
- renameSync(lock, aside);
175
- }
176
- catch {
177
- return false;
178
- }
179
- let removed = true;
180
- try {
181
- if (readFileSync(aside, "utf8") !== raw) {
182
- removed = false;
183
- linkSync(aside, lock);
184
- }
185
- }
186
- catch {
187
- }
188
- try {
189
- unlinkSync(aside);
190
- }
191
- catch {
192
- }
193
- return removed;
194
- }
195
- export function withRegistryLock(registry, fn, waitMs = LOCK_WAIT_MS) {
196
- const lock = `${registry}.lock`;
197
- const deadline = Date.now() + waitMs;
198
- let holderPid;
199
- let mine;
200
- for (let attempt = 0;; attempt++) {
201
- try {
202
- const fd = openSync(lock, "wx");
203
- mine = JSON.stringify({ pid: process.pid, at: Date.now(), nonce: Math.random().toString(36).slice(2) });
204
- writeFileSync(fd, mine);
205
- closeSync(fd);
206
- break;
207
- }
208
- catch (err) {
209
- const code = err.code;
210
- const busy = code === "EEXIST" || code === "EPERM" || code === "EACCES" || code === "EBUSY";
211
- if (!busy) {
212
- throw new ScreencastError(`Could not lock the session registry (${lock}): ${errorMessage(err)}`);
213
- }
214
- if (code === "EEXIST") {
215
- let seen;
216
- try {
217
- const raw = readFileSync(lock, "utf8");
218
- let holder;
219
- try {
220
- holder = JSON.parse(raw);
221
- }
222
- catch {
223
- holder = { at: statSync(lock).mtimeMs };
224
- }
225
- seen = { raw, holder };
226
- }
227
- catch {
228
- seen = null;
229
- }
230
- if (seen) {
231
- holderPid = seen.holder?.pid;
232
- if (isLockStale(seen.holder, Date.now(), isAlive(seen.holder?.pid ?? null)) &&
233
- breakStaleLock(lock, seen.raw)) {
234
- continue;
235
- }
236
- }
237
- }
238
- if (Date.now() >= deadline) {
239
- throw new ScreencastError(`The session registry is busy: could not take ${lock} within ${waitMs / 1000} s` +
240
- `${holderPid !== undefined ? ` (held by process ${holderPid})` : ""}. Nothing was written.`, "Another screencast-mcp server is writing to the same registry. Retry; if no other server is running, delete the .lock file.");
241
- }
242
- sleepSync(Math.min(50, 2 ** Math.min(attempt, 6)) * (0.5 + Math.random()));
243
- }
244
- }
245
- try {
246
- return fn();
247
- }
248
- finally {
249
- try {
250
- if (readFileSync(lock, "utf8") === mine)
251
- unlinkSync(lock);
252
- }
253
- catch {
254
- }
255
- }
256
- }
257
- export class SessionStore {
258
- path;
259
- lockWaitMs;
260
- records = new Map();
261
- pending = new Map();
262
- removed = new Set();
263
- seen = null;
264
- children = new Map();
265
- stopping = new Set();
266
- listeners = [];
267
- constructor(path, lockWaitMs = LOCK_WAIT_MS) {
268
- this.path = path;
269
- this.lockWaitMs = lockWaitMs;
270
- }
271
- onChange(cb) {
272
- this.listeners.push(cb);
273
- }
274
- readDisk() {
275
- if (!existsSync(this.path))
276
- return new Map();
277
- try {
278
- return this.parseDisk();
279
- }
280
- catch {
281
- try {
282
- copyFileSync(this.path, `${this.path}.bak`);
283
- process.stderr.write(`Session registry was unreadable; saved a copy to ${this.path}.bak and starting fresh.\n`);
284
- }
285
- catch {
286
- }
287
- return new Map();
288
- }
289
- }
290
- parseDisk() {
291
- const data = JSON.parse(readFileSync(this.path, "utf8"));
292
- return new Map(data.map((r) => [r.id, r]));
293
- }
294
- signature() {
295
- try {
296
- const s = statSync(this.path, { bigint: true });
297
- return `${s.ino}:${s.size}:${s.mtimeNs}`;
298
- }
299
- catch {
300
- return null;
301
- }
302
- }
303
- overlay(disk) {
304
- for (const [id, patch] of this.pending) {
305
- const base = disk.get(id) ?? this.records.get(id);
306
- if (base)
307
- disk.set(id, { ...base, ...patch });
308
- }
309
- for (const id of this.removed)
310
- disk.delete(id);
311
- return disk;
312
- }
313
- refresh() {
314
- const sig = this.signature();
315
- if (sig === this.seen)
316
- return;
317
- let disk;
318
- try {
319
- disk = sig === null ? new Map() : this.parseDisk();
320
- }
321
- catch {
322
- return;
323
- }
324
- this.seen = sig;
325
- this.records = new Map(pruneRecords([...this.overlay(disk).values()]).map((r) => [r.id, r]));
326
- }
327
- load() {
328
- const read = () => {
329
- const disk = this.readDisk();
330
- this.seen = this.signature();
331
- return disk;
332
- };
333
- let disk;
334
- try {
335
- disk = withRegistryLock(this.path, read, this.lockWaitMs);
336
- }
337
- catch (err) {
338
- process.stderr.write(`${errorMessage(err)} Reading the session registry without the lock.\n`);
339
- disk = read();
340
- }
341
- this.records = new Map(pruneRecords([...this.overlay(disk).values()]).map((r) => [r.id, r]));
342
- }
343
- persist() {
344
- withRegistryLock(this.path, () => {
345
- const pruned = pruneRecords([...this.overlay(this.readDisk()).values()]);
346
- const tmp = `${this.path}.${process.pid}.tmp`;
347
- writeFileSync(tmp, JSON.stringify(pruned, null, 2));
348
- renameWithRetry(tmp, this.path);
349
- this.seen = this.signature();
350
- this.records = new Map(pruned.map((r) => [r.id, r]));
351
- this.pending.clear();
352
- this.removed.clear();
353
- }, this.lockWaitMs);
354
- for (const cb of this.listeners) {
355
- try {
356
- cb();
357
- }
358
- catch {
359
- }
360
- }
361
- }
362
- create(record) {
363
- this.records.set(record.id, record);
364
- this.pending.set(record.id, record);
365
- try {
366
- this.persist();
367
- }
368
- catch (err) {
369
- this.records.delete(record.id);
370
- this.pending.delete(record.id);
371
- throw err;
372
- }
373
- }
374
- remove(ids) {
375
- const before = ids.flatMap((id) => {
376
- const r = this.records.get(id);
377
- return r ? [r] : [];
378
- });
379
- for (const id of ids) {
380
- this.removed.add(id);
381
- this.pending.delete(id);
382
- this.records.delete(id);
383
- }
384
- try {
385
- this.persist();
386
- }
387
- catch (err) {
388
- for (const id of ids)
389
- this.removed.delete(id);
390
- for (const r of before)
391
- this.records.set(r.id, r);
392
- throw err;
393
- }
394
- }
395
- get(id) {
396
- this.refresh();
397
- return this.records.get(id);
398
- }
399
- list() {
400
- this.refresh();
401
- return [...this.records.values()].sort((a, b) => a.startedAt < b.startedAt ? 1 : -1);
402
- }
403
- update(id, patch) {
404
- let cur = this.records.get(id);
405
- if (!cur) {
406
- this.refresh();
407
- cur = this.records.get(id);
408
- }
409
- if (!cur)
410
- return undefined;
411
- const next = { ...cur, ...patch };
412
- this.records.set(id, next);
413
- this.pending.set(id, { ...this.pending.get(id), ...patch });
414
- this.persist();
415
- return this.records.get(id) ?? next;
416
- }
417
- tryUpdate(id, patch) {
418
- try {
419
- return this.update(id, patch);
420
- }
421
- catch (err) {
422
- process.stderr.write(`Could not save session ${id}: ${errorMessage(err)}\n`);
423
- return undefined;
424
- }
425
- }
426
- attachChild(id, child) {
427
- this.children.set(id, child);
428
- }
429
- getChild(id) {
430
- return this.children.get(id);
431
- }
432
- detachChild(id, child) {
433
- if (child && this.children.get(id) !== child)
434
- return;
435
- this.children.delete(id);
436
- }
437
- activeIds() {
438
- return [
439
- ...[...this.children.keys()].filter((id) => this.records.get(id)?.status === "recording"),
440
- ...[...this.paused].filter((id) => this.records.get(id)?.status === "paused" && !this.children.has(id)),
441
- ];
442
- }
443
- paused = new Set();
444
- markPaused(id) {
445
- this.paused.add(id);
446
- }
447
- ownsPaused(id) {
448
- return this.paused.has(id);
449
- }
450
- clearPaused(id) {
451
- this.paused.delete(id);
452
- }
453
- markStopping(id) {
454
- this.stopping.add(id);
455
- }
456
- isStopping(id) {
457
- return this.stopping.has(id);
458
- }
459
- clearStopping(id) {
460
- this.stopping.delete(id);
461
- }
462
- reapOrphans() {
463
- this.refresh();
464
- const reaped = [];
465
- const owners = new Map();
466
- for (const record of this.records.values()) {
467
- if (!isLive(record.status))
468
- continue;
469
- if (isForeignLiveRecording(record, process.pid, ownerAlive(record, owners))) {
470
- continue;
471
- }
472
- const alive = isAlive(record.pid);
473
- const verdict = classifyOrphan(record, alive);
474
- if (verdict.reaped && record.pid !== null) {
475
- if (isOwnRecorder(record))
476
- killPid(record.pid);
477
- reaped.push(record.id);
478
- }
479
- const patch = {
480
- status: verdict.status,
481
- ...(record.stoppedAt ? {} : { stoppedAt: new Date().toISOString() }),
482
- ...(verdict.status === "orphaned"
483
- ? { error: "Reaped on server restart (recording was interrupted)." }
484
- : {}),
485
- ...(record.status === "paused"
486
- ? {
487
- endReason: "shutdown",
488
- error: `The server exited while this recording was paused; its parts were not joined (${record.segments?.parts.map((p) => p.path).join(", ") ?? record.outputPath}).`,
489
- }
490
- : {}),
491
- };
492
- this.records.set(record.id, { ...record, ...patch });
493
- this.pending.set(record.id, { ...this.pending.get(record.id), ...patch });
494
- }
495
- if (this.records.size > 0)
496
- this.persist();
497
- return reaped;
498
- }
499
- }
@@ -1,59 +0,0 @@
1
- import { ScreencastError } from "./errors.js";
2
- import { escapeFilterPath } from "./fonts.js";
3
- import { stillOutput } from "./paths.js";
4
- export const DEFAULT_SHEET_COUNT = 12;
5
- export const MAX_SHEET_COUNT = 48;
6
- export const DEFAULT_TILE_WIDTH = 320;
7
- export function evenTimes(durationSec, count) {
8
- if (!(durationSec > 0))
9
- throw new ScreencastError("Could not read the video's duration.");
10
- return Array.from({ length: count }, (_, i) => Math.round(((i + 0.5) * durationSec) / count * 1000) / 1000);
11
- }
12
- export function formatTimecode(sec) {
13
- const tenths = Math.round(Math.max(0, sec) * 10);
14
- const h = Math.floor(tenths / 36000);
15
- const m = Math.floor((tenths % 36000) / 600);
16
- const rest = (tenths % 600) / 10;
17
- if (h > 0)
18
- return `${h}:${String(m).padStart(2, "0")}:${String(Math.floor(rest)).padStart(2, "0")}`;
19
- return `${m}:${rest.toFixed(1).padStart(4, "0")}`;
20
- }
21
- export function sheetGrid(count, columns) {
22
- const auto = count <= 4 ? count : Math.ceil(Math.sqrt(count));
23
- const c = Math.max(1, Math.min(count, columns ?? auto));
24
- return { columns: c, rows: Math.ceil(count / c) };
25
- }
26
- export function buildTileArgs(input, timeSec, output, tileWidth, fontFile, labelFile) {
27
- if (!Number.isInteger(tileWidth) || tileWidth < 64) {
28
- throw new ScreencastError("tileWidth must be an integer of at least 64.");
29
- }
30
- const fontSize = Math.max(12, Math.round(tileWidth / 16));
31
- const label = `drawtext=fontfile=${escapeFilterPath(fontFile)}:textfile=${escapeFilterPath(labelFile)}:expansion=none:` +
32
- `fontcolor=white:fontsize=${fontSize}:x=6:y=h-text_h-6:box=1:boxcolor=black@0.6:boxborderw=4`;
33
- return [
34
- "-y", "-v", "error", "-ss", String(timeSec), "-i", input,
35
- "-frames:v", "1",
36
- "-vf", `scale=${tileWidth}:-2,${label}`,
37
- ...stillOutput(output),
38
- ];
39
- }
40
- export function buildSheetArgs(tilePattern, grid, output) {
41
- return [
42
- "-y", "-v", "error", "-framerate", "1", "-i", tilePattern,
43
- "-vf", `tile=${grid.columns}x${grid.rows}:padding=4:margin=4:color=black`,
44
- "-frames:v", "1",
45
- ...stillOutput(output),
46
- ];
47
- }
48
- export function buildPosterArgs(input, durationSec, output, width) {
49
- if (!(durationSec > 0))
50
- throw new ScreencastError("Could not read the video's duration.");
51
- const candidates = 30;
52
- const rate = Math.max(1e-4, candidates / durationSec);
53
- return [
54
- "-y", "-v", "error", "-i", input,
55
- "-vf", `fps=${rate.toFixed(4)},thumbnail=${candidates},scale='min(${width},iw)':-2`,
56
- "-frames:v", "1",
57
- ...stillOutput(output),
58
- ];
59
- }