@geekapps/silo-elements-nextjs 0.3.15 → 0.3.17

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.
@@ -762,15 +762,21 @@ function Video({
762
762
  if (Hls.isSupported()) {
763
763
  const hls = new Hls({
764
764
  enableWorker: true,
765
- maxBufferLength: 30,
766
- maxMaxBufferLength: 60,
767
- maxBufferSize: 60 * 1e3 * 1e3,
768
- backBufferLength: 30,
765
+ // Buffer ~20s ahead (≈1/6 of a 2min video). maxMaxBufferLength caps the
766
+ // absolute ceiling so HLS.js doesn't buffer the entire file on fast connections.
767
+ maxBufferLength: 20,
768
+ maxMaxBufferLength: 30,
769
+ maxBufferSize: 40 * 1e3 * 1e3,
770
+ // Keep only 10s of back-buffer for seeking — avoids holding GB of 4K data
771
+ backBufferLength: 10,
769
772
  maxBufferHole: 0.5,
770
- nudgeMaxRetry: 6,
773
+ highBufferWatchdogPeriod: 5,
774
+ nudgeOffset: 0.2,
775
+ nudgeMaxRetry: 3,
771
776
  startLevel: -1,
772
777
  abrBandWidthFactor: 0.95,
773
- abrBandWidthUpFactor: 0.7
778
+ abrBandWidthUpFactor: 0.7,
779
+ abrEwmaDefaultEstimate: 5e6
774
780
  });
775
781
  hlsRef.current = hls;
776
782
  let pinnedLevel = -1;
@@ -822,6 +828,9 @@ function Video({
822
828
  });
823
829
  hls.on(Hls.Events.LEVEL_SWITCHED, (_, data) => {
824
830
  console.debug("[Silo/hls] LEVEL_SWITCHED", data.level);
831
+ if (pinnedLevel >= 0 && data.level === pinnedLevel) {
832
+ hls.currentLevel = pinnedLevel;
833
+ }
825
834
  if (pinnedAudio >= 0 && hls.audioTrack !== pinnedAudio) {
826
835
  hls.audioTrack = pinnedAudio;
827
836
  }
@@ -846,6 +855,7 @@ function Video({
846
855
  });
847
856
  let mediaErrorAttempts = 0;
848
857
  let audioAppendErrors = 0;
858
+ let stalledOnPinnedLevel = 0;
849
859
  hls.on(Hls.Events.ERROR, (_, data) => {
850
860
  const fragUrl = (data.frag?.url ?? data.url ?? "").slice(-80);
851
861
  const fragType = data.frag?.type ?? "?";
@@ -866,6 +876,19 @@ function Video({
866
876
  } else {
867
877
  audioAppendErrors = 0;
868
878
  }
879
+ if (data.details === Hls.ErrorDetails.BUFFER_STALLED_ERROR && pinnedLevel >= 0) {
880
+ stalledOnPinnedLevel += 1;
881
+ if (stalledOnPinnedLevel >= 4) {
882
+ stalledOnPinnedLevel = 0;
883
+ const nextLevel = Math.max(0, pinnedLevel - 1);
884
+ console.warn("[Silo/hls] repeated stalls on pinned level", pinnedLevel, "\u2014 stepping down to", nextLevel);
885
+ pinnedLevel = nextLevel;
886
+ hls.currentLevel = nextLevel;
887
+ setSelectedQuality(nextLevel === 0 ? "auto" : `hls-${nextLevel}`);
888
+ }
889
+ } else if (data.details !== Hls.ErrorDetails.BUFFER_STALLED_ERROR) {
890
+ stalledOnPinnedLevel = 0;
891
+ }
869
892
  return;
870
893
  }
871
894
  if (data.details === Hls.ErrorDetails.FRAG_PARSING_ERROR && fragType === "audio") {
@@ -1038,7 +1061,7 @@ function Video({
1038
1061
  }
1039
1062
  if (option.type === "hls" && hlsRef.current && option.index != null) {
1040
1063
  hlsRef.current.__pinLevel?.(option.index);
1041
- hlsRef.current.currentLevel = option.index;
1064
+ hlsRef.current.nextLevel = option.index;
1042
1065
  return;
1043
1066
  }
1044
1067
  if (option.type === "dash" && dashRef.current && option.index != null) {