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.
@@ -1502,7 +1502,10 @@ function createHlsAdPlayer(contentVideo, options) {
1502
1502
  }
1503
1503
  if (adVideoElement) {
1504
1504
  adVideoElement.pause();
1505
- adVideoElement.src = "";
1505
+ adVideoElement.removeAttribute("src");
1506
+ try {
1507
+ adVideoElement.load();
1508
+ } catch (unused) {}
1506
1509
  }
1507
1510
  currentAd = void 0;
1508
1511
  podAds = [];
@@ -1548,7 +1551,10 @@ function createHlsAdPlayer(contentVideo, options) {
1548
1551
  }
1549
1552
  if (adVideoElement) {
1550
1553
  adVideoElement.pause();
1551
- adVideoElement.src = "";
1554
+ adVideoElement.removeAttribute("src");
1555
+ try {
1556
+ adVideoElement.load();
1557
+ } catch (unused) {}
1552
1558
  adVideoElement.remove();
1553
1559
  adVideoElement = void 0;
1554
1560
  }
@@ -6232,6 +6238,7 @@ var HlsEngine = /*#__PURE__*/ function() {
6232
6238
  this.isLiveStream = false;
6233
6239
  this.nativeHlsMode = false;
6234
6240
  this.videoSrcProtection = null;
6241
+ this.reloadingLiveStream = false;
6235
6242
  this.bufferedSegmentsCount = 0;
6236
6243
  this.shouldAutoplayAfterBuffering = false;
6237
6244
  this.hasInitialBufferCompleted = false;
@@ -6365,6 +6372,7 @@ var HlsEngine = /*#__PURE__*/ function() {
6365
6372
  _state.sent();
6366
6373
  _state.label = 3;
6367
6374
  case 3:
6375
+ this.reloadingLiveStream = false;
6368
6376
  return [
6369
6377
  2
6370
6378
  ];
@@ -6709,6 +6717,33 @@ var HlsEngine = /*#__PURE__*/ function() {
6709
6717
  }
6710
6718
  }
6711
6719
  },
6720
+ {
6721
+ key: "reloadLiveStream",
6722
+ value: function reloadLiveStream() {
6723
+ var hls = this.hls;
6724
+ if (!hls) {
6725
+ return;
6726
+ }
6727
+ if (this.debug) {
6728
+ console.log("[StormcloudVideoPlayer] Hard-reloading live stream (detach \u2192 reset video \u2192 re-attach)");
6729
+ }
6730
+ try {
6731
+ this.reloadingLiveStream = true;
6732
+ hls.stopLoad();
6733
+ hls.detachMedia();
6734
+ try {
6735
+ this.video.removeAttribute("src");
6736
+ this.video.load();
6737
+ } catch (unused) {}
6738
+ hls.attachMedia(this.video);
6739
+ } catch (error) {
6740
+ this.reloadingLiveStream = false;
6741
+ if (this.debug) {
6742
+ console.warn("[StormcloudVideoPlayer] Failed to hard-reload live stream:", error);
6743
+ }
6744
+ }
6745
+ }
6746
+ },
6712
6747
  {
6713
6748
  key: "destroy",
6714
6749
  value: function destroy() {
@@ -8028,51 +8063,96 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8028
8063
  this.host.restartHlsLoad(liveSyncPos);
8029
8064
  }
8030
8065
  this.resumeContentPlayback();
8031
- this.monitorLiveResumeStall(0, this.host.video.currentTime);
8066
+ this.monitorLiveResumeStall(this.host.video.currentTime);
8032
8067
  return;
8033
8068
  }
8034
8069
  this.resumeContentPlayback();
8035
8070
  }
8036
8071
  },
8072
+ {
8073
+ key: "getBufferedAhead",
8074
+ value: function getBufferedAhead() {
8075
+ var video = this.host.video;
8076
+ var t = video.currentTime;
8077
+ var ranges = video.buffered;
8078
+ for(var i = 0; i < ranges.length; i++){
8079
+ if (t >= ranges.start(i) - 0.5 && t <= ranges.end(i)) {
8080
+ return ranges.end(i) - t;
8081
+ }
8082
+ }
8083
+ return 0;
8084
+ }
8085
+ },
8037
8086
  {
8038
8087
  key: "monitorLiveResumeStall",
8039
- value: function monitorLiveResumeStall(attempt, lastTime) {
8088
+ value: function monitorLiveResumeStall(resumeBaseline) {
8040
8089
  var _this = this;
8041
- var maxAttempts = 3;
8042
- var checkDelayMs = 2500;
8043
- window.setTimeout(function() {
8090
+ var pollIntervalMs = 1e3;
8091
+ var graceMs = 5e3;
8092
+ var recoveryCooldownMs = 5e3;
8093
+ var maxRecoveries = 2;
8094
+ var maxMonitorMs = 3e4;
8095
+ var startTime = Date.now();
8096
+ var baseline = resumeBaseline;
8097
+ var recoveries = 0;
8098
+ var lastRecoveryAt = 0;
8099
+ var poll = function poll1() {
8044
8100
  if (_this.inAdBreak) {
8045
8101
  return;
8046
8102
  }
8047
- var currentTime = _this.host.video.currentTime;
8048
- var advanced = currentTime > lastTime + 0.25;
8049
- if (advanced && !_this.host.video.paused) {
8103
+ var video = _this.host.video;
8104
+ var currentTime = video.currentTime;
8105
+ var advanced = currentTime > baseline + 0.5;
8106
+ var playing = !video.paused && video.readyState >= 3;
8107
+ if (advanced && playing) {
8050
8108
  if (_this.debug) {
8051
8109
  console.log("[StormcloudVideoPlayer] Live stream resumed successfully after ad break");
8052
8110
  }
8053
8111
  return;
8054
8112
  }
8055
- if (attempt >= maxAttempts) {
8056
- if (_this.debug) {
8057
- console.warn("[StormcloudVideoPlayer] Live stream failed to resume after ".concat(maxAttempts, " recovery attempts (t=").concat(currentTime.toFixed(2), "s)"));
8113
+ if (video.paused) {
8114
+ var _video_play;
8115
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
8116
+ }
8117
+ var elapsed = Date.now() - startTime;
8118
+ var bufferedAhead = _this.getBufferedAhead();
8119
+ var wedged = bufferedAhead < 0.5 && !advanced;
8120
+ if (elapsed >= maxMonitorMs) {
8121
+ if (_this.debug && !advanced) {
8122
+ 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)"));
8058
8123
  }
8059
8124
  return;
8060
8125
  }
8061
- if (_this.debug) {
8062
- 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, ")"));
8063
- }
8064
- var liveSyncPos = _this.host.getLiveSyncPosition();
8065
- var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8066
- if (liveSyncPos != null && liveSyncPos > currentTime) {
8067
- _this.host.video.currentTime = liveSyncPos;
8068
- }
8069
- _this.host.restartHlsLoad(reloadPos);
8070
- if (_this.host.video.paused) {
8071
- var _this_host_video_play;
8072
- (_this_host_video_play = _this.host.video.play()) === null || _this_host_video_play === void 0 ? void 0 : _this_host_video_play.catch(function() {});
8126
+ var canRecover = wedged && elapsed >= graceMs && Date.now() - lastRecoveryAt >= recoveryCooldownMs && recoveries < maxRecoveries;
8127
+ if (canRecover) {
8128
+ recoveries++;
8129
+ lastRecoveryAt = Date.now();
8130
+ var isFinalAttempt = recoveries >= maxRecoveries;
8131
+ if (!isFinalAttempt) {
8132
+ var liveSyncPos = _this.host.getLiveSyncPosition();
8133
+ var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8134
+ if (_this.debug) {
8135
+ 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, ")"));
8136
+ }
8137
+ if (liveSyncPos != null && liveSyncPos > currentTime) {
8138
+ video.currentTime = liveSyncPos;
8139
+ }
8140
+ _this.host.restartHlsLoad(reloadPos);
8141
+ } else {
8142
+ if (_this.debug) {
8143
+ 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, ")"));
8144
+ }
8145
+ _this.host.reloadLiveStream();
8146
+ }
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
+ }
8073
8152
  }
8074
- _this.monitorLiveResumeStall(attempt + 1, _this.host.video.currentTime);
8075
- }, checkDelayMs);
8153
+ window.setTimeout(poll, pollIntervalMs);
8154
+ };
8155
+ window.setTimeout(poll, pollIntervalMs);
8076
8156
  }
8077
8157
  },
8078
8158
  {
@@ -8226,6 +8306,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8226
8306
  restartHlsLoad: function restartHlsLoad(position) {
8227
8307
  return _this.hlsEngine.restartLoadAt(position);
8228
8308
  },
8309
+ reloadLiveStream: function reloadLiveStream() {
8310
+ return _this.hlsEngine.reloadLiveStream();
8311
+ },
8229
8312
  generatePodVastUrl: function generatePodVastUrl(base, breakDurationMs) {
8230
8313
  return _this.generatePodVastUrl(base, breakDurationMs);
8231
8314
  }
@@ -8357,6 +8440,14 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8357
8440
  return _async_to_generator(function() {
8358
8441
  var prerollKey, adBehavior;
8359
8442
  return _ts_generator(this, function(_state) {
8443
+ if (this.hlsEngine.reloadingLiveStream) {
8444
+ if (this.debug) {
8445
+ console.log("[StormcloudVideoPlayer] Manifest re-parsed after hard reload \u2014 skipping ad-player setup");
8446
+ }
8447
+ return [
8448
+ 2
8449
+ ];
8450
+ }
8360
8451
  if (!this.adConfig.isVmapEnabled() && !isLive && this.adConfig.vmapBreaks.length === 0 && this.adConfig.apiVastTagUrl) {
8361
8452
  prerollKey = "synthetic-vod-preroll";
8362
8453
  if (!this.adConfig.consumedVmapBreakIds.has(prerollKey)) {