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.
package/lib/index.js CHANGED
@@ -1486,7 +1486,10 @@ function createHlsAdPlayer(contentVideo, options) {
1486
1486
  }
1487
1487
  if (adVideoElement) {
1488
1488
  adVideoElement.pause();
1489
- adVideoElement.src = "";
1489
+ adVideoElement.removeAttribute("src");
1490
+ try {
1491
+ adVideoElement.load();
1492
+ } catch (unused) {}
1490
1493
  }
1491
1494
  currentAd = void 0;
1492
1495
  podAds = [];
@@ -1532,7 +1535,10 @@ function createHlsAdPlayer(contentVideo, options) {
1532
1535
  }
1533
1536
  if (adVideoElement) {
1534
1537
  adVideoElement.pause();
1535
- adVideoElement.src = "";
1538
+ adVideoElement.removeAttribute("src");
1539
+ try {
1540
+ adVideoElement.load();
1541
+ } catch (unused) {}
1536
1542
  adVideoElement.remove();
1537
1543
  adVideoElement = void 0;
1538
1544
  }
@@ -8065,51 +8071,88 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8065
8071
  this.host.restartHlsLoad(liveSyncPos);
8066
8072
  }
8067
8073
  this.resumeContentPlayback();
8068
- this.monitorLiveResumeStall(0, this.host.video.currentTime);
8074
+ this.monitorLiveResumeStall(this.host.video.currentTime);
8069
8075
  return;
8070
8076
  }
8071
8077
  this.resumeContentPlayback();
8072
8078
  }
8073
8079
  },
8080
+ {
8081
+ key: "getBufferedAhead",
8082
+ value: function getBufferedAhead() {
8083
+ var video = this.host.video;
8084
+ var t = video.currentTime;
8085
+ var ranges = video.buffered;
8086
+ for(var i = 0; i < ranges.length; i++){
8087
+ if (t >= ranges.start(i) - 0.5 && t <= ranges.end(i)) {
8088
+ return ranges.end(i) - t;
8089
+ }
8090
+ }
8091
+ return 0;
8092
+ }
8093
+ },
8074
8094
  {
8075
8095
  key: "monitorLiveResumeStall",
8076
- value: function monitorLiveResumeStall(attempt, lastTime) {
8096
+ value: function monitorLiveResumeStall(resumeBaseline) {
8077
8097
  var _this = this;
8078
- var maxAttempts = 3;
8079
- var checkDelayMs = 2500;
8080
- window.setTimeout(function() {
8098
+ var pollIntervalMs = 1e3;
8099
+ var graceMs = 5e3;
8100
+ var reloadCooldownMs = 5e3;
8101
+ var maxHardReloads = 2;
8102
+ var maxMonitorMs = 25e3;
8103
+ var startTime = Date.now();
8104
+ var baseline = resumeBaseline;
8105
+ var hardReloads = 0;
8106
+ var lastReloadAt = 0;
8107
+ var poll = function poll1() {
8081
8108
  if (_this.inAdBreak) {
8082
8109
  return;
8083
8110
  }
8084
- var currentTime = _this.host.video.currentTime;
8085
- var advanced = currentTime > lastTime + 0.25;
8086
- if (advanced && !_this.host.video.paused) {
8111
+ var video = _this.host.video;
8112
+ var currentTime = video.currentTime;
8113
+ var advanced = currentTime > baseline + 0.5;
8114
+ var playing = !video.paused && video.readyState >= 3;
8115
+ if (advanced && playing) {
8087
8116
  if (_this.debug) {
8088
8117
  console.log("[StormcloudVideoPlayer] Live stream resumed successfully after ad break");
8089
8118
  }
8090
8119
  return;
8091
8120
  }
8092
- if (attempt >= maxAttempts) {
8093
- if (_this.debug) {
8094
- console.warn("[StormcloudVideoPlayer] Live stream failed to resume after ".concat(maxAttempts, " recovery attempts (t=").concat(currentTime.toFixed(2), "s)"));
8121
+ if (video.paused) {
8122
+ var _video_play;
8123
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
8124
+ }
8125
+ var elapsed = Date.now() - startTime;
8126
+ var bufferedAhead = _this.getBufferedAhead();
8127
+ var wedged = bufferedAhead < 0.5 && !advanced;
8128
+ if (elapsed >= maxMonitorMs) {
8129
+ if (_this.debug && !advanced) {
8130
+ 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)"));
8095
8131
  }
8096
8132
  return;
8097
8133
  }
8098
- if (_this.debug) {
8099
- 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, ")"));
8100
- }
8101
- var liveSyncPos = _this.host.getLiveSyncPosition();
8102
- var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8103
- if (liveSyncPos != null && liveSyncPos > currentTime) {
8104
- _this.host.video.currentTime = liveSyncPos;
8105
- }
8106
- _this.host.restartHlsLoad(reloadPos);
8107
- if (_this.host.video.paused) {
8108
- var _this_host_video_play;
8109
- (_this_host_video_play = _this.host.video.play()) === null || _this_host_video_play === void 0 ? void 0 : _this_host_video_play.catch(function() {});
8134
+ var canHardReload = wedged && elapsed >= graceMs && Date.now() - lastReloadAt >= reloadCooldownMs && hardReloads < maxHardReloads;
8135
+ if (canHardReload) {
8136
+ hardReloads++;
8137
+ lastReloadAt = Date.now();
8138
+ var liveSyncPos = _this.host.getLiveSyncPosition();
8139
+ var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8140
+ if (_this.debug) {
8141
+ 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, ")"));
8142
+ }
8143
+ if (liveSyncPos != null && liveSyncPos > currentTime) {
8144
+ video.currentTime = liveSyncPos;
8145
+ }
8146
+ _this.host.restartHlsLoad(reloadPos);
8147
+ baseline = video.currentTime;
8148
+ if (video.paused) {
8149
+ var _video_play1;
8150
+ (_video_play1 = video.play()) === null || _video_play1 === void 0 ? void 0 : _video_play1.catch(function() {});
8151
+ }
8110
8152
  }
8111
- _this.monitorLiveResumeStall(attempt + 1, _this.host.video.currentTime);
8112
- }, checkDelayMs);
8153
+ window.setTimeout(poll, pollIntervalMs);
8154
+ };
8155
+ window.setTimeout(poll, pollIntervalMs);
8113
8156
  }
8114
8157
  },
8115
8158
  {