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.
@@ -1465,7 +1465,10 @@ function createHlsAdPlayer(contentVideo, options) {
1465
1465
  }
1466
1466
  if (adVideoElement) {
1467
1467
  adVideoElement.pause();
1468
- adVideoElement.src = "";
1468
+ adVideoElement.removeAttribute("src");
1469
+ try {
1470
+ adVideoElement.load();
1471
+ } catch (unused) {}
1469
1472
  }
1470
1473
  currentAd = void 0;
1471
1474
  podAds = [];
@@ -1511,7 +1514,10 @@ function createHlsAdPlayer(contentVideo, options) {
1511
1514
  }
1512
1515
  if (adVideoElement) {
1513
1516
  adVideoElement.pause();
1514
- adVideoElement.src = "";
1517
+ adVideoElement.removeAttribute("src");
1518
+ try {
1519
+ adVideoElement.load();
1520
+ } catch (unused) {}
1515
1521
  adVideoElement.remove();
1516
1522
  adVideoElement = void 0;
1517
1523
  }
@@ -6195,6 +6201,7 @@ var HlsEngine = /*#__PURE__*/ function() {
6195
6201
  this.isLiveStream = false;
6196
6202
  this.nativeHlsMode = false;
6197
6203
  this.videoSrcProtection = null;
6204
+ this.reloadingLiveStream = false;
6198
6205
  this.bufferedSegmentsCount = 0;
6199
6206
  this.shouldAutoplayAfterBuffering = false;
6200
6207
  this.hasInitialBufferCompleted = false;
@@ -6328,6 +6335,7 @@ var HlsEngine = /*#__PURE__*/ function() {
6328
6335
  _state.sent();
6329
6336
  _state.label = 3;
6330
6337
  case 3:
6338
+ this.reloadingLiveStream = false;
6331
6339
  return [
6332
6340
  2
6333
6341
  ];
@@ -6672,6 +6680,33 @@ var HlsEngine = /*#__PURE__*/ function() {
6672
6680
  }
6673
6681
  }
6674
6682
  },
6683
+ {
6684
+ key: "reloadLiveStream",
6685
+ value: function reloadLiveStream() {
6686
+ var hls = this.hls;
6687
+ if (!hls) {
6688
+ return;
6689
+ }
6690
+ if (this.debug) {
6691
+ console.log("[StormcloudVideoPlayer] Hard-reloading live stream (detach \u2192 reset video \u2192 re-attach)");
6692
+ }
6693
+ try {
6694
+ this.reloadingLiveStream = true;
6695
+ hls.stopLoad();
6696
+ hls.detachMedia();
6697
+ try {
6698
+ this.video.removeAttribute("src");
6699
+ this.video.load();
6700
+ } catch (unused) {}
6701
+ hls.attachMedia(this.video);
6702
+ } catch (error) {
6703
+ this.reloadingLiveStream = false;
6704
+ if (this.debug) {
6705
+ console.warn("[StormcloudVideoPlayer] Failed to hard-reload live stream:", error);
6706
+ }
6707
+ }
6708
+ }
6709
+ },
6675
6710
  {
6676
6711
  key: "destroy",
6677
6712
  value: function destroy() {
@@ -7991,51 +8026,96 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
7991
8026
  this.host.restartHlsLoad(liveSyncPos);
7992
8027
  }
7993
8028
  this.resumeContentPlayback();
7994
- this.monitorLiveResumeStall(0, this.host.video.currentTime);
8029
+ this.monitorLiveResumeStall(this.host.video.currentTime);
7995
8030
  return;
7996
8031
  }
7997
8032
  this.resumeContentPlayback();
7998
8033
  }
7999
8034
  },
8035
+ {
8036
+ key: "getBufferedAhead",
8037
+ value: function getBufferedAhead() {
8038
+ var video = this.host.video;
8039
+ var t = video.currentTime;
8040
+ var ranges = video.buffered;
8041
+ for(var i = 0; i < ranges.length; i++){
8042
+ if (t >= ranges.start(i) - 0.5 && t <= ranges.end(i)) {
8043
+ return ranges.end(i) - t;
8044
+ }
8045
+ }
8046
+ return 0;
8047
+ }
8048
+ },
8000
8049
  {
8001
8050
  key: "monitorLiveResumeStall",
8002
- value: function monitorLiveResumeStall(attempt, lastTime) {
8051
+ value: function monitorLiveResumeStall(resumeBaseline) {
8003
8052
  var _this = this;
8004
- var maxAttempts = 3;
8005
- var checkDelayMs = 2500;
8006
- window.setTimeout(function() {
8053
+ var pollIntervalMs = 1e3;
8054
+ var graceMs = 5e3;
8055
+ var recoveryCooldownMs = 5e3;
8056
+ var maxRecoveries = 2;
8057
+ var maxMonitorMs = 3e4;
8058
+ var startTime = Date.now();
8059
+ var baseline = resumeBaseline;
8060
+ var recoveries = 0;
8061
+ var lastRecoveryAt = 0;
8062
+ var poll = function poll1() {
8007
8063
  if (_this.inAdBreak) {
8008
8064
  return;
8009
8065
  }
8010
- var currentTime = _this.host.video.currentTime;
8011
- var advanced = currentTime > lastTime + 0.25;
8012
- if (advanced && !_this.host.video.paused) {
8066
+ var video = _this.host.video;
8067
+ var currentTime = video.currentTime;
8068
+ var advanced = currentTime > baseline + 0.5;
8069
+ var playing = !video.paused && video.readyState >= 3;
8070
+ if (advanced && playing) {
8013
8071
  if (_this.debug) {
8014
8072
  console.log("[StormcloudVideoPlayer] Live stream resumed successfully after ad break");
8015
8073
  }
8016
8074
  return;
8017
8075
  }
8018
- if (attempt >= maxAttempts) {
8019
- if (_this.debug) {
8020
- console.warn("[StormcloudVideoPlayer] Live stream failed to resume after ".concat(maxAttempts, " recovery attempts (t=").concat(currentTime.toFixed(2), "s)"));
8076
+ if (video.paused) {
8077
+ var _video_play;
8078
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
8079
+ }
8080
+ var elapsed = Date.now() - startTime;
8081
+ var bufferedAhead = _this.getBufferedAhead();
8082
+ var wedged = bufferedAhead < 0.5 && !advanced;
8083
+ if (elapsed >= maxMonitorMs) {
8084
+ if (_this.debug && !advanced) {
8085
+ 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)"));
8021
8086
  }
8022
8087
  return;
8023
8088
  }
8024
- if (_this.debug) {
8025
- 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, ")"));
8026
- }
8027
- var liveSyncPos = _this.host.getLiveSyncPosition();
8028
- var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8029
- if (liveSyncPos != null && liveSyncPos > currentTime) {
8030
- _this.host.video.currentTime = liveSyncPos;
8031
- }
8032
- _this.host.restartHlsLoad(reloadPos);
8033
- if (_this.host.video.paused) {
8034
- var _this_host_video_play;
8035
- (_this_host_video_play = _this.host.video.play()) === null || _this_host_video_play === void 0 ? void 0 : _this_host_video_play.catch(function() {});
8089
+ var canRecover = wedged && elapsed >= graceMs && Date.now() - lastRecoveryAt >= recoveryCooldownMs && recoveries < maxRecoveries;
8090
+ if (canRecover) {
8091
+ recoveries++;
8092
+ lastRecoveryAt = Date.now();
8093
+ var isFinalAttempt = recoveries >= maxRecoveries;
8094
+ if (!isFinalAttempt) {
8095
+ var liveSyncPos = _this.host.getLiveSyncPosition();
8096
+ var reloadPos = liveSyncPos != null && liveSyncPos > currentTime ? liveSyncPos : currentTime;
8097
+ if (_this.debug) {
8098
+ 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, ")"));
8099
+ }
8100
+ if (liveSyncPos != null && liveSyncPos > currentTime) {
8101
+ video.currentTime = liveSyncPos;
8102
+ }
8103
+ _this.host.restartHlsLoad(reloadPos);
8104
+ } else {
8105
+ if (_this.debug) {
8106
+ 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, ")"));
8107
+ }
8108
+ _this.host.reloadLiveStream();
8109
+ }
8110
+ baseline = video.currentTime;
8111
+ if (video.paused) {
8112
+ var _video_play1;
8113
+ (_video_play1 = video.play()) === null || _video_play1 === void 0 ? void 0 : _video_play1.catch(function() {});
8114
+ }
8036
8115
  }
8037
- _this.monitorLiveResumeStall(attempt + 1, _this.host.video.currentTime);
8038
- }, checkDelayMs);
8116
+ window.setTimeout(poll, pollIntervalMs);
8117
+ };
8118
+ window.setTimeout(poll, pollIntervalMs);
8039
8119
  }
8040
8120
  },
8041
8121
  {
@@ -8189,6 +8269,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8189
8269
  restartHlsLoad: function restartHlsLoad(position) {
8190
8270
  return _this.hlsEngine.restartLoadAt(position);
8191
8271
  },
8272
+ reloadLiveStream: function reloadLiveStream() {
8273
+ return _this.hlsEngine.reloadLiveStream();
8274
+ },
8192
8275
  generatePodVastUrl: function generatePodVastUrl(base, breakDurationMs) {
8193
8276
  return _this.generatePodVastUrl(base, breakDurationMs);
8194
8277
  }
@@ -8320,6 +8403,14 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8320
8403
  return _async_to_generator(function() {
8321
8404
  var prerollKey, adBehavior;
8322
8405
  return _ts_generator(this, function(_state) {
8406
+ if (this.hlsEngine.reloadingLiveStream) {
8407
+ if (this.debug) {
8408
+ console.log("[StormcloudVideoPlayer] Manifest re-parsed after hard reload \u2014 skipping ad-player setup");
8409
+ }
8410
+ return [
8411
+ 2
8412
+ ];
8413
+ }
8323
8414
  if (!this.adConfig.isVmapEnabled() && !isLive && this.adConfig.vmapBreaks.length === 0 && this.adConfig.apiVastTagUrl) {
8324
8415
  prerollKey = "synthetic-vod-preroll";
8325
8416
  if (!this.adConfig.consumedVmapBreakIds.has(prerollKey)) {