@torrent-tv/proxy 2.59.2 → 2.60.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torrent-tv/proxy",
3
- "version": "2.59.2",
3
+ "version": "2.60.0",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "publishConfig": {
@@ -1,31 +1,48 @@
1
- /**
2
- * Accept a viewer link report for a transcode session (adaptive bitrate).
3
- * The browser measures its own data-channel throughput per segment fetch and
4
- * posts a rolling median + its buffered seconds; the session manager's budget
5
- * loop uses the latest report as the link-deficit downshift trigger.
6
- *
7
- * POST /api/transcode-sessions/:sessionId/net-report
8
- * Body: { linkMbps: number, bufferedAheadSec: number }
9
- *
10
- * Best-effort telemetry: invalid body → 400, unknown session → 404, ok → 204.
11
- *
12
- * @param {import("fastify").FastifyRequest} req
13
- * @param {import("fastify").FastifyReply} reply
14
- * @param {{ hlsSessionManager: import("../../../../services/hls-session-manager.js").HlsSessionManager }} deps
15
- * @returns {Promise<void>}
16
- */
17
- export async function handleApiTranscodeSessionNetReportPost(req, reply, { hlsSessionManager }) {
18
- const sessionId = typeof req.params.sessionId === "string" ? req.params.sessionId : "";
19
- const body = req.body && typeof req.body === "object" && !Array.isArray(req.body) ? req.body : {};
20
- const linkMbps = Number(body.linkMbps);
21
- const bufferedAheadSec = Number(body.bufferedAheadSec);
22
- if (!sessionId || !Number.isFinite(linkMbps) || linkMbps <= 0 || !Number.isFinite(bufferedAheadSec) || bufferedAheadSec < 0) {
23
- return reply.code(400).send({ error: "linkMbps (>0) and bufferedAheadSec (>=0) are required." });
24
- }
25
-
26
- const recorded = hlsSessionManager.recordNetReport(sessionId, { linkMbps, bufferedAheadSec });
27
- if (!recorded) {
28
- return reply.code(404).send({ error: "Transcode session was not found." });
29
- }
30
- return reply.code(204).send();
31
- }
1
+ /**
2
+ * Accept a viewer link report for a transcode session (adaptive bitrate).
3
+ * The browser measures its own data-channel throughput per segment fetch and
4
+ * posts a rolling median + its buffered seconds; the session manager's budget
5
+ * loop uses the latest report as the link-deficit downshift trigger.
6
+ *
7
+ * POST /api/transcode-sessions/:sessionId/net-report
8
+ * Body: { linkMbps: number, bufferedAheadSec: number,
9
+ * consumerId?: string, positionSeconds?: number }
10
+ *
11
+ * `consumerId` and `positionSeconds` say WHO is reporting and WHERE they are.
12
+ * A copied picture is one session shared by every viewer of it, so without them
13
+ * the proxy could only act on whichever viewer reported last. Both are
14
+ * optional: a browser that sends neither is treated exactly as before.
15
+ *
16
+ * Best-effort telemetry: invalid body → 400, unknown session → 404, ok → 204.
17
+ *
18
+ * @param {import("fastify").FastifyRequest} req
19
+ * @param {import("fastify").FastifyReply} reply
20
+ * @param {{ hlsSessionManager: import("../../../../services/hls-session-manager.js").HlsSessionManager }} deps
21
+ * @returns {Promise<void>}
22
+ */
23
+ export async function handleApiTranscodeSessionNetReportPost(req, reply, { hlsSessionManager }) {
24
+ const sessionId = typeof req.params.sessionId === "string" ? req.params.sessionId : "";
25
+ const body = req.body && typeof req.body === "object" && !Array.isArray(req.body) ? req.body : {};
26
+ const linkMbps = Number(body.linkMbps);
27
+ const bufferedAheadSec = Number(body.bufferedAheadSec);
28
+ if (!sessionId || !Number.isFinite(linkMbps) || linkMbps <= 0 || !Number.isFinite(bufferedAheadSec) || bufferedAheadSec < 0) {
29
+ return reply.code(400).send({ error: "linkMbps (>0) and bufferedAheadSec (>=0) are required." });
30
+ }
31
+
32
+ // Neither is required, and neither can make a report invalid: they are what
33
+ // the proxy uses to tell the viewers of one session apart, and a report
34
+ // without them is still a truthful reading of somebody's link.
35
+ const consumerId = typeof body.consumerId === "string" ? body.consumerId.trim() : "";
36
+ const positionSeconds = Number(body.positionSeconds);
37
+ const recorded = hlsSessionManager.recordNetReport(sessionId, {
38
+ linkMbps,
39
+ bufferedAheadSec,
40
+ consumerId,
41
+ positionSeconds:
42
+ Number.isFinite(positionSeconds) && positionSeconds >= 0 ? positionSeconds : undefined
43
+ });
44
+ if (!recorded) {
45
+ return reply.code(404).send({ error: "Transcode session was not found." });
46
+ }
47
+ return reply.code(204).send();
48
+ }