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.
@@ -1516,7 +1516,10 @@ function createHlsAdPlayer(contentVideo, options) {
1516
1516
  }
1517
1517
  if (adVideoElement) {
1518
1518
  adVideoElement.pause();
1519
- adVideoElement.src = "";
1519
+ adVideoElement.removeAttribute("src");
1520
+ try {
1521
+ adVideoElement.load();
1522
+ } catch (unused) {}
1520
1523
  }
1521
1524
  currentAd = void 0;
1522
1525
  podAds = [];
@@ -1562,7 +1565,10 @@ function createHlsAdPlayer(contentVideo, options) {
1562
1565
  }
1563
1566
  if (adVideoElement) {
1564
1567
  adVideoElement.pause();
1565
- adVideoElement.src = "";
1568
+ adVideoElement.removeAttribute("src");
1569
+ try {
1570
+ adVideoElement.load();
1571
+ } catch (unused) {}
1566
1572
  adVideoElement.remove();
1567
1573
  adVideoElement = void 0;
1568
1574
  }
@@ -8042,51 +8048,88 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8042
8048
  this.host.restartHlsLoad(liveSyncPos);
8043
8049
  }
8044
8050
  this.resumeContentPlayback();
8045
- this.monitorLiveResumeStall(0, this.host.video.currentTime);
8051
+ this.monitorLiveResumeStall(this.host.video.currentTime);
8046
8052
  return;
8047
8053
  }
8048
8054
  this.resumeContentPlayback();
8049
8055
  }
8050
8056
  },
8057
+ {
8058
+ key: "getBufferedAhead",
8059
+ value: function getBufferedAhead() {
8060
+ var video = this.host.video;
8061
+ var t = video.currentTime;
8062
+ var ranges = video.buffered;
8063
+ for(var i = 0; i < ranges.length; i++){
8064
+ if (t >= ranges.start(i) - 0.5 && t <= ranges.end(i)) {
8065
+ return ranges.end(i) - t;
8066
+ }
8067
+ }
8068
+ return 0;
8069
+ }
8070
+ },
8051
8071
  {
8052
8072
  key: "monitorLiveResumeStall",
8053
- value: function monitorLiveResumeStall(attempt, lastTime) {
8073
+ value: function monitorLiveResumeStall(resumeBaseline) {
8054
8074
  var _this = this;
8055
- var maxAttempts = 3;
8056
- var checkDelayMs = 2500;
8057
- window.setTimeout(function() {
8075
+ var pollIntervalMs = 1e3;
8076
+ var graceMs = 5e3;
8077
+ var reloadCooldownMs = 5e3;
8078
+ var maxHardReloads = 2;
8079
+ var maxMonitorMs = 25e3;
8080
+ var startTime = Date.now();
8081
+ var baseline = resumeBaseline;
8082
+ var hardReloads = 0;
8083
+ var lastReloadAt = 0;
8084
+ var poll = function poll1() {
8058
8085
  if (_this.inAdBreak) {
8059
8086
  return;
8060
8087
  }
8061
- var currentTime = _this.host.video.currentTime;
8062
- var advanced = currentTime > lastTime + 0.25;
8063
- if (advanced && !_this.host.video.paused) {
8088
+ var video = _this.host.video;
8089
+ var currentTime = video.currentTime;
8090
+ var advanced = currentTime > baseline + 0.5;
8091
+ var playing = !video.paused && video.readyState >= 3;
8092
+ if (advanced && playing) {
8064
8093
  if (_this.debug) {
8065
8094
  console.log("[StormcloudVideoPlayer] Live stream resumed successfully after ad break");
8066
8095
  }
8067
8096
  return;
8068
8097
  }
8069
- if (attempt >= maxAttempts) {
8070
- if (_this.debug) {
8071
- console.warn("[StormcloudVideoPlayer] Live stream failed to resume after ".concat(maxAttempts, " recovery attempts (t=").concat(currentTime.toFixed(2), "s)"));
8098
+ if (video.paused) {
8099
+ var _video_play;
8100
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
8101
+ }
8102
+ var elapsed = Date.now() - startTime;
8103
+ var bufferedAhead = _this.getBufferedAhead();
8104
+ var wedged = bufferedAhead < 0.5 && !advanced;
8105
+ if (elapsed >= maxMonitorMs) {
8106
+ if (_this.debug && !advanced) {
8107
+ 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)"));
8072
8108
  }
8073
8109
  return;
8074
8110
  }
8075
- if (_this.debug) {
8076
- 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, ")"));
8077
- }
8078
- var liveSyncPos = _this.host.getLiveSyncPosition();
8079
- var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8080
- if (liveSyncPos != null && liveSyncPos > currentTime) {
8081
- _this.host.video.currentTime = liveSyncPos;
8082
- }
8083
- _this.host.restartHlsLoad(reloadPos);
8084
- if (_this.host.video.paused) {
8085
- var _this_host_video_play;
8086
- (_this_host_video_play = _this.host.video.play()) === null || _this_host_video_play === void 0 ? void 0 : _this_host_video_play.catch(function() {});
8111
+ var canHardReload = wedged && elapsed >= graceMs && Date.now() - lastReloadAt >= reloadCooldownMs && hardReloads < maxHardReloads;
8112
+ if (canHardReload) {
8113
+ hardReloads++;
8114
+ lastReloadAt = Date.now();
8115
+ var liveSyncPos = _this.host.getLiveSyncPosition();
8116
+ var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8117
+ if (_this.debug) {
8118
+ 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, ")"));
8119
+ }
8120
+ if (liveSyncPos != null && liveSyncPos > currentTime) {
8121
+ video.currentTime = liveSyncPos;
8122
+ }
8123
+ _this.host.restartHlsLoad(reloadPos);
8124
+ baseline = video.currentTime;
8125
+ if (video.paused) {
8126
+ var _video_play1;
8127
+ (_video_play1 = video.play()) === null || _video_play1 === void 0 ? void 0 : _video_play1.catch(function() {});
8128
+ }
8087
8129
  }
8088
- _this.monitorLiveResumeStall(attempt + 1, _this.host.video.currentTime);
8089
- }, checkDelayMs);
8130
+ window.setTimeout(poll, pollIntervalMs);
8131
+ };
8132
+ window.setTimeout(poll, pollIntervalMs);
8090
8133
  }
8091
8134
  },
8092
8135
  {