@torrent-tv/proxy 2.59.3 → 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.
@@ -59,6 +59,7 @@ function fakeSession({ id, encodeHeight, dirPath, transcodeVideo = true }) {
59
59
  seekSettleTimer: null,
60
60
  seekTarget: null,
61
61
  waitEpoch: 0,
62
+ netReports: new Map(),
62
63
  usesExplicitCuts: false,
63
64
  useSyntheticPlaylist: true,
64
65
  playlistText: "#EXTM3U\n",
@@ -660,7 +661,12 @@ test("a separately published audio track starts where the picture is, from the r
660
661
  // picture — so the viewer is at 100 s, and that, less a segment of margin,
661
662
  // is where the track has to begin.
662
663
  base.viewerPositionSeconds = 140;
663
- base.netReport = { linkMbps: 20, bufferedAheadSec: 40, at: Date.now() };
664
+ base.netReports.set("viewer", {
665
+ linkMbps: 20,
666
+ bufferedAheadSec: 40,
667
+ positionSeconds: null,
668
+ at: Date.now()
669
+ });
664
670
  manager.getCachedAudioTracks = () => [
665
671
  { index: 0, language: "rus", title: "", isDefault: true },
666
672
  { index: 1, language: "eng", title: "", isDefault: false }
@@ -683,6 +689,87 @@ test("a separately published audio track starts where the picture is, from the r
683
689
  );
684
690
  });
685
691
 
692
+ test("with two viewers the audio track starts at the EARLIEST picture, not the read head", async (t) => {
693
+ const { manager, base, dirPath } = await managerWithBase();
694
+ t.after(async () => {
695
+ await manager.disposeAll();
696
+ await rm(dirPath, { recursive: true, force: true });
697
+ });
698
+ base.audioSeparate = true;
699
+ // A copied picture is one session shared by both of them. The read head is
700
+ // the furthest request of EITHER, so it belongs to the viewer in front.
701
+ base.viewerPositionSeconds = 140;
702
+ base.netReports.set("ahead", {
703
+ linkMbps: 20,
704
+ bufferedAheadSec: 40,
705
+ positionSeconds: 100,
706
+ at: Date.now()
707
+ });
708
+ base.netReports.set("behind", {
709
+ linkMbps: 20,
710
+ bufferedAheadSec: 8,
711
+ positionSeconds: 40,
712
+ at: Date.now()
713
+ });
714
+ manager.getCachedAudioTracks = () => [
715
+ { index: 0, language: "rus", title: "", isDefault: true },
716
+ { index: 1, language: "eng", title: "", isDefault: false }
717
+ ];
718
+ const created = [];
719
+ manager.createOrGetSession = async (params) => {
720
+ created.push(params);
721
+ const rendition = fakeSession({ id: VARIANT_ID, encodeHeight: 0, dirPath });
722
+ rendition.audioOnly = true;
723
+ return { sessionId: VARIANT_ID, session: rendition };
724
+ };
725
+
726
+ await manager.resolveAudioRenditionFile(BASE_ID, 1, "segment-00010.mp4");
727
+
728
+ assert.equal(
729
+ created[0].startPositionSeconds,
730
+ 36,
731
+ "the viewer at 40 s, less one segment of margin — a run starting at the leader " +
732
+ "has nothing to give the one behind them"
733
+ );
734
+ });
735
+
736
+ test("a position past the read head is clamped rather than acted on", async (t) => {
737
+ const { manager, base, dirPath } = await managerWithBase();
738
+ t.after(async () => {
739
+ await manager.disposeAll();
740
+ await rm(dirPath, { recursive: true, force: true });
741
+ });
742
+ base.audioSeparate = true;
743
+ base.viewerPositionSeconds = 140;
744
+ // Reports and requests race; a position claiming to be past everything that
745
+ // has been asked for would start the run where no request can reach it.
746
+ base.netReports.set("viewer", {
747
+ linkMbps: 20,
748
+ bufferedAheadSec: 40,
749
+ positionSeconds: 900,
750
+ at: Date.now()
751
+ });
752
+ manager.getCachedAudioTracks = () => [
753
+ { index: 0, language: "rus", title: "", isDefault: true },
754
+ { index: 1, language: "eng", title: "", isDefault: false }
755
+ ];
756
+ const created = [];
757
+ manager.createOrGetSession = async (params) => {
758
+ created.push(params);
759
+ const rendition = fakeSession({ id: VARIANT_ID, encodeHeight: 0, dirPath });
760
+ rendition.audioOnly = true;
761
+ return { sessionId: VARIANT_ID, session: rendition };
762
+ };
763
+
764
+ await manager.resolveAudioRenditionFile(BASE_ID, 1, "segment-00010.mp4");
765
+
766
+ assert.equal(
767
+ created[0].startPositionSeconds,
768
+ 136,
769
+ "clamped to the read head, less one segment of margin"
770
+ );
771
+ });
772
+
686
773
  test("a stale buffer report is not used to place an audio track", async (t) => {
687
774
  const { manager, base, dirPath } = await managerWithBase();
688
775
  t.after(async () => {
@@ -691,9 +778,14 @@ test("a stale buffer report is not used to place an audio track", async (t) => {
691
778
  });
692
779
  base.audioSeparate = true;
693
780
  base.viewerPositionSeconds = 300;
694
- // Sent a minute ago: the viewer may have seeked anywhere since, so it says
695
- // nothing about where they are now.
696
- base.netReport = { linkMbps: 20, bufferedAheadSec: 5, at: Date.now() - 60_000 };
781
+ // Sent a minute ago: the viewer may have seeked anywhere since, so neither
782
+ // the buffer nor the position in it says where they are now.
783
+ base.netReports.set("viewer", {
784
+ linkMbps: 20,
785
+ bufferedAheadSec: 5,
786
+ positionSeconds: 250,
787
+ at: Date.now() - 60_000
788
+ });
697
789
  manager.getCachedAudioTracks = () => [
698
790
  { index: 0, language: "rus", title: "", isDefault: true },
699
791
  { index: 1, language: "eng", title: "", isDefault: false }