@torrent-tv/proxy 2.107.65 → 2.107.66

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.107.65",
3
+ "version": "2.107.66",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -31,43 +31,16 @@ import { activeOutputFor } from "../viewer/active-output.js";
31
31
  import {
32
32
  acceptsGeneration,
33
33
  askQualityOf,
34
- audioBeingWarmedOf,
35
- audioChoiceOf,
36
- chooseAudioTrack,
37
- chooseOutput,
38
- chosenOutputOf,
39
- consumersOn,
40
34
  dropAskOf,
41
- generationOfRequest,
42
- givenOutputOf,
43
- heightsChosenAs,
44
- highestGivenSegmentOf,
45
35
  holdForResponse,
46
- linkMbpsOf,
47
36
  linkReportOf,
48
37
  bufferOf,
49
- bufferedSecondsOf,
50
38
  visiblePictureOf,
51
39
  linkReportsOn,
52
- noteAudioBeingWarmed,
53
- noteGivenOutput,
54
- noteSameHeightSwitch,
55
- noteServingVerdict,
56
- noteStepBeingWarmed,
57
- noteStepOnScreen,
58
40
  placeInitially,
59
- placeOn,
60
- presentOn,
61
- qualityModeOf,
62
- sameHeightSwitchOf,
63
41
  servingVerdictOf,
64
42
  standingAskOf,
65
- stepBeingWarmedOf,
66
- stepBeingWarmedSinceOf,
67
- stepOnScreenOf,
68
- switchingFrom,
69
- switchingOnto,
70
- watches
43
+ viewerRelationsFor
71
44
  } from "../viewer/choices.js";
72
45
  import { viewerSecondsOn, viewerSegmentsOn } from "../viewer/positions.js";
73
46
  import { Viewers } from "../viewer/Viewers.js";
@@ -401,6 +374,17 @@ export function wireOutputs({
401
374
  get outputTimes() { return parts.outputTimes; },
402
375
  get outputs() { return parts.outputs; },
403
376
  });
377
+ // Who listens to viewer changes subscribes here (`startPlayback`); a throw
378
+ // of a listener reaches the code that changed the viewers.
379
+ parts.viewerChanges = new EventEmitter();
380
+ parts.viewers = new Viewers({ onChange: () => {
381
+ parts.lifecycle.observeUse();
382
+ parts.encodeRuns.planEncodersSoon();
383
+ parts.viewerChanges.emit("change");
384
+ } });
385
+ // What encoding and the requests of a viewer are told about a person: values
386
+ // and names, never the viewer itself (`viewer/choices.js`).
387
+ const viewerRelations = viewerRelationsFor(parts.viewers);
404
388
  // The steps of a picture and its soundtracks: which output answers each, made when first asked for, and the master playlist listing them.
405
389
  // The cushion this file needs, from its segment length and the worst
406
390
  // interruption its supply has shown — one statement read by every operation
@@ -422,51 +406,9 @@ export function wireOutputs({
422
406
  viewerSecondsOn: (output, consumerId, now) => viewerSecondsOn(parts.viewers, output, consumerId, now),
423
407
  audioStartSecondsFor: (args) => audioStartSecondsFor({ ...args, viewers: parts.viewers }),
424
408
  activeOutputFor: (args) => activeOutputFor({ ...args, viewers: parts.viewers }),
425
- // WHAT ENCODING IS TOLD ABOUT A PERSON, and what it may tell the viewer
426
- // layer about them: values and names, never the viewer itself. Steps and
427
- // soundtracks are chosen, warmed and left per person, so this is the widest
428
- // of the three sets — and every one of them is a call on the owner, which
429
- // is what keeps one writer per fact.
430
- viewerCountOn: (output) => parts.viewers.forOutput(output).size,
431
- // Whether anything still stands on it — somebody watching, or an
432
- // assignment not yet released. See `Viewers.stillNeeded`.
433
- outputStillNeeded: (output) => parts.viewers.stillNeeded(output),
434
- consumersOn: (output) => consumersOn(parts.viewers, output),
435
- presentOn: (output) => presentOn(parts.viewers, output),
436
- qualityModeOf: (output, consumerId) => qualityModeOf(parts.viewers, output, consumerId),
437
- linkMbpsOf: (output, consumerId) => linkMbpsOf(parts.viewers, output, consumerId),
438
- audioChoiceOf: (output, consumerId) => audioChoiceOf(parts.viewers, output, consumerId),
439
- chooseAudioTrack: (output, consumerId, choice) =>
440
- chooseAudioTrack(parts.viewers, output, consumerId, choice),
441
- stepOnScreenOf: (output, consumerId) => stepOnScreenOf(parts.viewers, output, consumerId),
442
- noteStepOnScreen: (output, consumerId, stepId) =>
443
- noteStepOnScreen(parts.viewers, output, consumerId, stepId),
444
- stepBeingWarmedOf: (output, consumerId) => stepBeingWarmedOf(parts.viewers, output, consumerId),
445
- stepBeingWarmedSinceOf: (output, consumerId) => stepBeingWarmedSinceOf(parts.viewers, output, consumerId),
446
- noteStepBeingWarmed: (output, consumerId, stepId) =>
447
- noteStepBeingWarmed(parts.viewers, output, consumerId, stepId),
448
- audioBeingWarmedOf: (output, consumerId) => audioBeingWarmedOf(parts.viewers, output, consumerId),
449
- noteAudioBeingWarmed: (output, consumerId, renditionId) =>
450
- noteAudioBeingWarmed(parts.viewers, output, consumerId, renditionId),
451
- watches: (output, consumerId) => watches(parts.viewers, output, consumerId),
452
- placeOn: (output, consumerId, seconds) => placeOn(parts.viewers, output, consumerId, seconds),
453
- // A viewer's own assignments: which output answered a height and segment in
454
- // one generation of their viewing, so a repeat is answered the same way.
455
- // Values in and out, like everything above.
456
- generationOfRequest: (consumerId, stated) => generationOfRequest(parts.viewers, consumerId, stated),
457
- givenOutputOf: (consumerId, generation, askedHeight, segmentIndex) =>
458
- givenOutputOf(parts.viewers, consumerId, generation, askedHeight, segmentIndex),
459
- noteGivenOutput: (consumerId, generation, askedHeight, segmentIndex, outputKey) =>
460
- noteGivenOutput(parts.viewers, consumerId, generation, askedHeight, segmentIndex, outputKey),
461
- // The output this viewer was chosen at a height, and the rule's choice of
462
- // it — the viewer's own record, never one per file.
463
- chosenOutputOf: (consumerId, askedHeight) => chosenOutputOf(parts.viewers, consumerId, askedHeight),
464
- chooseOutput: (consumerId, askedHeight, outputKey) => chooseOutput(parts.viewers, consumerId, askedHeight, outputKey),
465
- noteServingVerdict: (consumerId, verdict) => noteServingVerdict(parts.viewers, consumerId, verdict),
466
- // A move between two limits of the height on a viewer's screen (roadmap
467
- // item 97, step 12): which heights their choice is the output on screen
468
- // under, the segment they were last given, the move being prepared, and
469
- // whether a segment is closed on the output being prepared.
409
+ // What encoding is told about a person: values and names, never the viewer
410
+ // itself (`viewer/choices.js`, `viewerRelationsFor`).
411
+ ...viewerRelationsFor(parts.viewers),
470
412
  limitsFor: (frame, file) => parts.limitsFor(frame, file),
471
413
  // A move between two speed settings of the size on a viewer's screen
472
414
  // (torrent-tv/meta#178): the settings this machine measured, in quality
@@ -485,15 +427,8 @@ export function wireOutputs({
485
427
  }
486
428
  },
487
429
  requiredSpeedOf: (output) => parts.hostLoad.requiredSpeedFor(output.file.sourceKey, output.file.fileIndex) ?? 1,
488
- heightsChosenAs: (consumerId, outputKey) => heightsChosenAs(parts.viewers, consumerId, outputKey),
489
- highestGivenSegmentOf: (consumerId, askedHeight) => highestGivenSegmentOf(parts.viewers, consumerId, askedHeight),
490
- sameHeightSwitchOf: (consumerId) => sameHeightSwitchOf(parts.viewers, consumerId),
491
- noteSameHeightSwitch: (consumerId, value) => noteSameHeightSwitch(parts.viewers, consumerId, value),
492
- switchingOnto: (output) => switchingOnto(parts.viewers, output),
493
- switchingFrom: (output) => switchingFrom(parts.viewers, output),
494
- // What a viewer holds, and the cushion this file needs before a move that
495
- // is not urgent is made (roadmap item 98).
496
- bufferedSecondsOf: (consumerId) => bufferedSecondsOf(parts.viewers, consumerId),
430
+ // The cushion this file needs before a move that is not urgent is made
431
+ // (roadmap item 98).
497
432
  minimumBufferSecondsFor: (output) => minimumBufferSecondsOf(output),
498
433
  // Whether the whole machine has a place for one more encoder on this output,
499
434
  // asked before a preparation is recorded.
@@ -706,8 +641,7 @@ export function wireOutputs({
706
641
  get outputs() { return parts.outputs; },
707
642
  placeViewerOn: (output, consumerId, seconds, now) =>
708
643
  placeInitially(parts.viewers, output, consumerId, seconds, now),
709
- chooseAudioTrack: (output, consumerId, choice) =>
710
- chooseAudioTrack(parts.viewers, output, consumerId, choice),
644
+ chooseAudioTrack: viewerRelations.chooseAudioTrack,
711
645
  get lookaheadSeconds() { return parts.lookaheadSeconds; },
712
646
  get quality() { return parts.quality; },
713
647
  get qualityOffer() { return parts.qualityOffer; },
@@ -721,11 +655,10 @@ export function wireOutputs({
721
655
  // Whether a request of this generation is still taken, what it belongs to,
722
656
  // what answered it, and the hold a response keeps while it is being sent.
723
657
  acceptsGeneration: (consumerId, stated) => acceptsGeneration(parts.viewers, consumerId, stated),
724
- generationOfRequest: (consumerId, stated) => generationOfRequest(parts.viewers, consumerId, stated),
725
- noteGivenOutput: (consumerId, generation, askedHeight, segmentIndex, outputKey) =>
726
- noteGivenOutput(parts.viewers, consumerId, generation, askedHeight, segmentIndex, outputKey),
658
+ generationOfRequest: viewerRelations.generationOfRequest,
659
+ noteGivenOutput: viewerRelations.noteGivenOutput,
727
660
  holdForResponse: (consumerId, outputKey) => holdForResponse(parts.viewers, consumerId, outputKey),
728
- noteServingVerdict: (consumerId, verdict) => noteServingVerdict(parts.viewers, consumerId, verdict),
661
+ noteServingVerdict: viewerRelations.noteServingVerdict,
729
662
  servingVerdictOf: (consumerId) => servingVerdictOf(parts.viewers, consumerId),
730
663
  });
731
664
  // How long each output took to its first served segment, said once in the log.
@@ -980,14 +913,6 @@ export function wireOutputs({
980
913
  // be re-taken on a five-second timer instead, which made a just-created
981
914
  // output wait up to five seconds before anything noticed it had a viewer.
982
915
  parts.retention = new OutputRetention();
983
- // Who listens to viewer changes subscribes here (`startPlayback`); a throw
984
- // of a listener reaches the code that changed the viewers.
985
- parts.viewerChanges = new EventEmitter();
986
- parts.viewers = new Viewers({ onChange: () => {
987
- parts.lifecycle.observeUse();
988
- parts.encodeRuns.planEncodersSoon();
989
- parts.viewerChanges.emit("change");
990
- } });
991
916
  // The outputs that exist, and every question about them: the picture a step
992
917
  // belongs to, the steps, the soundtracks, the height a step is named by.
993
918
  parts.outputs = new OutputCatalog({
@@ -1296,9 +1221,9 @@ export function wireOutputs({
1296
1221
  },
1297
1222
  // WHAT ENCODING IS TOLD ABOUT A PERSON: values, by name. Not the viewer,
1298
1223
  // whose record belongs to the viewer layer and is written only there.
1299
- consumersOn: (output) => consumersOn(parts.viewers, output),
1300
- qualityModeOf: (output, consumerId) => qualityModeOf(parts.viewers, output, consumerId),
1301
- stepOnScreenOf: (output, consumerId) => stepOnScreenOf(parts.viewers, output, consumerId),
1224
+ consumersOn: viewerRelations.consumersOn,
1225
+ qualityModeOf: viewerRelations.qualityModeOf,
1226
+ stepOnScreenOf: viewerRelations.stepOnScreenOf,
1302
1227
  standingAskOf: (output, consumerId) => standingAskOf(parts.viewers, output, consumerId),
1303
1228
  askQualityOf: (output, consumerId, height, reason, now, urgent) =>
1304
1229
  askQualityOf(parts.viewers, output, consumerId, height, reason, now, urgent),
@@ -1318,7 +1243,7 @@ export function wireOutputs({
1318
1243
  // EACH viewer's own link and who is present: a thin link decides for the
1319
1244
  // person on it and for nobody else (roadmap item 97, step 11), so the
1320
1245
  // budget asks per viewer instead of taking the worst over all of them.
1321
- presentOn: (output) => presentOn(parts.viewers, output),
1246
+ presentOn: viewerRelations.presentOn,
1322
1247
  linkReportOf: (output, consumerId) => linkReportOf(parts.viewers, output, consumerId),
1323
1248
  // The soundtrack a viewer receives, as part of the load their link carries.
1324
1249
  viewerAudioLoadOf: (base, consumerId) => parts.renditions.viewerAudioLoadOf(base, consumerId),
@@ -668,3 +668,66 @@ export function bufferedSecondsOf(viewers, consumerId) {
668
668
  const held = consumerId ? viewers.get(consumerId)?.bufferedSeconds : null;
669
669
  return Number.isFinite(held) ? Math.max(0, held) : 0;
670
670
  }
671
+
672
+ /**
673
+ * The viewer relations of the Renditions host: every port of it that is the
674
+ * viewers' records asked and told by name.
675
+ *
676
+ * WHAT ENCODING IS TOLD ABOUT A PERSON, and what it may tell the viewer layer
677
+ * about them: values and names, never the viewer itself. Steps and soundtracks
678
+ * are chosen, warmed and left per person, so this is the widest of the sets
679
+ * encoding reads — and every one of them is a call on the owner, which is what
680
+ * keeps one writer per fact. Production spreads this into the host it builds
681
+ * (`server/wire-outputs.js`), and a check takes the same function
682
+ * (`test/no-torrent/helpers/renditions.js`), so the two cannot drift.
683
+ *
684
+ * @param {object} viewers - The `Viewers` registry the relations answer over.
685
+ * @returns {Record<string, Function>}
686
+ */
687
+ export function viewerRelationsFor(viewers) {
688
+ return {
689
+ viewerCountOn: (output) => viewers.forOutput(output).size,
690
+ // Whether anything still stands on it — somebody watching, or an
691
+ // assignment not yet released. See `Viewers.stillNeeded`.
692
+ outputStillNeeded: (output) => viewers.stillNeeded(output),
693
+ consumersOn: (output) => consumersOn(viewers, output),
694
+ presentOn: (output) => presentOn(viewers, output),
695
+ qualityModeOf: (output, consumerId) => qualityModeOf(viewers, output, consumerId),
696
+ linkMbpsOf: (output, consumerId) => linkMbpsOf(viewers, output, consumerId),
697
+ audioChoiceOf: (output, consumerId) => audioChoiceOf(viewers, output, consumerId),
698
+ chooseAudioTrack: (output, consumerId, choice) => chooseAudioTrack(viewers, output, consumerId, choice),
699
+ stepOnScreenOf: (output, consumerId) => stepOnScreenOf(viewers, output, consumerId),
700
+ noteStepOnScreen: (output, consumerId, stepId) => noteStepOnScreen(viewers, output, consumerId, stepId),
701
+ stepBeingWarmedOf: (output, consumerId) => stepBeingWarmedOf(viewers, output, consumerId),
702
+ stepBeingWarmedSinceOf: (output, consumerId) => stepBeingWarmedSinceOf(viewers, output, consumerId),
703
+ noteStepBeingWarmed: (output, consumerId, stepId) => noteStepBeingWarmed(viewers, output, consumerId, stepId),
704
+ audioBeingWarmedOf: (output, consumerId) => audioBeingWarmedOf(viewers, output, consumerId),
705
+ noteAudioBeingWarmed: (output, consumerId, renditionId) =>
706
+ noteAudioBeingWarmed(viewers, output, consumerId, renditionId),
707
+ watches: (output, consumerId) => watches(viewers, output, consumerId),
708
+ placeOn: (output, consumerId, seconds) => placeOn(viewers, output, consumerId, seconds),
709
+ // A viewer's own assignments: which output answered a height and segment in
710
+ // one generation of their viewing, so a repeat is answered the same way.
711
+ generationOfRequest: (consumerId, stated) => generationOfRequest(viewers, consumerId, stated),
712
+ givenOutputOf: (consumerId, generation, askedHeight, segmentIndex) =>
713
+ givenOutputOf(viewers, consumerId, generation, askedHeight, segmentIndex),
714
+ noteGivenOutput: (consumerId, generation, askedHeight, segmentIndex, outputKey) =>
715
+ noteGivenOutput(viewers, consumerId, generation, askedHeight, segmentIndex, outputKey),
716
+ // The output this viewer was chosen at a height, and the rule's choice of
717
+ // it — the viewer's own record, never one per file.
718
+ chosenOutputOf: (consumerId, askedHeight) => chosenOutputOf(viewers, consumerId, askedHeight),
719
+ chooseOutput: (consumerId, askedHeight, outputKey) => chooseOutput(viewers, consumerId, askedHeight, outputKey),
720
+ noteServingVerdict: (consumerId, verdict) => noteServingVerdict(viewers, consumerId, verdict),
721
+ heightsChosenAs: (consumerId, outputKey) => heightsChosenAs(viewers, consumerId, outputKey),
722
+ highestGivenSegmentOf: (consumerId, askedHeight) => highestGivenSegmentOf(viewers, consumerId, askedHeight),
723
+ // A move between two limits of the height on a viewer's screen: the segment
724
+ // they were last given, the move being prepared, and the outputs it is
725
+ // between.
726
+ sameHeightSwitchOf: (consumerId) => sameHeightSwitchOf(viewers, consumerId),
727
+ noteSameHeightSwitch: (consumerId, value) => noteSameHeightSwitch(viewers, consumerId, value),
728
+ switchingOnto: (output) => switchingOnto(viewers, output),
729
+ switchingFrom: (output) => switchingFrom(viewers, output),
730
+ // What a viewer holds.
731
+ bufferedSecondsOf: (consumerId) => bufferedSecondsOf(viewers, consumerId)
732
+ };
733
+ }