@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/CHANGELOG.md +1220 -1209
- package/package.json +1 -1
- package/routes/api/transcode-sessions/net-report/post.js +48 -31
- package/services/hls-session-manager.js +9449 -9244
- package/test/auto-quality-step.test.js +506 -442
- package/test/quality-variants.test.js +1073 -862
package/package.json
CHANGED
|
@@ -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
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}
|