@torrent-tv/proxy 2.85.0 → 2.86.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.
@@ -1,63 +1,45 @@
1
- /**
2
- * @file A viewer's statement about itself, taken in.
3
- *
4
- * The VIEWER layer's own entry point, and the whole of what happens when a page
5
- * says where it is: the statement reaches the person it is about, and readings
6
- * that have gone stale stop deciding for the people still here.
7
- *
8
- * It lived in the session manager, which is a description of an OUTPUT, and the
9
- * two questions were tangled there: whether this is a measurement of a LINK,
10
- * and whether this is a statement by a VIEWER. Required to be both, a page that
11
- * had measured nothing could say nothing — see `Viewer.report`.
12
- *
13
- * Given the session and the registry as plain arguments, so nothing here knows
14
- * how a session is found, what a variant is, or that there is an encoder.
15
- */
16
-
17
- import { viewersOf } from "./Viewer.js";
18
-
19
- /**
20
- * Take one report.
21
- *
22
- * @param {object} params
23
- * @param {{ of: (session: object, consumerId: string) => import("./Viewer.js").Viewer }} params.viewers
24
- * @param {object} params.session - The output this viewer has on screen.
25
- * @param {string} params.consumerId - Who is reporting; empty when the page
26
- * does not name itself, and then every such page shares one viewer, which is
27
- * exactly what one unnamed browser is.
28
- * @param {object} params.report - What they said about themselves.
29
- * @param {number} params.now
30
- * @param {number} params.linkFreshMs - How long a link reading describes the
31
- * link it was measured on.
32
- * @returns {true}
33
- */
34
- export function takeViewerReport({ viewers, session, consumerId, report, now, linkFreshMs }) {
35
- viewers.of(session, consumerId).report(report, now);
36
- forgetStaleLinkReadings({ session, now, linkFreshMs });
37
- return true;
38
- }
39
-
40
- /**
41
- * Drop link readings older than the time they describe.
42
- *
43
- * ONLY THE READING EXPIRES. Whether the person is still watching is a different
44
- * question with its own answer — their connection — and a viewer who has simply
45
- * stopped reporting is not thereby gone. Answering both from this one place is
46
- * what stopped a soundtrack's encoder on 2026-09-05, seconds after it started
47
- * and before it had made the `init.mp4` the picture could not be played
48
- * without.
49
- *
50
- * @param {object} params
51
- * @param {object} params.session
52
- * @param {number} params.now
53
- * @param {number} params.linkFreshMs
54
- * @returns {void}
55
- */
56
- export function forgetStaleLinkReadings({ session, now, linkFreshMs }) {
57
- for (const viewer of viewersOf(session).values()) {
58
- const reading = viewer.netReport;
59
- if (reading !== null && now - reading.at > linkFreshMs) {
60
- viewer.netReport = null;
61
- }
62
- }
63
- }
1
+ /**
2
+ * @file A viewer's statement about itself, taken in.
3
+ *
4
+ * The VIEWER layer's own entry point, and the whole of what happens when a page
5
+ * says where it is: the output the reporter has on screen is resolved, and the
6
+ * statement reaches the person it is about. Nothing expires here — a link
7
+ * reading is the last thing known about that link, and whether it is still
8
+ * somebody's is presence's answer (`Viewer.linkReading`).
9
+ *
10
+ * It lived in the session manager, which is a description of an OUTPUT, and the
11
+ * two questions were tangled there: whether this is a measurement of a LINK,
12
+ * and whether this is a statement by a VIEWER. Required to be both, a page that
13
+ * had measured nothing could say nothing — see `Viewer.report`.
14
+ *
15
+ * Given the sessions and the registry as plain values, so nothing here knows
16
+ * how a session is found, what a variant is, or that there is an encoder.
17
+ */
18
+
19
+ import { activeOutputFor } from "./active-output.js";
20
+
21
+ /**
22
+ * Take one report from one viewer.
23
+ *
24
+ * @param {object} params
25
+ * @param {{ get: (id: string) => object | undefined }} params.sessions - Every live session, by id.
26
+ * @param {{ of: (session: object, consumerId: string) => import("./Viewer.js").Viewer }} params.viewers
27
+ * @param {string} params.sessionId - The session the page addresses, which is
28
+ * always the picture's: the browser is not told which rung it is on.
29
+ * @param {object} params.report - What they said about themselves.
30
+ * @param {number} [params.now]
31
+ * @returns {boolean} False when no such session is live, which is the page
32
+ * reporting into one that has been disposed.
33
+ */
34
+ export function recordViewerReport({ sessions, viewers, sessionId, report, now = Date.now() }) {
35
+ const named = sessions.get(sessionId);
36
+ if (!named || named.state === "disposed") {
37
+ return false;
38
+ }
39
+ const consumerId = typeof report?.consumerId === "string" ? report.consumerId : "";
40
+ // The stream on screen is the reporter's own: with two viewers on two rungs,
41
+ // one report says nothing about the other's encoder.
42
+ const session = activeOutputFor({ base: named, consumerId, sessions, viewers });
43
+ viewers.of(session, consumerId).report(report, now);
44
+ return true;
45
+ }