@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.
@@ -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,74 @@ 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 link reading does not expire — presence is what decides whose it is", () => {
148
+ const viewer = new Viewer("one", AT);
149
+ viewer.report({ linkMbps: 8, bufferedAheadSec: 10, positionSeconds: 5, playing: true }, AT);
150
+
151
+ // A link does not stop being what it was measured to be because nobody
152
+ // measured it for a while. The page says as much by keeping its own last
153
+ // figure rather than reporting nothing.
154
+ assert.equal(viewer.linkReading()?.linkMbps, 8);
155
+ assert.equal(viewer.linkReading()?.linkMbps, 8, "and an hour later it is still the last thing known");
156
+
157
+ // What ends it is the person leaving, which is a different fact with a
158
+ // different owner.
159
+ assert.equal(viewer.isPresent(), true);
160
+ });
161
+
162
+ test("the worst reading is taken across the people who are still here", async () => {
163
+ const { worstLinkReading } = await import("../services/viewer/link-readings.js");
164
+ const output = {};
165
+ const slow = new Viewer("slow", AT);
166
+ slow.outputs.add("out");
167
+ const fast = new Viewer("fast", AT);
168
+ fast.outputs.add("out");
169
+ output.viewers = new Map([
170
+ ["slow", slow],
171
+ ["fast", fast]
172
+ ]);
173
+ slow.report({ linkMbps: 2, bufferedAheadSec: 3, playing: true }, AT);
174
+ fast.report({ linkMbps: 40, bufferedAheadSec: 90, playing: true }, AT);
175
+
176
+ // The slowest link and the emptiest buffer, which may belong to two people.
177
+ const worst = worstLinkReading(output);
178
+ assert.equal(worst?.linkMbps, 2);
179
+ assert.equal(worst?.bufferedAheadSec, 3);
180
+ assert.equal(worst?.viewers, 2);
181
+
182
+ // The slow one leaves. Their reading goes with them, however recent it was.
183
+ slow.gone = true;
184
+ const left = worstLinkReading(output);
185
+ assert.equal(left?.linkMbps, 40);
186
+ assert.equal(left?.viewers, 1);
187
+ });
188
+
189
+ test("a report into a session that is gone is refused rather than invented", async () => {
190
+ const { recordViewerReport } = await import("../services/viewer/report-intake.js");
191
+ const sessions = new Map([["dead", { id: "dead", state: "disposed" }]]);
192
+ const viewers = { of() { throw new Error("must not be asked"); } };
193
+
194
+ assert.equal(
195
+ recordViewerReport({ sessions, viewers, sessionId: "dead", report: { bufferedAheadSec: 0 }, now: AT }),
196
+ false
197
+ );
198
+ assert.equal(
199
+ recordViewerReport({ sessions, viewers, sessionId: "never", report: { bufferedAheadSec: 0 }, now: AT }),
200
+ false
201
+ );
151
202
  });