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.
@@ -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
  }
@@ -6246,6 +6252,7 @@ var HlsEngine = /*#__PURE__*/ function() {
6246
6252
  this.isLiveStream = false;
6247
6253
  this.nativeHlsMode = false;
6248
6254
  this.videoSrcProtection = null;
6255
+ this.reloadingLiveStream = false;
6249
6256
  this.bufferedSegmentsCount = 0;
6250
6257
  this.shouldAutoplayAfterBuffering = false;
6251
6258
  this.hasInitialBufferCompleted = false;
@@ -6379,6 +6386,7 @@ var HlsEngine = /*#__PURE__*/ function() {
6379
6386
  _state.sent();
6380
6387
  _state.label = 3;
6381
6388
  case 3:
6389
+ this.reloadingLiveStream = false;
6382
6390
  return [
6383
6391
  2
6384
6392
  ];
@@ -6723,6 +6731,33 @@ var HlsEngine = /*#__PURE__*/ function() {
6723
6731
  }
6724
6732
  }
6725
6733
  },
6734
+ {
6735
+ key: "reloadLiveStream",
6736
+ value: function reloadLiveStream() {
6737
+ var hls = this.hls;
6738
+ if (!hls) {
6739
+ return;
6740
+ }
6741
+ if (this.debug) {
6742
+ console.log("[StormcloudVideoPlayer] Hard-reloading live stream (detach \u2192 reset video \u2192 re-attach)");
6743
+ }
6744
+ try {
6745
+ this.reloadingLiveStream = true;
6746
+ hls.stopLoad();
6747
+ hls.detachMedia();
6748
+ try {
6749
+ this.video.removeAttribute("src");
6750
+ this.video.load();
6751
+ } catch (unused) {}
6752
+ hls.attachMedia(this.video);
6753
+ } catch (error) {
6754
+ this.reloadingLiveStream = false;
6755
+ if (this.debug) {
6756
+ console.warn("[StormcloudVideoPlayer] Failed to hard-reload live stream:", error);
6757
+ }
6758
+ }
6759
+ }
6760
+ },
6726
6761
  {
6727
6762
  key: "destroy",
6728
6763
  value: function destroy() {
@@ -8042,51 +8077,96 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8042
8077
  this.host.restartHlsLoad(liveSyncPos);
8043
8078
  }
8044
8079
  this.resumeContentPlayback();
8045
- this.monitorLiveResumeStall(0, this.host.video.currentTime);
8080
+ this.monitorLiveResumeStall(this.host.video.currentTime);
8046
8081
  return;
8047
8082
  }
8048
8083
  this.resumeContentPlayback();
8049
8084
  }
8050
8085
  },
8086
+ {
8087
+ key: "getBufferedAhead",
8088
+ value: function getBufferedAhead() {
8089
+ var video = this.host.video;
8090
+ var t = video.currentTime;
8091
+ var ranges = video.buffered;
8092
+ for(var i = 0; i < ranges.length; i++){
8093
+ if (t >= ranges.start(i) - 0.5 && t <= ranges.end(i)) {
8094
+ return ranges.end(i) - t;
8095
+ }
8096
+ }
8097
+ return 0;
8098
+ }
8099
+ },
8051
8100
  {
8052
8101
  key: "monitorLiveResumeStall",
8053
- value: function monitorLiveResumeStall(attempt, lastTime) {
8102
+ value: function monitorLiveResumeStall(resumeBaseline) {
8054
8103
  var _this = this;
8055
- var maxAttempts = 3;
8056
- var checkDelayMs = 2500;
8057
- window.setTimeout(function() {
8104
+ var pollIntervalMs = 1e3;
8105
+ var graceMs = 5e3;
8106
+ var recoveryCooldownMs = 5e3;
8107
+ var maxRecoveries = 2;
8108
+ var maxMonitorMs = 3e4;
8109
+ var startTime = Date.now();
8110
+ var baseline = resumeBaseline;
8111
+ var recoveries = 0;
8112
+ var lastRecoveryAt = 0;
8113
+ var poll = function poll1() {
8058
8114
  if (_this.inAdBreak) {
8059
8115
  return;
8060
8116
  }
8061
- var currentTime = _this.host.video.currentTime;
8062
- var advanced = currentTime > lastTime + 0.25;
8063
- if (advanced && !_this.host.video.paused) {
8117
+ var video = _this.host.video;
8118
+ var currentTime = video.currentTime;
8119
+ var advanced = currentTime > baseline + 0.5;
8120
+ var playing = !video.paused && video.readyState >= 3;
8121
+ if (advanced && playing) {
8064
8122
  if (_this.debug) {
8065
8123
  console.log("[StormcloudVideoPlayer] Live stream resumed successfully after ad break");
8066
8124
  }
8067
8125
  return;
8068
8126
  }
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)"));
8127
+ if (video.paused) {
8128
+ var _video_play;
8129
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
8130
+ }
8131
+ var elapsed = Date.now() - startTime;
8132
+ var bufferedAhead = _this.getBufferedAhead();
8133
+ var wedged = bufferedAhead < 0.5 && !advanced;
8134
+ if (elapsed >= maxMonitorMs) {
8135
+ if (_this.debug && !advanced) {
8136
+ 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
8137
  }
8073
8138
  return;
8074
8139
  }
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() {});
8140
+ var canRecover = wedged && elapsed >= graceMs && Date.now() - lastRecoveryAt >= recoveryCooldownMs && recoveries < maxRecoveries;
8141
+ if (canRecover) {
8142
+ recoveries++;
8143
+ lastRecoveryAt = Date.now();
8144
+ var isFinalAttempt = recoveries >= maxRecoveries;
8145
+ if (!isFinalAttempt) {
8146
+ var liveSyncPos = _this.host.getLiveSyncPosition();
8147
+ var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8148
+ if (_this.debug) {
8149
+ 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, ")"));
8150
+ }
8151
+ if (liveSyncPos != null && liveSyncPos > currentTime) {
8152
+ video.currentTime = liveSyncPos;
8153
+ }
8154
+ _this.host.restartHlsLoad(reloadPos);
8155
+ } else {
8156
+ if (_this.debug) {
8157
+ 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, ")"));
8158
+ }
8159
+ _this.host.reloadLiveStream();
8160
+ }
8161
+ baseline = video.currentTime;
8162
+ if (video.paused) {
8163
+ var _video_play1;
8164
+ (_video_play1 = video.play()) === null || _video_play1 === void 0 ? void 0 : _video_play1.catch(function() {});
8165
+ }
8087
8166
  }
8088
- _this.monitorLiveResumeStall(attempt + 1, _this.host.video.currentTime);
8089
- }, checkDelayMs);
8167
+ window.setTimeout(poll, pollIntervalMs);
8168
+ };
8169
+ window.setTimeout(poll, pollIntervalMs);
8090
8170
  }
8091
8171
  },
8092
8172
  {
@@ -8240,6 +8320,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8240
8320
  restartHlsLoad: function restartHlsLoad(position) {
8241
8321
  return _this.hlsEngine.restartLoadAt(position);
8242
8322
  },
8323
+ reloadLiveStream: function reloadLiveStream() {
8324
+ return _this.hlsEngine.reloadLiveStream();
8325
+ },
8243
8326
  generatePodVastUrl: function generatePodVastUrl(base, breakDurationMs) {
8244
8327
  return _this.generatePodVastUrl(base, breakDurationMs);
8245
8328
  }
@@ -8371,6 +8454,14 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8371
8454
  return _async_to_generator(function() {
8372
8455
  var prerollKey, adBehavior;
8373
8456
  return _ts_generator(this, function(_state) {
8457
+ if (this.hlsEngine.reloadingLiveStream) {
8458
+ if (this.debug) {
8459
+ console.log("[StormcloudVideoPlayer] Manifest re-parsed after hard reload \u2014 skipping ad-player setup");
8460
+ }
8461
+ return [
8462
+ 2
8463
+ ];
8464
+ }
8374
8465
  if (!this.adConfig.isVmapEnabled() && !isLive && this.adConfig.vmapBreaks.length === 0 && this.adConfig.apiVastTagUrl) {
8375
8466
  prerollKey = "synthetic-vod-preroll";
8376
8467
  if (!this.adConfig.consumedVmapBreakIds.has(prerollKey)) {