@torrent-tv/proxy 2.89.17 → 2.89.19

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 (300) hide show
  1. package/README.md +14 -3
  2. package/package.json +10 -2
  3. package/server.js +0 -11
  4. package/utils/client-log-file.js +147 -42
  5. package/.claude/commands/opsx/apply.md +0 -155
  6. package/.claude/commands/opsx/archive.md +0 -160
  7. package/.claude/commands/opsx/explore.md +0 -174
  8. package/.claude/commands/opsx/propose.md +0 -109
  9. package/.claude/commands/opsx/sync.md +0 -143
  10. package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
  11. package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
  12. package/.claude/skills/openspec-explore/SKILL.md +0 -289
  13. package/.claude/skills/openspec-propose/SKILL.md +0 -113
  14. package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
  15. package/.dockerignore +0 -5
  16. package/AGENTS.md +0 -363
  17. package/CHANGELOG.md +0 -2377
  18. package/Dockerfile +0 -30
  19. package/biome.json +0 -412
  20. package/corpus.tmp.json +0 -1
  21. package/docs/browser-proxy-contract.md +0 -155
  22. package/docs/container-architecture.md +0 -273
  23. package/docs/download-architecture.md +0 -261
  24. package/docs/encode-architecture.md +0 -765
  25. package/docs/encode-run-state.md +0 -96
  26. package/docs/logs.md +0 -151
  27. package/docs/playback-start-forecast.md +0 -113
  28. package/docs/socks5-egress-research.md +0 -114
  29. package/docs/storage-architecture.md +0 -273
  30. package/knip.json +0 -14
  31. package/main2.cpuprofile +0 -1
  32. package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
  33. package/openspec/changes/adaptive-bitrate/design.md +0 -92
  34. package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
  35. package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
  36. package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
  37. package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
  38. package/openspec/changes/binary-distribution/proposal.md +0 -53
  39. package/openspec/changes/chunked-request-bodies/design.md +0 -81
  40. package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
  41. package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
  42. package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
  43. package/openspec/changes/cold-start/design.md +0 -98
  44. package/openspec/changes/cold-start/proposal.md +0 -62
  45. package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
  46. package/openspec/changes/cold-start/tasks.md +0 -48
  47. package/openspec/changes/disk-cap/.openspec.yaml +0 -2
  48. package/openspec/changes/disk-cap/proposal.md +0 -37
  49. package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
  50. package/openspec/changes/disk-cap/tasks.md +0 -19
  51. package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
  52. package/openspec/changes/proxy-observability/design.md +0 -38
  53. package/openspec/changes/proxy-observability/proposal.md +0 -49
  54. package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
  55. package/openspec/changes/proxy-observability/tasks.md +0 -21
  56. package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
  57. package/openspec/changes/seek-debounce/design.md +0 -118
  58. package/openspec/changes/seek-debounce/proposal.md +0 -59
  59. package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
  60. package/openspec/changes/seek-debounce/tasks.md +0 -33
  61. package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
  62. package/openspec/changes/subtitle-language/proposal.md +0 -50
  63. package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
  64. package/openspec/changes/subtitle-language/tasks.md +0 -26
  65. package/openspec/changes/track-selection/.openspec.yaml +0 -2
  66. package/openspec/changes/track-selection/design.md +0 -47
  67. package/openspec/changes/track-selection/proposal.md +0 -45
  68. package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
  69. package/openspec/changes/track-selection/tasks.md +0 -20
  70. package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
  71. package/openspec/changes/transcode-quality/proposal.md +0 -51
  72. package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
  73. package/openspec/changes/transcode-quality/tasks.md +0 -63
  74. package/openspec/config.yaml +0 -38
  75. package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
  76. package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
  77. package/research/double-spawn-2026-09-10.md +0 -171
  78. package/research/handover-2026-09-13.md +0 -209
  79. package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
  80. package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
  81. package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
  82. package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
  83. package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
  84. package/scripts/build-audio-samples.mjs +0 -31
  85. package/scripts/render-run-graph.js +0 -173
  86. package/test/asset-paths.test.js +0 -28
  87. package/test/audio-buffer-continuity.test.js +0 -77
  88. package/test/audio-calibration.test.js +0 -23
  89. package/test/audio-inventory.test.js +0 -212
  90. package/test/audio-track-bitrate.test.js +0 -40
  91. package/test/audio-warm-recorded.test.js +0 -63
  92. package/test/auto-quality-step.test.js +0 -762
  93. package/test/available-share.test.js +0 -76
  94. package/test/background-fill.test.js +0 -190
  95. package/test/client-log-file.test.js +0 -126
  96. package/test/client-logs-route.test.js +0 -34
  97. package/test/coalesce.test.js +0 -39
  98. package/test/completed-files.test.js +0 -115
  99. package/test/concurrent-cost.test.js +0 -148
  100. package/test/container-media-info.test.js +0 -228
  101. package/test/contention.test.js +0 -76
  102. package/test/core-dumps.test.js +0 -57
  103. package/test/coverage-follows-the-disk.test.js +0 -233
  104. package/test/coverage-map.test.js +0 -195
  105. package/test/cue-push-carries-what-the-walk-found.test.js +0 -58
  106. package/test/cut-times-timeline.test.js +0 -65
  107. package/test/cuts-follow-published-grid.test.js +0 -109
  108. package/test/data-channel-frame.test.js +0 -63
  109. package/test/data-channel-viewer-lifecycle.test.js +0 -193
  110. package/test/dead-torrent-handle.test.js +0 -52
  111. package/test/declared-rates.test.js +0 -116
  112. package/test/declared-tracks.test.js +0 -43
  113. package/test/decode-cost-fit.test.js +0 -202
  114. package/test/decode-cost.test.js +0 -475
  115. package/test/delivery-probe-field.test.js +0 -173
  116. package/test/delivery-probe.test.js +0 -382
  117. package/test/demand-register.test.js +0 -206
  118. package/test/dht-bootstrap.test.js +0 -72
  119. package/test/drain-threat.test.js +0 -65
  120. package/test/duplicate-add.test.js +0 -48
  121. package/test/encode-admission.test.js +0 -170
  122. package/test/encode-cost.test.js +0 -275
  123. package/test/encode-exit.test.js +0 -111
  124. package/test/encode-orchestrator.test.js +0 -426
  125. package/test/encode-plan-viewers.test.js +0 -725
  126. package/test/encode-plan.test.js +0 -545
  127. package/test/encode-run-state.test.js +0 -314
  128. package/test/encode-run.test.js +0 -248
  129. package/test/encode-slope.test.js +0 -46
  130. package/test/encoded-output.test.js +0 -39
  131. package/test/encoder-kinds.test.js +0 -122
  132. package/test/encoder-readings.test.js +0 -68
  133. package/test/episode-naming.test.js +0 -131
  134. package/test/every-claimant-is-told-its-share.test.js +0 -152
  135. package/test/failed-encoder-still-serves-what-exists.test.js +0 -354
  136. package/test/failed-start-breaker.test.js +0 -202
  137. package/test/fastest-wires.test.js +0 -143
  138. package/test/ffmpeg-stream-counts.test.js +0 -101
  139. package/test/file-edges.test.js +0 -191
  140. package/test/files-in-use.test.js +0 -34
  141. package/test/fixtures/audio-frame-boundary.json +0 -1
  142. package/test/fixtures/refused-audio-20261002.json +0 -10
  143. package/test/fmp4-presentation-clock.test.js +0 -148
  144. package/test/fmp4-self-contained.test.js +0 -80
  145. package/test/fmp4-timestamps.test.js +0 -140
  146. package/test/fmp4-track-completeness.test.js +0 -41
  147. package/test/format-keyed-outputs.test.js +0 -78
  148. package/test/health-metrics.test.js +0 -36
  149. package/test/held-read-ownership.test.js +0 -77
  150. package/test/held-request-width.test.js +0 -157
  151. package/test/helpers/encode-run.js +0 -248
  152. package/test/helpers/held-file.js +0 -77
  153. package/test/helpers/manager.js +0 -62
  154. package/test/helpers/matroska-file.js +0 -296
  155. package/test/helpers/output-spec.js +0 -63
  156. package/test/host-load.test.js +0 -68
  157. package/test/index-accuracy-is-about-the-file.test.js +0 -128
  158. package/test/init-compat.test.js +0 -219
  159. package/test/input-lost-quiets-the-plan.test.js +0 -261
  160. package/test/input-unavailable.test.js +0 -48
  161. package/test/installation-id.test.js +0 -39
  162. package/test/keeping-period.test.js +0 -83
  163. package/test/keyframe-index-accuracy.test.js +0 -188
  164. package/test/keyframe-table-budget.test.js +0 -123
  165. package/test/keyframes-belong-to-the-file.test.js +0 -249
  166. package/test/learned-median.test.js +0 -37
  167. package/test/letting-go-asks-who-is-watching.test.js +0 -191
  168. package/test/limit-row-by-area.test.js +0 -60
  169. package/test/link-budget.test.js +0 -111
  170. package/test/link-probe.test.js +0 -56
  171. package/test/local-encoding-data.test.js +0 -273
  172. package/test/logger-repeats.test.js +0 -134
  173. package/test/look-ahead-coverage.test.js +0 -56
  174. package/test/manager-surface.test.js +0 -291
  175. package/test/matroska-blocks.test.js +0 -0
  176. package/test/matroska-cluster-discovery.test.js +0 -323
  177. package/test/matroska-cues-track.test.js +0 -192
  178. package/test/media-time.test.js +0 -62
  179. package/test/memory-budget.test.js +0 -390
  180. package/test/move-cost.test.js +0 -216
  181. package/test/mp4-composition-times.test.js +0 -0
  182. package/test/mp4-subtitles.test.js +0 -173
  183. package/test/one-authority.test.js +0 -285
  184. package/test/one-budget.test.js +0 -149
  185. package/test/one-output-one-session.test.js +0 -273
  186. package/test/one-resource-divided.test.js +0 -185
  187. package/test/one-serving-output-per-height.test.js +0 -458
  188. package/test/orchestrator-wired.test.js +0 -207
  189. package/test/output-catalog.test.js +0 -39
  190. package/test/output-shape.test.js +0 -21
  191. package/test/output-spec.test.js +0 -251
  192. package/test/output-speed.test.js +0 -92
  193. package/test/outputs-being-prepared.test.js +0 -40
  194. package/test/packet-witness-ring.test.js +0 -236
  195. package/test/packet-witness.test.js +0 -148
  196. package/test/piece-completeness.test.js +0 -78
  197. package/test/piece-disk-store.test.js +0 -401
  198. package/test/piece-from-whole-file.test.js +0 -129
  199. package/test/piece-lru.test.js +0 -319
  200. package/test/piece-reader.test.js +0 -162
  201. package/test/piece-selection-offset.test.js +0 -85
  202. package/test/piece-store-eviction.test.js +0 -595
  203. package/test/piece-store-never-refuses.test.js +0 -153
  204. package/test/piece-store-reservations.test.js +0 -403
  205. package/test/piece-store-slow-disk.test.js +0 -159
  206. package/test/piece-tail.test.js +0 -97
  207. package/test/plan-host-timings.test.js +0 -68
  208. package/test/plan-is-steady.test.js +0 -225
  209. package/test/playback-readiness.test.js +0 -518
  210. package/test/playback-start-regressions.test.js +0 -101
  211. package/test/priority-map-download.test.js +0 -174
  212. package/test/priority-map-emptied.test.js +0 -204
  213. package/test/priority-map-per-output.test.js +0 -215
  214. package/test/priority-map.test.js +0 -163
  215. package/test/probe-wedge-certainty.test.js +0 -60
  216. package/test/produced-copy-choice.test.js +0 -213
  217. package/test/published-timeline.test.js +0 -83
  218. package/test/quality-offer.test.js +0 -160
  219. package/test/quality-variants.test.js +0 -1274
  220. package/test/rate-control-in-the-output.test.js +0 -181
  221. package/test/read-survives-withdrawal.test.js +0 -164
  222. package/test/read-window.test.js +0 -365
  223. package/test/reads-not-yet-arrived.test.js +0 -218
  224. package/test/resume-warm.test.js +0 -39
  225. package/test/run-graph-drift.test.js +0 -37
  226. package/test/run-inputs.test.js +0 -80
  227. package/test/run-intervals.test.js +0 -100
  228. package/test/run-position-follows-published-grid.test.js +0 -89
  229. package/test/run-progress.test.js +0 -64
  230. package/test/same-height-switch.test.js +0 -663
  231. package/test/seek-frees-the-viewers-requests.test.js +0 -217
  232. package/test/seek-landing.test.js +0 -109
  233. package/test/seek-target-not-superseded.test.js +0 -195
  234. package/test/segment-closed-on-both-branches.test.js +0 -114
  235. package/test/segment-cut-times.test.js +0 -63
  236. package/test/segment-demand.test.js +0 -80
  237. package/test/segment-hold-supersede.test.js +0 -91
  238. package/test/segment-judged-by-its-own-header.test.js +0 -222
  239. package/test/segment-serve-wiring.test.js +0 -481
  240. package/test/segment-store-eviction.test.js +0 -247
  241. package/test/segment-store.test.js +0 -352
  242. package/test/segment-true-start.test.js +0 -86
  243. package/test/segments-are-shared.test.js +0 -176
  244. package/test/send-chunk-bytes.test.js +0 -86
  245. package/test/serving-existing-output.test.js +0 -111
  246. package/test/serving-output.test.js +0 -102
  247. package/test/shared-piece-store.test.js +0 -310
  248. package/test/sidecar-naming.test.js +0 -142
  249. package/test/soundtrack-rate-bound.test.js +0 -289
  250. package/test/source-file.test.js +0 -133
  251. package/test/source-files-route.test.js +0 -113
  252. package/test/source-registry.test.js +0 -18
  253. package/test/split-a-stretch.test.js +0 -139
  254. package/test/stale-request-after-seek.test.js +0 -158
  255. package/test/startup-readings.test.js +0 -124
  256. package/test/stream-route.test.js +0 -237
  257. package/test/subtitle-cue-framing.test.js +0 -200
  258. package/test/subtitle-cue-source.test.js +0 -102
  259. package/test/subtitle-cue-walk.test.js +0 -385
  260. package/test/subtitle-cursor.test.js +0 -63
  261. package/test/subtitle-defaults.test.js +0 -118
  262. package/test/subtitle-language.test.js +0 -252
  263. package/test/subtitle-metadata.test.js +0 -15
  264. package/test/subtitle-plan-waits.test.js +0 -125
  265. package/test/subtitle-track-numbering.test.js +0 -391
  266. package/test/supply-margin.test.js +0 -190
  267. package/test/swarm-follows-readers.test.js +0 -174
  268. package/test/swarm-reach.test.js +0 -130
  269. package/test/swarm-selection.test.js +0 -220
  270. package/test/tail-duplication.test.js +0 -167
  271. package/test/the-channel-has-both-ends.test.js +0 -91
  272. package/test/the-torrent-thread-serves-bytes.test.js +0 -107
  273. package/test/thread-pool.test.js +0 -53
  274. package/test/timeline.test.js +0 -84
  275. package/test/torrent-contents.test.js +0 -235
  276. package/test/torrent-cost.test.js +0 -71
  277. package/test/torrent-files.test.js +0 -221
  278. package/test/torrent-naming.test.js +0 -255
  279. package/test/tracks-begin-together.test.js +0 -209
  280. package/test/tunnel-renewal.test.js +0 -167
  281. package/test/two-viewers-one-picture.test.js +0 -508
  282. package/test/upload-hurry.test.js +0 -186
  283. package/test/usrsctp-state.test.js +0 -131
  284. package/test/video-facts.test.js +0 -102
  285. package/test/viewer-assignments.test.js +0 -143
  286. package/test/viewer-outputs.test.js +0 -285
  287. package/test/viewer-presence.test.js +0 -116
  288. package/test/viewer-requests-admission.test.js +0 -92
  289. package/test/viewer-starts-on-map.test.js +0 -27
  290. package/test/viewer-states.test.js +0 -192
  291. package/test/viewer-subtitle-subscription.test.js +0 -96
  292. package/test/viewer.test.js +0 -139
  293. package/test/viewing-generations.test.js +0 -390
  294. package/test/visible-rung.test.js +0 -37
  295. package/test/wait-ledger.test.js +0 -100
  296. package/test/webrtc-shim.test.js +0 -149
  297. package/test/wedge-certainty.test.js +0 -131
  298. package/test/whole-file-held-read.test.js +0 -30
  299. package/test/withdraw-piece-claim.test.js +0 -212
  300. package/test/worker-channel.test.js +0 -158
@@ -1,116 +0,0 @@
1
- /**
2
- * @file Presence is a fact of the connection, and it is not the same fact as
3
- * position.
4
- *
5
- * Both halves failed together on 2026-09-05. A viewer who had arrived and asked
6
- * for nothing counted as absent, so a soundtrack's encoder was stopped 1.25 s
7
- * after starting with nothing produced — and its `init.mp4` was therefore never
8
- * made, which is the one file the viewer needed in order to ask for the segment
9
- * that would have marked them present. And nothing anywhere let a viewer go
10
- * when their connection closed: the only exits were the browser's own release,
11
- * which a killed tab never sends, and a silence that a paused viewer produces
12
- * just as well as a departed one.
13
- */
14
-
15
- import test from "node:test";
16
- import assert from "node:assert/strict";
17
- import { mkdtemp, rm } from "node:fs/promises";
18
- import os from "node:os";
19
- import path from "node:path";
20
- import { wireOutputs } from "../services/server/wire-outputs.js";
21
- import { SourceFile } from "../services/media/SourceFile.js";
22
- import { Viewers } from "../services/viewer/Viewers.js";
23
- import { outputSpec } from "./helpers/output-spec.js";
24
-
25
- const PICTURE = "aaaaaaaa00004000";
26
- const SOUND = "aaaaaaaa00004001";
27
-
28
- /**
29
- * @param {string} id
30
- * @param {string} dirPath
31
- * @returns {object}
32
- */
33
- function outputOn(id, dirPath) {
34
- return {
35
- id,
36
- spec: outputSpec(),
37
- dirPath,
38
- state: "live",
39
- file: new SourceFile({ sourceKey: "source-1", fileIndex: 0, name: "video.mkv" }),
40
- get inputFile() { return this.file; },
41
- get audioFile() { return this.file; },
42
- claims: new Set(),
43
- lastAccessedAt: Date.now()
44
- };
45
- }
46
-
47
- test("asking for a viewer of an output is that viewer watching it", () => {
48
- let changes = 0;
49
- const viewers = new Viewers({ onChange: () => { changes += 1; } });
50
- const output = { id: "out-1" };
51
-
52
- const first = viewers.of(output, "someone");
53
- assert.equal(changes, 1, "a new relation is a change");
54
- assert.equal(first.outputs.has("out-1"), true);
55
-
56
- viewers.of(output, "someone");
57
- assert.equal(changes, 1, "asking again about the same output changes nothing");
58
-
59
- const second = { id: "out-2" };
60
- viewers.of(second, "someone");
61
- assert.equal(changes, 2, "a second output is a change");
62
- assert.equal(viewers.get("someone")?.outputs.size, 2);
63
- });
64
-
65
- test("a connection closing takes the person off every output at once", () => {
66
- const viewers = new Viewers();
67
- const picture = { id: "picture" };
68
- const sound = { id: "sound" };
69
- viewers.of(picture, "watcher");
70
- viewers.of(sound, "watcher");
71
- viewers.of(picture, "other");
72
-
73
- const left = viewers.hasGone("watcher");
74
-
75
- assert.deepEqual(left.sort(), ["picture", "sound"], "both, not the one the browser holds an id for");
76
- assert.equal(viewers.forOutput(picture).has("watcher"), false);
77
- assert.equal(viewers.forOutput(sound).has("watcher"), false);
78
- assert.equal(viewers.forOutput(picture).has("other"), true, "and nobody else goes with them");
79
- assert.equal(viewers.get("watcher"), null, "the registry does not keep what it has let go");
80
- });
81
-
82
- test("a viewer whose connection closed is let go of every output they were watching", async (t) => {
83
- const dirPath = await mkdtemp(path.join(os.tmpdir(), "presence-"));
84
- t.after(async () => {
85
- await rm(dirPath, { recursive: true, force: true });
86
- });
87
- const manager = wireOutputs({
88
- enabled: true,
89
- ffmpegBin: "ffmpeg",
90
- localBindHost: "127.0.0.1",
91
- localPort: 9090
92
- });
93
-
94
- const picture = outputOn(PICTURE, dirPath);
95
- const sound = outputOn(SOUND, dirPath);
96
- manager.outputs.set(PICTURE, picture);
97
- manager.outputs.set(SOUND, sound);
98
- manager.viewers.of(picture, "watcher");
99
- manager.viewers.of(sound, "watcher");
100
-
101
- const released = await manager.lifecycle.viewerHasGone("watcher", "the connection closed");
102
-
103
- assert.equal(released, 2, "the picture and the soundtrack, from one statement");
104
- assert.equal(manager.viewers.get("watcher"), null);
105
- });
106
-
107
- test("a viewer nobody knows costs nothing to let go of", async () => {
108
- const manager = wireOutputs({
109
- enabled: true,
110
- ffmpegBin: "ffmpeg",
111
- localBindHost: "127.0.0.1",
112
- localPort: 9090
113
- });
114
- assert.equal(await manager.lifecycle.viewerHasGone("never-seen"), 0);
115
- assert.equal(await manager.lifecycle.viewerHasGone(""), 0);
116
- });
@@ -1,92 +0,0 @@
1
- /**
2
- * @file Opening an output admits and places its viewer in one synchronous call.
3
- */
4
-
5
- import test from "node:test";
6
- import assert from "node:assert/strict";
7
- import { EncodeAdmission } from "../services/encode/EncodeAdmission.js";
8
- import { ViewerRequests } from "../services/server/ViewerRequests.js";
9
-
10
- test("the first opening holds capacity before a concurrent opening is admitted", async () => {
11
- const records = new Map();
12
- const outputCosts = new Map([
13
- ["source-a:0", 0.6],
14
- ["source-b:0", 0.6]
15
- ]);
16
- const viewers = {
17
- get: () => null,
18
- forOutput(output) {
19
- return new Set(records.get(output.outputKey)?.keys() ?? []);
20
- },
21
- of(output, consumerId) {
22
- let viewersOnOutput = records.get(output.outputKey);
23
- if (!viewersOnOutput) {
24
- viewersOnOutput = new Map();
25
- records.set(output.outputKey, viewersOnOutput);
26
- }
27
- let viewer = viewersOnOutput.get(consumerId);
28
- if (!viewer) {
29
- viewer = {
30
- position: null,
31
- linkReading: () => null,
32
- noteVisiblePicture: () => {},
33
- // What the request says about them, kept by the real viewer; what
34
- // this check is about is the place on the machine, not the report.
35
- report: () => {}
36
- };
37
- viewersOnOutput.set(consumerId, viewer);
38
- }
39
- return viewer;
40
- },
41
- watchedAddresses() {
42
- return new Set(
43
- [...records]
44
- .filter(([, members]) => [...members.values()].some((viewer) => viewer.position !== null))
45
- .map(([address]) => address)
46
- );
47
- }
48
- };
49
- const admission = new EncodeAdmission({
50
- liveRunsByAddress: () => new Map(),
51
- preparedAddresses: () => new Set(),
52
- watchedAddresses: () => viewers.watchedAddresses(),
53
- loadOf: (address) => {
54
- const costSec = outputCosts.get(address);
55
- return costSec === undefined ? null : { costSec, fileKey: address, fileCostSec: 0 };
56
- },
57
- availability: () => ({ share: 1, known: true }),
58
- finished: () => false
59
- });
60
- const opening = {
61
- async open({ sourceKey, fileIndex, claim }) {
62
- const output = { id: `${sourceKey}:${fileIndex}`, outputKey: `${sourceKey}:${fileIndex}` };
63
- const answer = claim(output);
64
- if (!answer.admitted) {
65
- const error = new Error(answer.reason);
66
- error.code = "OUTPUT_NO_CAPACITY";
67
- throw error;
68
- }
69
- return { output, existed: false, audio: null, verdict: null };
70
- }
71
- };
72
- const requests = new ViewerRequests({
73
- opening,
74
- viewers,
75
- admitsWatching: (output) => admission.admitsWatching(output.outputKey),
76
- outputTimes: { segmentIndexForTime: (_output, seconds) => Math.floor(seconds / 4) },
77
- planEncodersSoon: () => {},
78
- outputs: { touch: () => {} },
79
- noteServingVerdict: () => {},
80
- waitUntilReady: async () => {}
81
- });
82
-
83
- const first = requests.createOrGetSession({ sourceKey: "source-a", fileIndex: 0, consumerId: "viewer-a" });
84
- const second = requests.createOrGetSession({ sourceKey: "source-b", fileIndex: 0, consumerId: "viewer-b" });
85
- const [firstResult, secondResult] = await Promise.allSettled([first, second]);
86
-
87
- assert.equal(firstResult.status, "fulfilled");
88
- assert.equal(secondResult.status, "rejected");
89
- assert.match(secondResult.reason.message, /would make 0\.83x/);
90
- assert.equal(viewers.forOutput({ outputKey: "source-a:0" }).has("viewer-a"), true);
91
- assert.equal(viewers.forOutput({ outputKey: "source-b:0" }).has("viewer-b"), false);
92
- });
@@ -1,27 +0,0 @@
1
- /**
2
- * @file Where viewers stand, read off a merged priority map — the times the
3
- * subtitle walk reads first.
4
- */
5
-
6
- import test from "node:test";
7
- import assert from "node:assert/strict";
8
-
9
- import { emptyMap, mapForViewer, mergeMaps, viewerStartsOn } from "../services/viewer/PriorityMap.js";
10
-
11
- test("each viewer's position is a step up in the merged map", () => {
12
- const map = mergeMaps([
13
- mapForViewer({ atSeconds: 30, durationSeconds: 300, allowanceSeconds: 5 }),
14
- mapForViewer({ atSeconds: 200, durationSeconds: 300, allowanceSeconds: 5 })
15
- ]);
16
- assert.deepEqual(viewerStartsOn(map), [30, 200]);
17
- });
18
-
19
- test("a viewer at the very start, a stopped viewer, and nobody", () => {
20
- assert.deepEqual(viewerStartsOn(mapForViewer({ atSeconds: 0, durationSeconds: 60, allowanceSeconds: 5 })), [0]);
21
- assert.deepEqual(
22
- viewerStartsOn(mapForViewer({ atSeconds: 12, durationSeconds: 60, allowanceSeconds: 5, playing: false })),
23
- [12]
24
- );
25
- assert.deepEqual(viewerStartsOn(emptyMap(60)), []);
26
- assert.deepEqual(viewerStartsOn(null), []);
27
- });
@@ -1,192 +0,0 @@
1
- /**
2
- * @file The three states a viewer can be in, and what each is worth.
3
- *
4
- * Written against the failure of 2026-09-14: a page whose tab was hidden for
5
- * 145 seconds, which had measured nothing and therefore said nothing, was
6
- * carried 146 seconds into a film it had not begun — and the soundtrack's
7
- * encoder was placed there while the browser asked for segment #0 and was
8
- * refused for sixty seconds.
9
- */
10
-
11
- import assert from "node:assert/strict";
12
- import test from "node:test";
13
-
14
- import { Viewer } from "../services/viewer/Viewer.js";
15
- import { Viewers } from "../services/viewer/Viewers.js";
16
-
17
- const AT = 1_000_000;
18
-
19
- test("a viewer who has stated nothing does not move, however long they are silent", () => {
20
- const viewer = new Viewer("one", AT);
21
- viewer.moveTo(0, AT);
22
-
23
- // 146 seconds of silence — the field figure exactly.
24
- assert.equal(viewer.positionSeconds(AT + 146_000), 0);
25
- });
26
-
27
- test("a viewer who has stated nothing is waiting, and their work is due now", () => {
28
- const viewer = new Viewer("one", AT);
29
- viewer.moveTo(0, AT);
30
-
31
- assert.equal(viewer.playing, false);
32
- assert.equal(viewer.waiting, true);
33
- assert.equal(viewer.wantsFilmNow(), true);
34
- });
35
-
36
- test("a playing viewer moves with the film, and no further than what they hold", () => {
37
- const viewer = new Viewer("one", AT);
38
- viewer.report({ bufferedAheadSec: 30, positionSeconds: 100, playing: true, waiting: false }, AT);
39
-
40
- // Ten seconds of silence, ten seconds of film.
41
- assert.equal(viewer.positionSeconds(AT + 10_000), 110);
42
- // Two minutes of silence buys only the thirty seconds they said they held.
43
- assert.equal(viewer.positionSeconds(AT + 120_000), 130);
44
- });
45
-
46
- test("a viewer holding nothing cannot move at all, even reported as playing", () => {
47
- const viewer = new Viewer("one", AT);
48
- viewer.report({ bufferedAheadSec: 0, positionSeconds: 0, playing: true, waiting: false }, AT);
49
-
50
- assert.equal(viewer.positionSeconds(AT + 146_000), 0);
51
- });
52
-
53
- test("a viewer who stopped the picture is not waiting, and nothing of theirs falls due", () => {
54
- const viewer = new Viewer("one", AT);
55
- viewer.report({ bufferedAheadSec: 42, positionSeconds: 100, playing: false, waiting: false }, AT);
56
-
57
- assert.equal(viewer.wantsFilmNow(), false);
58
- assert.equal(viewer.positionSeconds(AT + 60_000), 100);
59
- });
60
-
61
- test("a viewer starved of material is waiting, and is as urgent as one playing", () => {
62
- const playing = new Viewer("playing", AT);
63
- playing.report({ bufferedAheadSec: 30, positionSeconds: 100, playing: true, waiting: false }, AT);
64
- const starved = new Viewer("starved", AT);
65
- starved.report({ bufferedAheadSec: 0, positionSeconds: 100, playing: false, waiting: true }, AT);
66
-
67
- // Both want film now, and that is the whole point: the starved one used to
68
- // count as somebody who had chosen to stop.
69
- assert.equal(starved.wantsFilmNow(), true);
70
- assert.equal(playing.wantsFilmNow(), true);
71
- // And the starved one cannot be carried forward from where they stand,
72
- // because they hold nothing to play.
73
- assert.equal(starved.positionSeconds(AT + 60_000), 100);
74
- });
75
-
76
- test("a report without a link measurement still states everything about the viewer", () => {
77
- const viewer = new Viewer("one", AT);
78
- viewer.report({ bufferedAheadSec: 0, positionSeconds: 12, playing: false, waiting: true }, AT);
79
-
80
- assert.equal(viewer.positionSeconds(AT), 12);
81
- assert.equal(viewer.waiting, true);
82
- // The report is kept from the first one the page sends (proxy 2.86.0), and
83
- // since nothing was measured, nothing is claimed about the link.
84
- assert.equal(viewer.netReport.linkMbps, null);
85
- assert.equal(viewer.netReport.linkSampleMbps, null);
86
- assert.equal(viewer.netReport.positionSeconds, 12);
87
- });
88
-
89
- test("a page one release behind, which cannot say `waiting`, is read from what it does say", () => {
90
- const starved = new Viewer("starved", AT);
91
- starved.report({ linkMbps: 5, bufferedAheadSec: 0, positionSeconds: 0, playing: false }, AT);
92
- assert.equal(starved.waiting, true, "stopped and holding nothing is starved");
93
-
94
- const paused = new Viewer("paused", AT);
95
- paused.report({ linkMbps: 5, bufferedAheadSec: 40, positionSeconds: 0, playing: false }, AT);
96
- assert.equal(paused.waiting, false, "stopped while holding film is a viewer's own pause");
97
- });
98
-
99
- test("a seek does not carry the cushion of the place it left", () => {
100
- const viewer = new Viewer("one", AT);
101
- viewer.report({ bufferedAheadSec: 120, positionSeconds: 100, playing: true, waiting: false }, AT);
102
-
103
- viewer.moveTo(2000, AT + 1000);
104
- // Nothing is held at the new place until they say so, so the position stands.
105
- assert.equal(viewer.positionSeconds(AT + 61_000), 2000);
106
- });
107
-
108
- test("a page that is not on screen wants nothing now, whatever else it says", () => {
109
- const viewer = new Viewer("one", AT);
110
- viewer.report(
111
- { bufferedAheadSec: 0, positionSeconds: 100, playing: false, waiting: true, onScreen: false },
112
- AT
113
- );
114
-
115
- assert.equal(viewer.wantsFilmNow(), false);
116
- });
117
-
118
- test("the intake hands the statement to the viewer on the output they are watching", async () => {
119
- const { recordViewerReport } = await import("../services/viewer/report-intake.js");
120
- const picture = { id: "picture" };
121
- const rung = { id: "rung" };
122
- const sessions = new Map([
123
- ["picture", picture],
124
- ["rung", rung]
125
- ]);
126
- const viewers = new Viewers();
127
- viewers.of(picture, "one", AT).activeVariantId = "rung";
128
-
129
- // The page always addresses the PICTURE — it is never told which rung it is
130
- // on — and the statement belongs to the rung actually on screen.
131
- const taken = recordViewerReport({
132
- outputs: sessions,
133
- viewers,
134
- sessionId: "picture",
135
- report: { linkMbps: 8, bufferedAheadSec: 10, positionSeconds: 5, playing: true, consumerId: "one" },
136
- now: AT
137
- });
138
-
139
- assert.equal(taken, true);
140
- assert.equal(viewers.forOutput(rung).get("one").positionSeconds(AT), 5);
141
- assert.equal(viewers.forOutput(picture).has("one"), true);
142
- });
143
-
144
- test("a link reading does not expire — presence is what decides whose it is", () => {
145
- const viewer = new Viewer("one", AT);
146
- viewer.report({ linkMbps: 8, bufferedAheadSec: 10, positionSeconds: 5, playing: true }, AT);
147
-
148
- // A link does not stop being what it was measured to be because nobody
149
- // measured it for a while. The page says as much by keeping its own last
150
- // figure rather than reporting nothing.
151
- assert.equal(viewer.linkReading()?.linkMbps, 8);
152
- assert.equal(viewer.linkReading()?.linkMbps, 8, "and an hour later it is still the last thing known");
153
-
154
- // What ends it is the person leaving, which is a different fact with a
155
- // different owner.
156
- assert.equal(viewer.isPresent(), true);
157
- });
158
-
159
- test("each viewer's link is read for that viewer alone, never as a worst over several", async () => {
160
- // Roadmap item 97, step 11: a thin link decides for the person on it. The
161
- // worst reading across everybody watching used to decide for all of them.
162
- const { linkReportOf, presentOn } = await import("../services/viewer/choices.js");
163
- const output = { id: "out" };
164
- const viewers = new Viewers();
165
- const slow = viewers.of(output, "slow", AT);
166
- const fast = viewers.of(output, "fast", AT);
167
- slow.report({ linkMbps: 2, bufferedAheadSec: 3, playing: true }, AT);
168
- fast.report({ linkMbps: 40, bufferedAheadSec: 90, playing: true }, AT);
169
-
170
- assert.equal(linkReportOf(viewers, output, "slow")?.linkMbps, 2);
171
- assert.equal(linkReportOf(viewers, output, "fast")?.linkMbps, 40, "the slow link says nothing about this one");
172
- assert.equal(linkReportOf(viewers, output, "nobody"), null);
173
-
174
- // The slow one leaves: they are no longer among the viewers asked about.
175
- slow.gone = true;
176
- assert.deepEqual(presentOn(viewers, output), ["fast"]);
177
- });
178
-
179
- test("a report into an output absent from the live registry is refused rather than invented", async () => {
180
- const { recordViewerReport } = await import("../services/viewer/report-intake.js");
181
- const sessions = new Map();
182
- const viewers = { of() { throw new Error("must not be asked"); } };
183
-
184
- assert.equal(
185
- recordViewerReport({ outputs: sessions, viewers, sessionId: "dead", report: { bufferedAheadSec: 0 }, now: AT }),
186
- false
187
- );
188
- assert.equal(
189
- recordViewerReport({ outputs: sessions, viewers, sessionId: "never", report: { bufferedAheadSec: 0 }, now: AT }),
190
- false
191
- );
192
- });
@@ -1,96 +0,0 @@
1
- /**
2
- * @file Who wants subtitle cues, and why the answer is a person and not a channel.
3
- *
4
- * The subscription used to be a `Set<DataChannel>` inside the transport, keyed
5
- * by `sourceKey:fileIndex`. Two things followed from that, and both are field
6
- * facts rather than worries:
7
- *
8
- * 1. a seamless reconnect lost subtitles for the rest of the session, because
9
- * the new channel is a different object and nothing re-subscribed it;
10
- * 2. the transport had to sniff `/api/subtitles` out of the request path and
11
- * derive a torrent key to build that key at all — application routing and
12
- * torrent identity, inside the layer that is only supposed to carry bytes.
13
- *
14
- * Held against the viewer instead, both go away by construction: whatever
15
- * channel the person is reachable on next, they are still subscribed, and the
16
- * transport never learns what a subtitle is.
17
- */
18
-
19
- import test from "node:test";
20
- import assert from "node:assert/strict";
21
-
22
- import { Viewers } from "../services/viewer/Viewers.js";
23
-
24
- /** An output is only ever held by id here, so the thinnest possible stand-in. */
25
- const anOutput = (id) => ({ id, viewers: new Set() });
26
-
27
- test("a viewer who switched subtitles on is listed for that file", () => {
28
- const viewers = new Viewers();
29
- viewers.of(anOutput("picture"), "alice");
30
-
31
- assert.equal(viewers.wantsCues("alice", "src-1", 3), true);
32
- assert.deepEqual(viewers.wantingCues("src-1", 3), ["alice"]);
33
- });
34
-
35
- test("nobody is listed for a file nobody asked about", () => {
36
- const viewers = new Viewers();
37
- viewers.of(anOutput("picture"), "alice");
38
- viewers.wantsCues("alice", "src-1", 3);
39
-
40
- assert.deepEqual(viewers.wantingCues("src-1", 4), []);
41
- assert.deepEqual(viewers.wantingCues("src-2", 3), []);
42
- });
43
-
44
- test("two viewers of one file are both listed, and one file each is kept apart", () => {
45
- const viewers = new Viewers();
46
- const picture = anOutput("picture");
47
- viewers.of(picture, "alice");
48
- viewers.of(picture, "bob");
49
-
50
- viewers.wantsCues("alice", "src-1", 0);
51
- viewers.wantsCues("bob", "src-1", 0);
52
- viewers.wantsCues("bob", "src-1", 1);
53
-
54
- assert.deepEqual(viewers.wantingCues("src-1", 0).sort(), ["alice", "bob"]);
55
- assert.deepEqual(viewers.wantingCues("src-1", 1), ["bob"]);
56
- });
57
-
58
- test("the subscription outlives the connection, which is the whole point", () => {
59
- // Nothing here mentions a channel, and that is the assertion: the registry
60
- // has no way to express "this channel", so a channel dying cannot take a
61
- // subscription with it.
62
- const viewers = new Viewers();
63
- viewers.of(anOutput("picture"), "alice");
64
- viewers.wantsCues("alice", "src-1", 3);
65
-
66
- // A reconnect is, from here, nothing at all: the same person is still known.
67
- viewers.seen("alice");
68
-
69
- assert.deepEqual(viewers.wantingCues("src-1", 3), ["alice"]);
70
- });
71
-
72
- test("a viewer who has gone is no longer listed", () => {
73
- const viewers = new Viewers();
74
- const picture = anOutput("picture");
75
- viewers.of(picture, "alice");
76
- viewers.wantsCues("alice", "src-1", 3);
77
-
78
- viewers.hasGone("alice");
79
-
80
- assert.deepEqual(viewers.wantingCues("src-1", 3), []);
81
- });
82
-
83
- test("an unknown name subscribes to nothing", () => {
84
- const viewers = new Viewers();
85
- assert.equal(viewers.wantsCues("nobody", "src-1", 3), false);
86
- assert.deepEqual(viewers.wantingCues("src-1", 3), []);
87
- });
88
-
89
- test("a request missing the file index registers nothing", () => {
90
- const viewers = new Viewers();
91
- viewers.of(anOutput("picture"), "alice");
92
-
93
- assert.equal(viewers.wantsCues("alice", "src-1", Number.NaN), false);
94
- assert.equal(viewers.wantsCues("alice", "", 3), false);
95
- assert.deepEqual(viewers.wantingCues("src-1", 3), []);
96
- });
@@ -1,139 +0,0 @@
1
- /**
2
- * @file One object per person watching, and one deletion to forget them.
3
- *
4
- * It was six maps hung on the session, each keyed by consumer id, and the
5
- * forgetting was already wrong: releasing a consumer emptied none of them, so a
6
- * viewer who had left went on counting as wanting their soundtrack until their
7
- * head expired, and their entries stayed for the life of the session.
8
- */
9
-
10
- import test from "node:test";
11
- import assert from "node:assert/strict";
12
- import { SourceFile } from "../services/media/SourceFile.js";
13
- import { mkdtemp, rm } from "node:fs/promises";
14
- import os from "node:os";
15
- import path from "node:path";
16
- import { wireOutputs } from "../services/server/wire-outputs.js";
17
- import { Viewer } from "../services/viewer/Viewer.js";
18
- import { Viewers } from "../services/viewer/Viewers.js";
19
- import { outputSpec } from "./helpers/output-spec.js";
20
-
21
- const SESSION_ID = "aaaaaaaabbbbcccc";
22
-
23
- test("presence and position are two facts, and presence does not wait for a request", () => {
24
- const now = 1_000_000;
25
- const viewer = new Viewer("someone", now);
26
-
27
- // The whole of the 2026-09-05 failure in one assertion: a viewer who has
28
- // arrived and asked for nothing yet IS watching. Answered from the position
29
- // alone — which is written only when a segment is requested — this read
30
- // false, every encoder on their output was stopped for having nobody, and
31
- // the `init.mp4` they needed in order to request their first segment was
32
- // therefore never made.
33
- assert.equal(viewer.position, null, "nothing has placed them yet");
34
- assert.equal(viewer.isPresent(), true, "and they are still here");
35
-
36
- // SILENCE IS NOT ABSENCE, however long it lasts. A paused viewer, a hidden
37
- // tab whose timers the browser has throttled, and one holding two minutes of
38
- // cushion all say nothing and are all still watching — so there is no
39
- // interval that separates them from someone who has left, and the threshold
40
- // that used to try is gone.
41
- viewer.seen(now - 600_000);
42
- assert.equal(viewer.isPresent(), true, "ten minutes of silence is not leaving");
43
-
44
- // Something SAID they are gone: the browser released the session, or their
45
- // connection closed. That is the only way out.
46
- viewer.gone = true;
47
- assert.equal(viewer.isPresent(), false, "a statement is what ends it");
48
- });
49
-
50
- test("position is one fact with one writer, and a function of time", () => {
51
- const viewer = new Viewer("someone");
52
- assert.equal(viewer.positionSeconds(), null);
53
-
54
- viewer.report({ bufferedAheadSec: 60, positionSeconds: 40, playing: false }, 1_000_000);
55
- assert.equal(viewer.positionSeconds(1_000_000), 40);
56
- assert.equal(viewer.positionSeconds(1_060_000), 40, "a stopped picture covers no film");
57
-
58
- viewer.report({ bufferedAheadSec: 60, positionSeconds: 40, playing: true }, 1_000_000);
59
- assert.equal(viewer.positionSeconds(1_010_000), 50, "a playing one covers a second a second");
60
- assert.equal(
61
- viewer.positionSeconds(1_600_000),
62
- 100,
63
- "and no further than the film they said they held"
64
- );
65
-
66
- // A seek is the same statement, and there is no second field for it to win
67
- // against: two writers taking turns on one reading is what made the priority
68
- // map jump backwards several times a second in the field on 2026-09-13.
69
- viewer.moveTo(900, 1_010_000);
70
- assert.equal(viewer.positionSeconds(1_010_000), 900);
71
- assert.equal(
72
- viewer.positionSeconds(1_070_000),
73
- 900,
74
- "and a seek carries no cushion from where it left, so nothing is extrapolated"
75
- );
76
- });
77
-
78
- test("a viewer who has stated nothing has a position and does not drift from it", () => {
79
- const viewer = new Viewer("someone");
80
- viewer.moveTo(0, 1_000_000);
81
-
82
- // The whole of the fault of 2026-09-14: `playing` used to start true, and a
83
- // page that had measured nothing was never allowed to say otherwise, so a
84
- // hidden tab's viewer was carried 146 seconds into a film they had not begun.
85
- assert.equal(viewer.playing, false);
86
- assert.equal(viewer.waiting, true, "a viewer who has just arrived is waiting on us");
87
- assert.equal(viewer.positionSeconds(1_146_000), 0);
88
- });
89
-
90
- test("asking for a viewer twice is the same viewer", () => {
91
- const session = { id: "session" };
92
- const viewers = new Viewers();
93
- const first = viewers.of(session, "one");
94
- first.audio = { trackIndex: 3, transcode: false };
95
-
96
- assert.equal(viewers.of(session, "one"), first);
97
- assert.equal(viewers.of(session, "one").audio.trackIndex, 3);
98
- assert.notEqual(viewers.of(session, "two"), first);
99
- assert.equal(viewers.forOutput(session).size, 2);
100
- });
101
-
102
- test("releasing a consumer forgets everything that was true of them alone", async (t) => {
103
- const dirPath = await mkdtemp(path.join(os.tmpdir(), "viewer-"));
104
- t.after(async () => {
105
- await rm(dirPath, { recursive: true, force: true });
106
- });
107
- const manager = wireOutputs({
108
- enabled: true,
109
- ffmpegBin: "ffmpeg",
110
- localBindHost: "127.0.0.1",
111
- localPort: 9090
112
- });
113
- const session = {
114
- id: SESSION_ID,
115
- spec: outputSpec(),
116
- dirPath,
117
- state: "live",
118
- file: new SourceFile({ sourceKey: "source-1", fileIndex: 0, name: "video.mkv" }),
119
- // An ordinary session reads its own file, and its sound is inside it. The
120
- // three differ only for a soundtrack shipped as a file of its own.
121
- get inputFile() { return this.file; },
122
- get audioFile() { return this.file; },
123
- claims: new Set(),
124
- lastAccessedAt: Date.now()
125
- };
126
- manager.outputs.set(SESSION_ID, session);
127
-
128
- const leaving = manager.viewers.of(session, "leaving");
129
- leaving.audio = { trackIndex: 2, transcode: true };
130
- leaving.activeVariantId = "some-variant";
131
- leaving.position = { segment: 40, seconds: 160, at: Date.now() };
132
- manager.viewers.of(session, "staying").audio = { trackIndex: 0, transcode: false };
133
-
134
- await manager.lifecycle.releaseSessionConsumer(SESSION_ID, "leaving", "the tab was closed");
135
-
136
- assert.equal(manager.viewers.forOutput(session).has("leaving"), false, "one deletion, not six");
137
- assert.equal(manager.viewers.forOutput(session).has("staying"), true, "and it takes nobody else with it");
138
- assert.equal(manager.viewers.size, 1);
139
- });