stormcloud-video-player 0.8.41 → 0.8.43

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.
@@ -2494,51 +2494,96 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
2494
2494
  this.host.restartHlsLoad(liveSyncPos);
2495
2495
  }
2496
2496
  this.resumeContentPlayback();
2497
- this.monitorLiveResumeStall(0, this.host.video.currentTime);
2497
+ this.monitorLiveResumeStall(this.host.video.currentTime);
2498
2498
  return;
2499
2499
  }
2500
2500
  this.resumeContentPlayback();
2501
2501
  }
2502
2502
  },
2503
+ {
2504
+ key: "getBufferedAhead",
2505
+ value: function getBufferedAhead() {
2506
+ var video = this.host.video;
2507
+ var t = video.currentTime;
2508
+ var ranges = video.buffered;
2509
+ for(var i = 0; i < ranges.length; i++){
2510
+ if (t >= ranges.start(i) - 0.5 && t <= ranges.end(i)) {
2511
+ return ranges.end(i) - t;
2512
+ }
2513
+ }
2514
+ return 0;
2515
+ }
2516
+ },
2503
2517
  {
2504
2518
  key: "monitorLiveResumeStall",
2505
- value: function monitorLiveResumeStall(attempt, lastTime) {
2519
+ value: function monitorLiveResumeStall(resumeBaseline) {
2506
2520
  var _this = this;
2507
- var maxAttempts = 3;
2508
- var checkDelayMs = 2500;
2509
- window.setTimeout(function() {
2521
+ var pollIntervalMs = 1e3;
2522
+ var graceMs = 5e3;
2523
+ var recoveryCooldownMs = 5e3;
2524
+ var maxRecoveries = 2;
2525
+ var maxMonitorMs = 3e4;
2526
+ var startTime = Date.now();
2527
+ var baseline = resumeBaseline;
2528
+ var recoveries = 0;
2529
+ var lastRecoveryAt = 0;
2530
+ var poll = function poll1() {
2510
2531
  if (_this.inAdBreak) {
2511
2532
  return;
2512
2533
  }
2513
- var currentTime = _this.host.video.currentTime;
2514
- var advanced = currentTime > lastTime + 0.25;
2515
- if (advanced && !_this.host.video.paused) {
2534
+ var video = _this.host.video;
2535
+ var currentTime = video.currentTime;
2536
+ var advanced = currentTime > baseline + 0.5;
2537
+ var playing = !video.paused && video.readyState >= 3;
2538
+ if (advanced && playing) {
2516
2539
  if (_this.debug) {
2517
2540
  console.log("[StormcloudVideoPlayer] Live stream resumed successfully after ad break");
2518
2541
  }
2519
2542
  return;
2520
2543
  }
2521
- if (attempt >= maxAttempts) {
2522
- if (_this.debug) {
2523
- console.warn("[StormcloudVideoPlayer] Live stream failed to resume after ".concat(maxAttempts, " recovery attempts (t=").concat(currentTime.toFixed(2), "s)"));
2544
+ if (video.paused) {
2545
+ var _video_play;
2546
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
2547
+ }
2548
+ var elapsed = Date.now() - startTime;
2549
+ var bufferedAhead = _this.getBufferedAhead();
2550
+ var wedged = bufferedAhead < 0.5 && !advanced;
2551
+ if (elapsed >= maxMonitorMs) {
2552
+ if (_this.debug && !advanced) {
2553
+ console.warn("[StormcloudVideoPlayer] Live stream failed to resume after ".concat((maxMonitorMs / 1e3).toFixed(0), "s (t=").concat(currentTime.toFixed(2), "s, buffered=").concat(bufferedAhead.toFixed(2), "s)"));
2524
2554
  }
2525
2555
  return;
2526
2556
  }
2527
- if (_this.debug) {
2528
- console.warn("[StormcloudVideoPlayer] Content stalled after ad break (t=".concat(currentTime.toFixed(2), "s) — forcing HLS reload at live edge (attempt ").concat(attempt + 1, "/").concat(maxAttempts, ")"));
2529
- }
2530
- var liveSyncPos = _this.host.getLiveSyncPosition();
2531
- var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
2532
- if (liveSyncPos != null && liveSyncPos > currentTime) {
2533
- _this.host.video.currentTime = liveSyncPos;
2534
- }
2535
- _this.host.restartHlsLoad(reloadPos);
2536
- if (_this.host.video.paused) {
2537
- var _this_host_video_play;
2538
- (_this_host_video_play = _this.host.video.play()) === null || _this_host_video_play === void 0 ? void 0 : _this_host_video_play.catch(function() {});
2557
+ var canRecover = wedged && elapsed >= graceMs && Date.now() - lastRecoveryAt >= recoveryCooldownMs && recoveries < maxRecoveries;
2558
+ if (canRecover) {
2559
+ recoveries++;
2560
+ lastRecoveryAt = Date.now();
2561
+ var isFinalAttempt = recoveries >= maxRecoveries;
2562
+ if (!isFinalAttempt) {
2563
+ var liveSyncPos = _this.host.getLiveSyncPosition();
2564
+ var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
2565
+ if (_this.debug) {
2566
+ console.warn("[StormcloudVideoPlayer] Content wedged after ad break (t=".concat(currentTime.toFixed(2), "s, buffered=").concat(bufferedAhead.toFixed(2), "s) — restarting HLS load at ").concat(reloadPos.toFixed(2), "s (recovery ").concat(recoveries, "/").concat(maxRecoveries, ")"));
2567
+ }
2568
+ if (liveSyncPos != null && liveSyncPos > currentTime) {
2569
+ video.currentTime = liveSyncPos;
2570
+ }
2571
+ _this.host.restartHlsLoad(reloadPos);
2572
+ } else {
2573
+ if (_this.debug) {
2574
+ console.warn("[StormcloudVideoPlayer] Content still wedged after ad break (t=".concat(currentTime.toFixed(2), "s, buffered=").concat(bufferedAhead.toFixed(2), "s) — hard-reloading live stream (recovery ").concat(recoveries, "/").concat(maxRecoveries, ")"));
2575
+ }
2576
+ _this.host.reloadLiveStream();
2577
+ }
2578
+ baseline = video.currentTime;
2579
+ if (video.paused) {
2580
+ var _video_play1;
2581
+ (_video_play1 = video.play()) === null || _video_play1 === void 0 ? void 0 : _video_play1.catch(function() {});
2582
+ }
2539
2583
  }
2540
- _this.monitorLiveResumeStall(attempt + 1, _this.host.video.currentTime);
2541
- }, checkDelayMs);
2584
+ window.setTimeout(poll, pollIntervalMs);
2585
+ };
2586
+ window.setTimeout(poll, pollIntervalMs);
2542
2587
  }
2543
2588
  },
2544
2589
  {