@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.
package/dist/index.js CHANGED
@@ -2292,15 +2292,21 @@ function Video({
2292
2292
  if (Hls.isSupported()) {
2293
2293
  const hls = new Hls({
2294
2294
  enableWorker: true,
2295
- maxBufferLength: 30,
2296
- maxMaxBufferLength: 60,
2297
- maxBufferSize: 60 * 1e3 * 1e3,
2298
- backBufferLength: 30,
2295
+ // Buffer ~20s ahead (≈1/6 of a 2min video). maxMaxBufferLength caps the
2296
+ // absolute ceiling so HLS.js doesn't buffer the entire file on fast connections.
2297
+ maxBufferLength: 20,
2298
+ maxMaxBufferLength: 30,
2299
+ maxBufferSize: 40 * 1e3 * 1e3,
2300
+ // Keep only 10s of back-buffer for seeking — avoids holding GB of 4K data
2301
+ backBufferLength: 10,
2299
2302
  maxBufferHole: 0.5,
2300
- nudgeMaxRetry: 6,
2303
+ highBufferWatchdogPeriod: 5,
2304
+ nudgeOffset: 0.2,
2305
+ nudgeMaxRetry: 3,
2301
2306
  startLevel: -1,
2302
2307
  abrBandWidthFactor: 0.95,
2303
- abrBandWidthUpFactor: 0.7
2308
+ abrBandWidthUpFactor: 0.7,
2309
+ abrEwmaDefaultEstimate: 5e6
2304
2310
  });
2305
2311
  hlsRef.current = hls;
2306
2312
  let pinnedLevel = -1;
@@ -2352,6 +2358,9 @@ function Video({
2352
2358
  });
2353
2359
  hls.on(Hls.Events.LEVEL_SWITCHED, (_, data) => {
2354
2360
  console.debug("[Silo/hls] LEVEL_SWITCHED", data.level);
2361
+ if (pinnedLevel >= 0 && data.level === pinnedLevel) {
2362
+ hls.currentLevel = pinnedLevel;
2363
+ }
2355
2364
  if (pinnedAudio >= 0 && hls.audioTrack !== pinnedAudio) {
2356
2365
  hls.audioTrack = pinnedAudio;
2357
2366
  }
@@ -2376,6 +2385,7 @@ function Video({
2376
2385
  });
2377
2386
  let mediaErrorAttempts = 0;
2378
2387
  let audioAppendErrors = 0;
2388
+ let stalledOnPinnedLevel = 0;
2379
2389
  hls.on(Hls.Events.ERROR, (_, data) => {
2380
2390
  const fragUrl = (data.frag?.url ?? data.url ?? "").slice(-80);
2381
2391
  const fragType = data.frag?.type ?? "?";
@@ -2396,6 +2406,19 @@ function Video({
2396
2406
  } else {
2397
2407
  audioAppendErrors = 0;
2398
2408
  }
2409
+ if (data.details === Hls.ErrorDetails.BUFFER_STALLED_ERROR && pinnedLevel >= 0) {
2410
+ stalledOnPinnedLevel += 1;
2411
+ if (stalledOnPinnedLevel >= 4) {
2412
+ stalledOnPinnedLevel = 0;
2413
+ const nextLevel = Math.max(0, pinnedLevel - 1);
2414
+ console.warn("[Silo/hls] repeated stalls on pinned level", pinnedLevel, "\u2014 stepping down to", nextLevel);
2415
+ pinnedLevel = nextLevel;
2416
+ hls.currentLevel = nextLevel;
2417
+ setSelectedQuality(nextLevel === 0 ? "auto" : `hls-${nextLevel}`);
2418
+ }
2419
+ } else if (data.details !== Hls.ErrorDetails.BUFFER_STALLED_ERROR) {
2420
+ stalledOnPinnedLevel = 0;
2421
+ }
2399
2422
  return;
2400
2423
  }
2401
2424
  if (data.details === Hls.ErrorDetails.FRAG_PARSING_ERROR && fragType === "audio") {
@@ -2568,7 +2591,7 @@ function Video({
2568
2591
  }
2569
2592
  if (option.type === "hls" && hlsRef.current && option.index != null) {
2570
2593
  hlsRef.current.__pinLevel?.(option.index);
2571
- hlsRef.current.currentLevel = option.index;
2594
+ hlsRef.current.nextLevel = option.index;
2572
2595
  return;
2573
2596
  }
2574
2597
  if (option.type === "dash" && dashRef.current && option.index != null) {