stormcloud-video-player 0.8.9 → 0.8.10

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.cjs CHANGED
@@ -2919,6 +2919,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2919
2919
  this.maxConsecutiveFailures = 5;
2920
2920
  this.lastAdRequestTime = 0;
2921
2921
  this.minAdRequestIntervalMs = 3e3;
2922
+ this.defaultMinRemainingMsToStartAd = 4e3;
2922
2923
  this.backoffBaseMs = 1e3;
2923
2924
  this.maxBackoffMs = 15e3;
2924
2925
  this.globalConsecutiveNoFills = 0;
@@ -3438,7 +3439,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3438
3439
  } : {});
3439
3440
  }
3440
3441
  if (_this.inAdBreak) {
3441
- if (remaining > 500) {
3442
+ if (_this.hasTimeToStartAnotherAd()) {
3442
3443
  _this.tryNextAvailableAdWithRateLimit();
3443
3444
  } else {
3444
3445
  _this.handleAdPodComplete();
@@ -3511,7 +3512,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3511
3512
  queuedUrls: _to_consumable_array(_this.adRequestQueue)
3512
3513
  } : {});
3513
3514
  }
3514
- if (remaining > 500) {
3515
+ if (_this.hasTimeToStartAnotherAd()) {
3515
3516
  _this.tryNextAvailableAdWithRateLimit();
3516
3517
  } else {
3517
3518
  _this.handleAdPodComplete();
@@ -4211,7 +4212,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4211
4212
  var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4212
4213
  this.scheduleAdStopCountdown(remainingMs1);
4213
4214
  }
4214
- if (!this.adPlayer.isAdPlaying() && this.activeAdRequestToken === null && this.adRequestQueue.length > 0) {
4215
+ if (!this.adPlayer.isAdPlaying() && this.activeAdRequestToken === null && this.adRequestQueue.length > 0 && this.hasTimeToStartAnotherAd()) {
4215
4216
  this.tryNextAvailableAdWithRateLimit();
4216
4217
  }
4217
4218
  return;
@@ -5670,7 +5671,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5670
5671
  key: "preloadPoolLoop",
5671
5672
  value: function preloadPoolLoop(baseVastUrl) {
5672
5673
  return _async_to_generator(function() {
5673
- var epoch, remaining, newUrls, newUrl;
5674
+ var epoch, newUrls, newUrl;
5674
5675
  return _ts_generator(this, function(_state) {
5675
5676
  switch(_state.label){
5676
5677
  case 0:
@@ -5737,14 +5738,14 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5737
5738
  8
5738
5739
  ];
5739
5740
  }
5740
- if (this.inAdBreak) {
5741
- remaining = this.getRemainingAdMs();
5742
- if (remaining <= 0) {
5743
- return [
5744
- 3,
5745
- 8
5746
- ];
5741
+ if (this.inAdBreak && !this.hasTimeToStartAnotherAd()) {
5742
+ if (this.config.debugAdTiming) {
5743
+ console.log("[PRELOAD-POOL] Not enough ad break time left, stopping preload");
5747
5744
  }
5745
+ return [
5746
+ 3,
5747
+ 8
5748
+ ];
5748
5749
  }
5749
5750
  newUrls = this.generateVastUrlsWithCorrelators(baseVastUrl, 1);
5750
5751
  newUrl = newUrls[0];
@@ -6174,9 +6175,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6174
6175
  switch(_state.label){
6175
6176
  case 0:
6176
6177
  remaining = _this.getRemainingAdMs();
6177
- if (remaining <= 0) {
6178
+ if (remaining <= _this.getMinRemainingMsToStartAd()) {
6178
6179
  if (_this.config.debugAdTiming) {
6179
- console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F Ad break time expired, stopping URL generation");
6180
+ console.log("[CONTINUOUS-FETCH] ⏹️ Not enough ad break time left (".concat(remaining, "ms), stopping URL generation"));
6180
6181
  }
6181
6182
  return [
6182
6183
  2,
@@ -6396,9 +6397,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6396
6397
  ];
6397
6398
  }
6398
6399
  remaining = this.getRemainingAdMs();
6399
- if (remaining <= 500) {
6400
+ if (!this.hasTimeToStartAnotherAd()) {
6400
6401
  if (this.config.debugAdTiming) {
6401
- console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F No time remaining, ending ad break");
6402
+ console.log("[CONTINUOUS-FETCH] ⏹️ Not enough time remaining (".concat(remaining, "ms) to start another ad, ending ad break"));
6402
6403
  }
6403
6404
  this.handleAdPodComplete();
6404
6405
  return [
@@ -6670,12 +6671,27 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6670
6671
  10
6671
6672
  ];
6672
6673
  }
6674
+ if (!this.hasTimeToStartAnotherAd()) {
6675
+ if (this.config.debugAdTiming) {
6676
+ console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F Not enough time remaining during placeholder wait, ending ad break");
6677
+ }
6678
+ return [
6679
+ 3,
6680
+ 10
6681
+ ];
6682
+ }
6673
6683
  _state.label = 3;
6674
6684
  case 3:
6675
6685
  if (!(this.adRequestQueue.length > 0)) return [
6676
6686
  3,
6677
6687
  9
6678
6688
  ];
6689
+ if (!this.hasTimeToStartAnotherAd()) {
6690
+ return [
6691
+ 3,
6692
+ 9
6693
+ ];
6694
+ }
6679
6695
  nextAdUrl = this.adRequestQueue.shift();
6680
6696
  if (!nextAdUrl) {
6681
6697
  return [
@@ -6958,21 +6974,23 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6958
6974
  if (!this.inAdBreak) return;
6959
6975
  this.adStopTimerId = void 0;
6960
6976
  var adPlaying = this.adPlayer.isAdPlaying();
6961
- var pendingAds = this.adPodQueue.length > 0;
6962
6977
  var checkIntervalMs = Math.max(250, Math.floor((_this_config_adBreakCheckIntervalMs = this.config.adBreakCheckIntervalMs) !== null && _this_config_adBreakCheckIntervalMs !== void 0 ? _this_config_adBreakCheckIntervalMs : 1e3));
6963
6978
  var maxExtensionMsConfig = this.config.maxAdBreakExtensionMs;
6964
- var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 6e4;
6979
+ var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 0;
6965
6980
  var elapsedSinceStartMs = 0;
6966
6981
  if (this.currentAdBreakStartWallClockMs != null) {
6967
6982
  elapsedSinceStartMs = Date.now() - this.currentAdBreakStartWallClockMs;
6968
6983
  }
6969
6984
  var expectedDurationMs = (_this_expectedAdBreakDurationMs = this.expectedAdBreakDurationMs) !== null && _this_expectedAdBreakDurationMs !== void 0 ? _this_expectedAdBreakDurationMs : 0;
6970
6985
  var overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
6971
- var shouldExtendAdBreak = (adPlaying || pendingAds || this.showAds) && overrunMs < maxExtensionMs;
6986
+ var shouldExtendAdBreak = adPlaying && overrunMs < maxExtensionMs;
6972
6987
  if (shouldExtendAdBreak) {
6973
6988
  this.scheduleAdStopCountdown(checkIntervalMs);
6974
6989
  return;
6975
6990
  }
6991
+ if (this.config.debugAdTiming) {
6992
+ console.log("[StormcloudVideoPlayer] ⏱️ Ad break boundary reached (overrun=".concat(overrunMs, "ms) - hard-stopping ads and resuming stream"));
6993
+ }
6976
6994
  if (adPlaying) {
6977
6995
  this.adPlayer.stop().catch(function() {});
6978
6996
  }
@@ -7478,11 +7496,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7478
7496
  this.handleAdPodComplete();
7479
7497
  return;
7480
7498
  }
7481
- if (remaining > 500) {
7499
+ if (this.hasTimeToStartAnotherAd()) {
7482
7500
  this.tryNextAvailableAdWithRateLimit();
7483
7501
  } else {
7484
7502
  if (this.config.debugAdTiming) {
7485
- console.log("[AD-ERROR] Ad failed and no time remaining. Failed URLs:", this.failedVastUrls.size);
7503
+ console.log("[AD-ERROR] Ad failed and not enough time remaining for another ad. Failed URLs:", this.failedVastUrls.size);
7486
7504
  }
7487
7505
  this.handleAdPodComplete();
7488
7506
  }
@@ -7617,6 +7635,22 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7617
7635
  return Math.max(0, this.expectedAdBreakDurationMs - elapsed);
7618
7636
  }
7619
7637
  },
7638
+ {
7639
+ key: "getMinRemainingMsToStartAd",
7640
+ value: function getMinRemainingMsToStartAd() {
7641
+ var configured = this.config.minRemainingMsToStartAd;
7642
+ if (typeof configured === "number" && configured >= 0) {
7643
+ return configured;
7644
+ }
7645
+ return this.defaultMinRemainingMsToStartAd;
7646
+ }
7647
+ },
7648
+ {
7649
+ key: "hasTimeToStartAnotherAd",
7650
+ value: function hasTimeToStartAnotherAd() {
7651
+ return this.getRemainingAdMs() > this.getMinRemainingMsToStartAd();
7652
+ }
7653
+ },
7620
7654
  {
7621
7655
  key: "findBreakForTime",
7622
7656
  value: function findBreakForTime(nowMs) {