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.
@@ -1,4 +1,4 @@
1
- import { S as StormcloudVideoPlayerConfig } from '../types-CUKMIqHL.cjs';
1
+ import { S as StormcloudVideoPlayerConfig } from '../types-DQM-Tu6a.cjs';
2
2
 
3
3
  declare class StormcloudVideoPlayer {
4
4
  private readonly video;
@@ -61,6 +61,7 @@ declare class StormcloudVideoPlayer {
61
61
  private readonly maxConsecutiveFailures;
62
62
  private lastAdRequestTime;
63
63
  private readonly minAdRequestIntervalMs;
64
+ private readonly defaultMinRemainingMsToStartAd;
64
65
  private readonly backoffBaseMs;
65
66
  private readonly maxBackoffMs;
66
67
  private placeholderContainer;
@@ -196,6 +197,8 @@ declare class StormcloudVideoPlayer {
196
197
  private selectVastTagsForBreak;
197
198
  private logAdState;
198
199
  private getRemainingAdMs;
200
+ private getMinRemainingMsToStartAd;
201
+ private hasTimeToStartAnotherAd;
199
202
  private findBreakForTime;
200
203
  toggleMute(): void;
201
204
  toggleFullscreen(): Promise<void>;
@@ -2688,6 +2688,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2688
2688
  this.maxConsecutiveFailures = 5;
2689
2689
  this.lastAdRequestTime = 0;
2690
2690
  this.minAdRequestIntervalMs = 3e3;
2691
+ this.defaultMinRemainingMsToStartAd = 4e3;
2691
2692
  this.backoffBaseMs = 1e3;
2692
2693
  this.maxBackoffMs = 15e3;
2693
2694
  this.globalConsecutiveNoFills = 0;
@@ -3207,7 +3208,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3207
3208
  } : {});
3208
3209
  }
3209
3210
  if (_this.inAdBreak) {
3210
- if (remaining > 500) {
3211
+ if (_this.hasTimeToStartAnotherAd()) {
3211
3212
  _this.tryNextAvailableAdWithRateLimit();
3212
3213
  } else {
3213
3214
  _this.handleAdPodComplete();
@@ -3280,7 +3281,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3280
3281
  queuedUrls: _to_consumable_array(_this.adRequestQueue)
3281
3282
  } : {});
3282
3283
  }
3283
- if (remaining > 500) {
3284
+ if (_this.hasTimeToStartAnotherAd()) {
3284
3285
  _this.tryNextAvailableAdWithRateLimit();
3285
3286
  } else {
3286
3287
  _this.handleAdPodComplete();
@@ -3980,7 +3981,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3980
3981
  var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
3981
3982
  this.scheduleAdStopCountdown(remainingMs1);
3982
3983
  }
3983
- if (!this.adPlayer.isAdPlaying() && this.activeAdRequestToken === null && this.adRequestQueue.length > 0) {
3984
+ if (!this.adPlayer.isAdPlaying() && this.activeAdRequestToken === null && this.adRequestQueue.length > 0 && this.hasTimeToStartAnotherAd()) {
3984
3985
  this.tryNextAvailableAdWithRateLimit();
3985
3986
  }
3986
3987
  return;
@@ -5439,7 +5440,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5439
5440
  key: "preloadPoolLoop",
5440
5441
  value: function preloadPoolLoop(baseVastUrl) {
5441
5442
  return _async_to_generator(function() {
5442
- var epoch, remaining, newUrls, newUrl;
5443
+ var epoch, newUrls, newUrl;
5443
5444
  return _ts_generator(this, function(_state) {
5444
5445
  switch(_state.label){
5445
5446
  case 0:
@@ -5506,14 +5507,14 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5506
5507
  8
5507
5508
  ];
5508
5509
  }
5509
- if (this.inAdBreak) {
5510
- remaining = this.getRemainingAdMs();
5511
- if (remaining <= 0) {
5512
- return [
5513
- 3,
5514
- 8
5515
- ];
5510
+ if (this.inAdBreak && !this.hasTimeToStartAnotherAd()) {
5511
+ if (this.config.debugAdTiming) {
5512
+ console.log("[PRELOAD-POOL] Not enough ad break time left, stopping preload");
5516
5513
  }
5514
+ return [
5515
+ 3,
5516
+ 8
5517
+ ];
5517
5518
  }
5518
5519
  newUrls = this.generateVastUrlsWithCorrelators(baseVastUrl, 1);
5519
5520
  newUrl = newUrls[0];
@@ -5943,9 +5944,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5943
5944
  switch(_state.label){
5944
5945
  case 0:
5945
5946
  remaining = _this.getRemainingAdMs();
5946
- if (remaining <= 0) {
5947
+ if (remaining <= _this.getMinRemainingMsToStartAd()) {
5947
5948
  if (_this.config.debugAdTiming) {
5948
- console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F Ad break time expired, stopping URL generation");
5949
+ console.log("[CONTINUOUS-FETCH] ⏹️ Not enough ad break time left (".concat(remaining, "ms), stopping URL generation"));
5949
5950
  }
5950
5951
  return [
5951
5952
  2,
@@ -6165,9 +6166,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6165
6166
  ];
6166
6167
  }
6167
6168
  remaining = this.getRemainingAdMs();
6168
- if (remaining <= 500) {
6169
+ if (!this.hasTimeToStartAnotherAd()) {
6169
6170
  if (this.config.debugAdTiming) {
6170
- console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F No time remaining, ending ad break");
6171
+ console.log("[CONTINUOUS-FETCH] ⏹️ Not enough time remaining (".concat(remaining, "ms) to start another ad, ending ad break"));
6171
6172
  }
6172
6173
  this.handleAdPodComplete();
6173
6174
  return [
@@ -6439,12 +6440,27 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6439
6440
  10
6440
6441
  ];
6441
6442
  }
6443
+ if (!this.hasTimeToStartAnotherAd()) {
6444
+ if (this.config.debugAdTiming) {
6445
+ console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F Not enough time remaining during placeholder wait, ending ad break");
6446
+ }
6447
+ return [
6448
+ 3,
6449
+ 10
6450
+ ];
6451
+ }
6442
6452
  _state.label = 3;
6443
6453
  case 3:
6444
6454
  if (!(this.adRequestQueue.length > 0)) return [
6445
6455
  3,
6446
6456
  9
6447
6457
  ];
6458
+ if (!this.hasTimeToStartAnotherAd()) {
6459
+ return [
6460
+ 3,
6461
+ 9
6462
+ ];
6463
+ }
6448
6464
  nextAdUrl = this.adRequestQueue.shift();
6449
6465
  if (!nextAdUrl) {
6450
6466
  return [
@@ -6727,21 +6743,23 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6727
6743
  if (!this.inAdBreak) return;
6728
6744
  this.adStopTimerId = void 0;
6729
6745
  var adPlaying = this.adPlayer.isAdPlaying();
6730
- var pendingAds = this.adPodQueue.length > 0;
6731
6746
  var checkIntervalMs = Math.max(250, Math.floor((_this_config_adBreakCheckIntervalMs = this.config.adBreakCheckIntervalMs) !== null && _this_config_adBreakCheckIntervalMs !== void 0 ? _this_config_adBreakCheckIntervalMs : 1e3));
6732
6747
  var maxExtensionMsConfig = this.config.maxAdBreakExtensionMs;
6733
- var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 6e4;
6748
+ var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 0;
6734
6749
  var elapsedSinceStartMs = 0;
6735
6750
  if (this.currentAdBreakStartWallClockMs != null) {
6736
6751
  elapsedSinceStartMs = Date.now() - this.currentAdBreakStartWallClockMs;
6737
6752
  }
6738
6753
  var expectedDurationMs = (_this_expectedAdBreakDurationMs = this.expectedAdBreakDurationMs) !== null && _this_expectedAdBreakDurationMs !== void 0 ? _this_expectedAdBreakDurationMs : 0;
6739
6754
  var overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
6740
- var shouldExtendAdBreak = (adPlaying || pendingAds || this.showAds) && overrunMs < maxExtensionMs;
6755
+ var shouldExtendAdBreak = adPlaying && overrunMs < maxExtensionMs;
6741
6756
  if (shouldExtendAdBreak) {
6742
6757
  this.scheduleAdStopCountdown(checkIntervalMs);
6743
6758
  return;
6744
6759
  }
6760
+ if (this.config.debugAdTiming) {
6761
+ console.log("[StormcloudVideoPlayer] ⏱️ Ad break boundary reached (overrun=".concat(overrunMs, "ms) - hard-stopping ads and resuming stream"));
6762
+ }
6745
6763
  if (adPlaying) {
6746
6764
  this.adPlayer.stop().catch(function() {});
6747
6765
  }
@@ -7247,11 +7265,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7247
7265
  this.handleAdPodComplete();
7248
7266
  return;
7249
7267
  }
7250
- if (remaining > 500) {
7268
+ if (this.hasTimeToStartAnotherAd()) {
7251
7269
  this.tryNextAvailableAdWithRateLimit();
7252
7270
  } else {
7253
7271
  if (this.config.debugAdTiming) {
7254
- console.log("[AD-ERROR] Ad failed and no time remaining. Failed URLs:", this.failedVastUrls.size);
7272
+ console.log("[AD-ERROR] Ad failed and not enough time remaining for another ad. Failed URLs:", this.failedVastUrls.size);
7255
7273
  }
7256
7274
  this.handleAdPodComplete();
7257
7275
  }
@@ -7386,6 +7404,22 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7386
7404
  return Math.max(0, this.expectedAdBreakDurationMs - elapsed);
7387
7405
  }
7388
7406
  },
7407
+ {
7408
+ key: "getMinRemainingMsToStartAd",
7409
+ value: function getMinRemainingMsToStartAd() {
7410
+ var configured = this.config.minRemainingMsToStartAd;
7411
+ if (typeof configured === "number" && configured >= 0) {
7412
+ return configured;
7413
+ }
7414
+ return this.defaultMinRemainingMsToStartAd;
7415
+ }
7416
+ },
7417
+ {
7418
+ key: "hasTimeToStartAnotherAd",
7419
+ value: function hasTimeToStartAnotherAd() {
7420
+ return this.getRemainingAdMs() > this.getMinRemainingMsToStartAd();
7421
+ }
7422
+ },
7389
7423
  {
7390
7424
  key: "findBreakForTime",
7391
7425
  value: function findBreakForTime(nowMs) {