@torrent-tv/proxy 2.85.0 → 2.85.1

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.
@@ -111,9 +111,14 @@ test("a page that is not on screen wants nothing now, whatever else it says", ()
111
111
  assert.equal(viewer.wantsFilmNow(), false);
112
112
  });
113
113
 
114
- test("the intake keeps a link reading only while it describes the link", async () => {
115
- const { takeViewerReport } = await import("../services/viewer/report-intake.js");
116
- const session = {};
114
+ test("the intake hands the statement to the viewer on the output they are watching", async () => {
115
+ const { recordViewerReport } = await import("../services/viewer/report-intake.js");
116
+ const picture = { id: "picture", state: "ready", activeVariantId: "rung" };
117
+ const rung = { id: "rung", state: "ready" };
118
+ const sessions = new Map([
119
+ ["picture", picture],
120
+ ["rung", rung]
121
+ ]);
117
122
  const viewers = {
118
123
  of(target, id) {
119
124
  target.viewers ??= new Map();
@@ -124,28 +129,44 @@ test("the intake keeps a link reading only while it describes the link", async (
124
129
  }
125
130
  };
126
131
 
127
- takeViewerReport({
132
+ // The page always addresses the PICTURE — it is never told which rung it is
133
+ // on — and the statement belongs to the rung actually on screen.
134
+ const taken = recordViewerReport({
135
+ sessions,
128
136
  viewers,
129
- session,
130
- consumerId: "one",
131
- report: { linkMbps: 8, bufferedAheadSec: 10, positionSeconds: 5, playing: true },
132
- now: AT,
133
- linkFreshMs: 30_000
137
+ sessionId: "picture",
138
+ report: { linkMbps: 8, bufferedAheadSec: 10, positionSeconds: 5, playing: true, consumerId: "one" },
139
+ now: AT
134
140
  });
135
- assert.equal(session.viewers.get("one").netReport?.linkMbps, 8);
136
141
 
137
- // A second report, a minute later, from somebody else: the first viewer's
138
- // reading has aged past what it describes and stops deciding for them. Who is
139
- // still watching is a different question and is not touched.
140
- takeViewerReport({
141
- viewers,
142
- session,
143
- consumerId: "two",
144
- report: { bufferedAheadSec: 0, playing: false, waiting: true },
145
- now: AT + 60_000,
146
- linkFreshMs: 30_000
147
- });
148
- assert.equal(session.viewers.get("one").netReport, null);
149
- assert.equal(session.viewers.get("one").isPresent(), true);
150
- assert.equal(session.viewers.get("two").waiting, true);
142
+ assert.equal(taken, true);
143
+ assert.equal(rung.viewers.get("one").positionSeconds(AT), 5);
144
+ assert.equal(picture.viewers?.has("one") ?? false, false);
145
+ });
146
+
147
+ test("a reading decides nothing once it is older than the link it describes", () => {
148
+ const viewer = new Viewer("one", AT);
149
+ viewer.report({ linkMbps: 8, bufferedAheadSec: 10, positionSeconds: 5, playing: true }, AT);
150
+
151
+ assert.equal(viewer.linkReading(AT)?.linkMbps, 8);
152
+ assert.equal(viewer.linkReading(AT + 29_000)?.linkMbps, 8);
153
+ assert.equal(viewer.linkReading(AT + 31_000), null);
154
+ // Nothing was deleted: the viewer is still here and still where they said.
155
+ assert.equal(viewer.isPresent(), true);
156
+ assert.equal(viewer.positionSeconds(AT + 31_000), 15);
157
+ });
158
+
159
+ test("a report into a session that is gone is refused rather than invented", async () => {
160
+ const { recordViewerReport } = await import("../services/viewer/report-intake.js");
161
+ const sessions = new Map([["dead", { id: "dead", state: "disposed" }]]);
162
+ const viewers = { of() { throw new Error("must not be asked"); } };
163
+
164
+ assert.equal(
165
+ recordViewerReport({ sessions, viewers, sessionId: "dead", report: { bufferedAheadSec: 0 }, now: AT }),
166
+ false
167
+ );
168
+ assert.equal(
169
+ recordViewerReport({ sessions, viewers, sessionId: "never", report: { bufferedAheadSec: 0 }, now: AT }),
170
+ false
171
+ );
151
172
  });