@geekapps/silo-elements-nextjs 0.3.11 → 0.3.14

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,11 +2292,19 @@ function Video({
2292
2292
  if (Hls.isSupported()) {
2293
2293
  const hls = new Hls({
2294
2294
  enableWorker: true,
2295
- maxBufferLength: 10,
2296
- maxMaxBufferLength: 20,
2297
- maxBufferSize: 20 * 1e3 * 1e3
2295
+ maxBufferLength: 30,
2296
+ maxMaxBufferLength: 60,
2297
+ maxBufferSize: 60 * 1e3 * 1e3,
2298
+ backBufferLength: 30,
2299
+ maxBufferHole: 0.5,
2300
+ nudgeMaxRetry: 6,
2301
+ startLevel: -1,
2302
+ abrBandWidthFactor: 0.95,
2303
+ abrBandWidthUpFactor: 0.7
2298
2304
  });
2299
2305
  hlsRef.current = hls;
2306
+ let pinnedLevel = -1;
2307
+ let pinnedAudio = -1;
2300
2308
  console.debug("[Silo/hls] loadSource", activeSource.src);
2301
2309
  hls.loadSource(activeSource.src);
2302
2310
  hls.attachMedia(video);
@@ -2321,8 +2329,10 @@ function Video({
2321
2329
  label: t.name ?? t.lang ?? `Track ${i + 1}`
2322
2330
  }))
2323
2331
  );
2324
- setSelectedAudio(hls.audioTrack ?? 0);
2332
+ if (pinnedAudio === -1) setSelectedAudio(hls.audioTrack ?? 0);
2325
2333
  }
2334
+ if (pinnedLevel >= 0) hls.currentLevel = pinnedLevel;
2335
+ if (pinnedAudio >= 0) hls.audioTrack = pinnedAudio;
2326
2336
  setIsLoading(false);
2327
2337
  });
2328
2338
  hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, (_, data) => {
@@ -2336,7 +2346,22 @@ function Video({
2336
2346
  }))
2337
2347
  );
2338
2348
  }
2349
+ if (pinnedAudio >= 0 && hls.audioTrack !== pinnedAudio) {
2350
+ hls.audioTrack = pinnedAudio;
2351
+ }
2352
+ });
2353
+ hls.on(Hls.Events.LEVEL_SWITCHED, (_, data) => {
2354
+ console.debug("[Silo/hls] LEVEL_SWITCHED", data.level);
2355
+ if (pinnedAudio >= 0 && hls.audioTrack !== pinnedAudio) {
2356
+ hls.audioTrack = pinnedAudio;
2357
+ }
2339
2358
  });
2359
+ hls.__pinLevel = (level) => {
2360
+ pinnedLevel = level;
2361
+ };
2362
+ hls.__pinAudio = (track) => {
2363
+ pinnedAudio = track;
2364
+ };
2340
2365
  hls.on(Hls.Events.LEVEL_LOADED, (_, data) => {
2341
2366
  console.debug("[Silo/hls] LEVEL_LOADED level=", data.level, "fragments=", data.details?.fragments?.length);
2342
2367
  });
@@ -2350,11 +2375,29 @@ function Video({
2350
2375
  console.debug("[Silo/hls] FRAG_LOADED", data.frag?.type, data.frag?.sn);
2351
2376
  });
2352
2377
  let mediaErrorAttempts = 0;
2378
+ let audioAppendErrors = 0;
2353
2379
  hls.on(Hls.Events.ERROR, (_, data) => {
2354
2380
  const fragUrl = (data.frag?.url ?? data.url ?? "").slice(-80);
2355
2381
  const fragType = data.frag?.type ?? "?";
2356
2382
  console.debug("[Silo/hls] ERROR fatal=", data.fatal, "type=", data.type, "details=", data.details, "fragType=", fragType, "url=", fragUrl);
2357
- if (!data.fatal) return;
2383
+ if (!data.fatal) {
2384
+ const isAudioBufError = fragType === "audio" && (data.details === Hls.ErrorDetails.BUFFER_APPEND_ERROR || data.details === Hls.ErrorDetails.BUFFER_APPENDING_ERROR);
2385
+ if (isAudioBufError) {
2386
+ audioAppendErrors += 1;
2387
+ if (audioAppendErrors >= 3) {
2388
+ console.warn("[Silo/hls] repeated audio buffer errors \u2014 disabling separate audio tracks");
2389
+ setAudioTracks([]);
2390
+ try {
2391
+ hls.audioTrack = -1;
2392
+ } catch {
2393
+ }
2394
+ audioAppendErrors = 0;
2395
+ }
2396
+ } else {
2397
+ audioAppendErrors = 0;
2398
+ }
2399
+ return;
2400
+ }
2358
2401
  if (data.details === Hls.ErrorDetails.FRAG_PARSING_ERROR && fragType === "audio") {
2359
2402
  console.warn("[Silo/hls] audio frag parse failed \u2014 disabling separate audio tracks and retrying");
2360
2403
  setAudioTracks([]);
@@ -2495,6 +2538,7 @@ function Video({
2495
2538
  setSelectedAudio(trackId);
2496
2539
  closeSettings();
2497
2540
  if (hlsRef.current) {
2541
+ hlsRef.current.__pinAudio?.(trackId);
2498
2542
  hlsRef.current.audioTrack = trackId;
2499
2543
  }
2500
2544
  }, [closeSettings]);
@@ -2506,6 +2550,7 @@ function Video({
2506
2550
  closeSettings();
2507
2551
  if (option.type === "auto") {
2508
2552
  if (hlsRef.current) {
2553
+ hlsRef.current.__pinLevel?.(-1);
2509
2554
  hlsRef.current.currentLevel = -1;
2510
2555
  }
2511
2556
  if (dashRef.current) {
@@ -2522,6 +2567,8 @@ function Video({
2522
2567
  return;
2523
2568
  }
2524
2569
  if (option.type === "hls" && hlsRef.current && option.index != null) {
2570
+ hlsRef.current.__pinLevel?.(option.index);
2571
+ hlsRef.current.nextLevel = option.index;
2525
2572
  hlsRef.current.currentLevel = option.index;
2526
2573
  return;
2527
2574
  }