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.
@@ -1552,7 +1552,10 @@ function createHlsAdPlayer(contentVideo, options) {
1552
1552
  }
1553
1553
  if (adVideoElement) {
1554
1554
  adVideoElement.pause();
1555
- adVideoElement.src = "";
1555
+ adVideoElement.removeAttribute("src");
1556
+ try {
1557
+ adVideoElement.load();
1558
+ } catch (unused) {}
1556
1559
  }
1557
1560
  currentAd = void 0;
1558
1561
  podAds = [];
@@ -1598,7 +1601,10 @@ function createHlsAdPlayer(contentVideo, options) {
1598
1601
  }
1599
1602
  if (adVideoElement) {
1600
1603
  adVideoElement.pause();
1601
- adVideoElement.src = "";
1604
+ adVideoElement.removeAttribute("src");
1605
+ try {
1606
+ adVideoElement.load();
1607
+ } catch (unused) {}
1602
1608
  adVideoElement.remove();
1603
1609
  adVideoElement = void 0;
1604
1610
  }
@@ -8078,51 +8084,88 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8078
8084
  this.host.restartHlsLoad(liveSyncPos);
8079
8085
  }
8080
8086
  this.resumeContentPlayback();
8081
- this.monitorLiveResumeStall(0, this.host.video.currentTime);
8087
+ this.monitorLiveResumeStall(this.host.video.currentTime);
8082
8088
  return;
8083
8089
  }
8084
8090
  this.resumeContentPlayback();
8085
8091
  }
8086
8092
  },
8093
+ {
8094
+ key: "getBufferedAhead",
8095
+ value: function getBufferedAhead() {
8096
+ var video = this.host.video;
8097
+ var t = video.currentTime;
8098
+ var ranges = video.buffered;
8099
+ for(var i = 0; i < ranges.length; i++){
8100
+ if (t >= ranges.start(i) - 0.5 && t <= ranges.end(i)) {
8101
+ return ranges.end(i) - t;
8102
+ }
8103
+ }
8104
+ return 0;
8105
+ }
8106
+ },
8087
8107
  {
8088
8108
  key: "monitorLiveResumeStall",
8089
- value: function monitorLiveResumeStall(attempt, lastTime) {
8109
+ value: function monitorLiveResumeStall(resumeBaseline) {
8090
8110
  var _this = this;
8091
- var maxAttempts = 3;
8092
- var checkDelayMs = 2500;
8093
- window.setTimeout(function() {
8111
+ var pollIntervalMs = 1e3;
8112
+ var graceMs = 5e3;
8113
+ var reloadCooldownMs = 5e3;
8114
+ var maxHardReloads = 2;
8115
+ var maxMonitorMs = 25e3;
8116
+ var startTime = Date.now();
8117
+ var baseline = resumeBaseline;
8118
+ var hardReloads = 0;
8119
+ var lastReloadAt = 0;
8120
+ var poll = function poll1() {
8094
8121
  if (_this.inAdBreak) {
8095
8122
  return;
8096
8123
  }
8097
- var currentTime = _this.host.video.currentTime;
8098
- var advanced = currentTime > lastTime + 0.25;
8099
- if (advanced && !_this.host.video.paused) {
8124
+ var video = _this.host.video;
8125
+ var currentTime = video.currentTime;
8126
+ var advanced = currentTime > baseline + 0.5;
8127
+ var playing = !video.paused && video.readyState >= 3;
8128
+ if (advanced && playing) {
8100
8129
  if (_this.debug) {
8101
8130
  console.log("[StormcloudVideoPlayer] Live stream resumed successfully after ad break");
8102
8131
  }
8103
8132
  return;
8104
8133
  }
8105
- if (attempt >= maxAttempts) {
8106
- if (_this.debug) {
8107
- console.warn("[StormcloudVideoPlayer] Live stream failed to resume after ".concat(maxAttempts, " recovery attempts (t=").concat(currentTime.toFixed(2), "s)"));
8134
+ if (video.paused) {
8135
+ var _video_play;
8136
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
8137
+ }
8138
+ var elapsed = Date.now() - startTime;
8139
+ var bufferedAhead = _this.getBufferedAhead();
8140
+ var wedged = bufferedAhead < 0.5 && !advanced;
8141
+ if (elapsed >= maxMonitorMs) {
8142
+ if (_this.debug && !advanced) {
8143
+ 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)"));
8108
8144
  }
8109
8145
  return;
8110
8146
  }
8111
- if (_this.debug) {
8112
- 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, ")"));
8113
- }
8114
- var liveSyncPos = _this.host.getLiveSyncPosition();
8115
- var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8116
- if (liveSyncPos != null && liveSyncPos > currentTime) {
8117
- _this.host.video.currentTime = liveSyncPos;
8118
- }
8119
- _this.host.restartHlsLoad(reloadPos);
8120
- if (_this.host.video.paused) {
8121
- var _this_host_video_play;
8122
- (_this_host_video_play = _this.host.video.play()) === null || _this_host_video_play === void 0 ? void 0 : _this_host_video_play.catch(function() {});
8147
+ var canHardReload = wedged && elapsed >= graceMs && Date.now() - lastReloadAt >= reloadCooldownMs && hardReloads < maxHardReloads;
8148
+ if (canHardReload) {
8149
+ hardReloads++;
8150
+ lastReloadAt = Date.now();
8151
+ var liveSyncPos = _this.host.getLiveSyncPosition();
8152
+ var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8153
+ if (_this.debug) {
8154
+ 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, ")"));
8155
+ }
8156
+ if (liveSyncPos != null && liveSyncPos > currentTime) {
8157
+ video.currentTime = liveSyncPos;
8158
+ }
8159
+ _this.host.restartHlsLoad(reloadPos);
8160
+ baseline = video.currentTime;
8161
+ if (video.paused) {
8162
+ var _video_play1;
8163
+ (_video_play1 = video.play()) === null || _video_play1 === void 0 ? void 0 : _video_play1.catch(function() {});
8164
+ }
8123
8165
  }
8124
- _this.monitorLiveResumeStall(attempt + 1, _this.host.video.currentTime);
8125
- }, checkDelayMs);
8166
+ window.setTimeout(poll, pollIntervalMs);
8167
+ };
8168
+ window.setTimeout(poll, pollIntervalMs);
8126
8169
  }
8127
8170
  },
8128
8171
  {