stormcloud-video-player 0.8.42 → 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.
@@ -6288,6 +6288,7 @@ var HlsEngine = /*#__PURE__*/ function() {
6288
6288
  this.isLiveStream = false;
6289
6289
  this.nativeHlsMode = false;
6290
6290
  this.videoSrcProtection = null;
6291
+ this.reloadingLiveStream = false;
6291
6292
  this.bufferedSegmentsCount = 0;
6292
6293
  this.shouldAutoplayAfterBuffering = false;
6293
6294
  this.hasInitialBufferCompleted = false;
@@ -6421,6 +6422,7 @@ var HlsEngine = /*#__PURE__*/ function() {
6421
6422
  _state.sent();
6422
6423
  _state.label = 3;
6423
6424
  case 3:
6425
+ this.reloadingLiveStream = false;
6424
6426
  return [
6425
6427
  2
6426
6428
  ];
@@ -6765,6 +6767,33 @@ var HlsEngine = /*#__PURE__*/ function() {
6765
6767
  }
6766
6768
  }
6767
6769
  },
6770
+ {
6771
+ key: "reloadLiveStream",
6772
+ value: function reloadLiveStream() {
6773
+ var hls = this.hls;
6774
+ if (!hls) {
6775
+ return;
6776
+ }
6777
+ if (this.debug) {
6778
+ console.log("[StormcloudVideoPlayer] Hard-reloading live stream (detach \u2192 reset video \u2192 re-attach)");
6779
+ }
6780
+ try {
6781
+ this.reloadingLiveStream = true;
6782
+ hls.stopLoad();
6783
+ hls.detachMedia();
6784
+ try {
6785
+ this.video.removeAttribute("src");
6786
+ this.video.load();
6787
+ } catch (unused) {}
6788
+ hls.attachMedia(this.video);
6789
+ } catch (error) {
6790
+ this.reloadingLiveStream = false;
6791
+ if (this.debug) {
6792
+ console.warn("[StormcloudVideoPlayer] Failed to hard-reload live stream:", error);
6793
+ }
6794
+ }
6795
+ }
6796
+ },
6768
6797
  {
6769
6798
  key: "destroy",
6770
6799
  value: function destroy() {
@@ -8110,13 +8139,13 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8110
8139
  var _this = this;
8111
8140
  var pollIntervalMs = 1e3;
8112
8141
  var graceMs = 5e3;
8113
- var reloadCooldownMs = 5e3;
8114
- var maxHardReloads = 2;
8115
- var maxMonitorMs = 25e3;
8142
+ var recoveryCooldownMs = 5e3;
8143
+ var maxRecoveries = 2;
8144
+ var maxMonitorMs = 3e4;
8116
8145
  var startTime = Date.now();
8117
8146
  var baseline = resumeBaseline;
8118
- var hardReloads = 0;
8119
- var lastReloadAt = 0;
8147
+ var recoveries = 0;
8148
+ var lastRecoveryAt = 0;
8120
8149
  var poll = function poll1() {
8121
8150
  if (_this.inAdBreak) {
8122
8151
  return;
@@ -8144,19 +8173,27 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8144
8173
  }
8145
8174
  return;
8146
8175
  }
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;
8176
+ var canRecover = wedged && elapsed >= graceMs && Date.now() - lastRecoveryAt >= recoveryCooldownMs && recoveries < maxRecoveries;
8177
+ if (canRecover) {
8178
+ recoveries++;
8179
+ lastRecoveryAt = Date.now();
8180
+ var isFinalAttempt = recoveries >= maxRecoveries;
8181
+ if (!isFinalAttempt) {
8182
+ var liveSyncPos = _this.host.getLiveSyncPosition();
8183
+ var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8184
+ if (_this.debug) {
8185
+ 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, ")"));
8186
+ }
8187
+ if (liveSyncPos != null && liveSyncPos > currentTime) {
8188
+ video.currentTime = liveSyncPos;
8189
+ }
8190
+ _this.host.restartHlsLoad(reloadPos);
8191
+ } else {
8192
+ if (_this.debug) {
8193
+ 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, ")"));
8194
+ }
8195
+ _this.host.reloadLiveStream();
8158
8196
  }
8159
- _this.host.restartHlsLoad(reloadPos);
8160
8197
  baseline = video.currentTime;
8161
8198
  if (video.paused) {
8162
8199
  var _video_play1;
@@ -8319,6 +8356,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8319
8356
  restartHlsLoad: function restartHlsLoad(position) {
8320
8357
  return _this.hlsEngine.restartLoadAt(position);
8321
8358
  },
8359
+ reloadLiveStream: function reloadLiveStream() {
8360
+ return _this.hlsEngine.reloadLiveStream();
8361
+ },
8322
8362
  generatePodVastUrl: function generatePodVastUrl(base, breakDurationMs) {
8323
8363
  return _this.generatePodVastUrl(base, breakDurationMs);
8324
8364
  }
@@ -8450,6 +8490,14 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8450
8490
  return _async_to_generator(function() {
8451
8491
  var prerollKey, adBehavior;
8452
8492
  return _ts_generator(this, function(_state) {
8493
+ if (this.hlsEngine.reloadingLiveStream) {
8494
+ if (this.debug) {
8495
+ console.log("[StormcloudVideoPlayer] Manifest re-parsed after hard reload \u2014 skipping ad-player setup");
8496
+ }
8497
+ return [
8498
+ 2
8499
+ ];
8500
+ }
8453
8501
  if (!this.adConfig.isVmapEnabled() && !isLive && this.adConfig.vmapBreaks.length === 0 && this.adConfig.apiVastTagUrl) {
8454
8502
  prerollKey = "synthetic-vod-preroll";
8455
8503
  if (!this.adConfig.consumedVmapBreakIds.has(prerollKey)) {