stormcloud-video-player 0.8.41 → 0.8.42

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 @@ declare class AdBreakOrchestrator {
59
59
  playSingleAd(vastTagUrl: string): Promise<void>;
60
60
  private showPlaceholderAndWaitForAds;
61
61
  handleAdPodComplete(): void;
62
+ private getBufferedAhead;
62
63
  private monitorLiveResumeStall;
63
64
  private resumeContentPlayback;
64
65
  handleAdFailure(): void;
@@ -1465,7 +1465,10 @@ function createHlsAdPlayer(contentVideo, options) {
1465
1465
  }
1466
1466
  if (adVideoElement) {
1467
1467
  adVideoElement.pause();
1468
- adVideoElement.src = "";
1468
+ adVideoElement.removeAttribute("src");
1469
+ try {
1470
+ adVideoElement.load();
1471
+ } catch (unused) {}
1469
1472
  }
1470
1473
  currentAd = void 0;
1471
1474
  podAds = [];
@@ -1511,7 +1514,10 @@ function createHlsAdPlayer(contentVideo, options) {
1511
1514
  }
1512
1515
  if (adVideoElement) {
1513
1516
  adVideoElement.pause();
1514
- adVideoElement.src = "";
1517
+ adVideoElement.removeAttribute("src");
1518
+ try {
1519
+ adVideoElement.load();
1520
+ } catch (unused) {}
1515
1521
  adVideoElement.remove();
1516
1522
  adVideoElement = void 0;
1517
1523
  }
@@ -7991,51 +7997,88 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
7991
7997
  this.host.restartHlsLoad(liveSyncPos);
7992
7998
  }
7993
7999
  this.resumeContentPlayback();
7994
- this.monitorLiveResumeStall(0, this.host.video.currentTime);
8000
+ this.monitorLiveResumeStall(this.host.video.currentTime);
7995
8001
  return;
7996
8002
  }
7997
8003
  this.resumeContentPlayback();
7998
8004
  }
7999
8005
  },
8006
+ {
8007
+ key: "getBufferedAhead",
8008
+ value: function getBufferedAhead() {
8009
+ var video = this.host.video;
8010
+ var t = video.currentTime;
8011
+ var ranges = video.buffered;
8012
+ for(var i = 0; i < ranges.length; i++){
8013
+ if (t >= ranges.start(i) - 0.5 && t <= ranges.end(i)) {
8014
+ return ranges.end(i) - t;
8015
+ }
8016
+ }
8017
+ return 0;
8018
+ }
8019
+ },
8000
8020
  {
8001
8021
  key: "monitorLiveResumeStall",
8002
- value: function monitorLiveResumeStall(attempt, lastTime) {
8022
+ value: function monitorLiveResumeStall(resumeBaseline) {
8003
8023
  var _this = this;
8004
- var maxAttempts = 3;
8005
- var checkDelayMs = 2500;
8006
- window.setTimeout(function() {
8024
+ var pollIntervalMs = 1e3;
8025
+ var graceMs = 5e3;
8026
+ var reloadCooldownMs = 5e3;
8027
+ var maxHardReloads = 2;
8028
+ var maxMonitorMs = 25e3;
8029
+ var startTime = Date.now();
8030
+ var baseline = resumeBaseline;
8031
+ var hardReloads = 0;
8032
+ var lastReloadAt = 0;
8033
+ var poll = function poll1() {
8007
8034
  if (_this.inAdBreak) {
8008
8035
  return;
8009
8036
  }
8010
- var currentTime = _this.host.video.currentTime;
8011
- var advanced = currentTime > lastTime + 0.25;
8012
- if (advanced && !_this.host.video.paused) {
8037
+ var video = _this.host.video;
8038
+ var currentTime = video.currentTime;
8039
+ var advanced = currentTime > baseline + 0.5;
8040
+ var playing = !video.paused && video.readyState >= 3;
8041
+ if (advanced && playing) {
8013
8042
  if (_this.debug) {
8014
8043
  console.log("[StormcloudVideoPlayer] Live stream resumed successfully after ad break");
8015
8044
  }
8016
8045
  return;
8017
8046
  }
8018
- if (attempt >= maxAttempts) {
8019
- if (_this.debug) {
8020
- console.warn("[StormcloudVideoPlayer] Live stream failed to resume after ".concat(maxAttempts, " recovery attempts (t=").concat(currentTime.toFixed(2), "s)"));
8047
+ if (video.paused) {
8048
+ var _video_play;
8049
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
8050
+ }
8051
+ var elapsed = Date.now() - startTime;
8052
+ var bufferedAhead = _this.getBufferedAhead();
8053
+ var wedged = bufferedAhead < 0.5 && !advanced;
8054
+ if (elapsed >= maxMonitorMs) {
8055
+ if (_this.debug && !advanced) {
8056
+ 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)"));
8021
8057
  }
8022
8058
  return;
8023
8059
  }
8024
- if (_this.debug) {
8025
- 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, ")"));
8026
- }
8027
- var liveSyncPos = _this.host.getLiveSyncPosition();
8028
- var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8029
- if (liveSyncPos != null && liveSyncPos > currentTime) {
8030
- _this.host.video.currentTime = liveSyncPos;
8031
- }
8032
- _this.host.restartHlsLoad(reloadPos);
8033
- if (_this.host.video.paused) {
8034
- var _this_host_video_play;
8035
- (_this_host_video_play = _this.host.video.play()) === null || _this_host_video_play === void 0 ? void 0 : _this_host_video_play.catch(function() {});
8060
+ var canHardReload = wedged && elapsed >= graceMs && Date.now() - lastReloadAt >= reloadCooldownMs && hardReloads < maxHardReloads;
8061
+ if (canHardReload) {
8062
+ hardReloads++;
8063
+ lastReloadAt = Date.now();
8064
+ var liveSyncPos = _this.host.getLiveSyncPosition();
8065
+ var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8066
+ if (_this.debug) {
8067
+ console.warn("[StormcloudVideoPlayer] Content wedged after ad break (t=".concat(currentTime.toFixed(2), "s, buffered=").concat(bufferedAhead.toFixed(2), "s) — forcing HLS reload at ").concat(reloadPos.toFixed(2), "s (hard reload ").concat(hardReloads, "/").concat(maxHardReloads, ")"));
8068
+ }
8069
+ if (liveSyncPos != null && liveSyncPos > currentTime) {
8070
+ video.currentTime = liveSyncPos;
8071
+ }
8072
+ _this.host.restartHlsLoad(reloadPos);
8073
+ baseline = video.currentTime;
8074
+ if (video.paused) {
8075
+ var _video_play1;
8076
+ (_video_play1 = video.play()) === null || _video_play1 === void 0 ? void 0 : _video_play1.catch(function() {});
8077
+ }
8036
8078
  }
8037
- _this.monitorLiveResumeStall(attempt + 1, _this.host.video.currentTime);
8038
- }, checkDelayMs);
8079
+ window.setTimeout(poll, pollIntervalMs);
8080
+ };
8081
+ window.setTimeout(poll, pollIntervalMs);
8039
8082
  }
8040
8083
  },
8041
8084
  {