stormcloud-video-player 0.8.8 → 0.8.9

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
@@ -2933,6 +2933,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2933
2933
  this.preloadPoolActive = false;
2934
2934
  this.preloadPoolLoopRunning = false;
2935
2935
  this.adDetectSentForCurrentBreak = false;
2936
+ this.adBreakEpoch = 0;
2936
2937
  this.palPlaybackStarted = false;
2937
2938
  this.streamCorrelator = generateCorrelator();
2938
2939
  this.consentSignals = {};
@@ -5480,7 +5481,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5480
5481
  key: "preloadAdIntoPool",
5481
5482
  value: function preloadAdIntoPool(vastUrl) {
5482
5483
  return _async_to_generator(function() {
5483
- var _this, loadPromise;
5484
+ var _this, epoch, loadPromise;
5484
5485
  return _ts_generator(this, function(_state) {
5485
5486
  _this = this;
5486
5487
  if (this.isGamInCooldown()) {
@@ -5506,6 +5507,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5506
5507
  if (this.config.debugAdTiming) {
5507
5508
  console.log("[PRELOAD-POOL] \uD83D\uDCE5 Preloading ad into pool: ".concat(vastUrl));
5508
5509
  }
5510
+ epoch = this.adBreakEpoch;
5509
5511
  loadPromise = function() {
5510
5512
  return _async_to_generator(function() {
5511
5513
  var _this, hasAdError, adErrorPayload, errorListenerCleanup, continueLiveStreamDuringAds, preloadAd, errorListener, isNoFill, poolEntry, lateErrorListener, error;
@@ -5583,6 +5585,20 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5583
5585
  2
5584
5586
  ];
5585
5587
  }
5588
+ if (!this.preloadPoolActive || epoch !== this.adBreakEpoch) {
5589
+ if (this.config.debugAdTiming) {
5590
+ console.log("[PRELOAD-POOL] \uD83D\uDEAB Discarding preloaded ad - break ended during fetch");
5591
+ }
5592
+ if (errorListenerCleanup) {
5593
+ errorListenerCleanup();
5594
+ }
5595
+ try {
5596
+ preloadAd.destroy();
5597
+ } catch (unused) {}
5598
+ return [
5599
+ 2
5600
+ ];
5601
+ }
5586
5602
  poolEntry = {
5587
5603
  vastUrl: vastUrl,
5588
5604
  adController: preloadAd,
@@ -5654,7 +5670,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5654
5670
  key: "preloadPoolLoop",
5655
5671
  value: function preloadPoolLoop(baseVastUrl) {
5656
5672
  return _async_to_generator(function() {
5657
- var remaining, newUrls, newUrl;
5673
+ var epoch, remaining, newUrls, newUrl;
5658
5674
  return _ts_generator(this, function(_state) {
5659
5675
  switch(_state.label){
5660
5676
  case 0:
@@ -5664,12 +5680,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5664
5680
  ];
5665
5681
  }
5666
5682
  this.preloadPoolLoopRunning = true;
5683
+ epoch = this.adBreakEpoch;
5667
5684
  if (this.config.debugAdTiming) {
5668
5685
  console.log("[PRELOAD-POOL] \uD83D\uDD04 Starting continuous preload loop");
5669
5686
  }
5670
5687
  _state.label = 1;
5671
5688
  case 1:
5672
- if (!this.preloadPoolActive) return [
5689
+ if (!(this.preloadPoolActive && epoch === this.adBreakEpoch)) return [
5673
5690
  3,
5674
5691
  10
5675
5692
  ];
@@ -5714,7 +5731,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5714
5731
  3,
5715
5732
  8
5716
5733
  ];
5717
- if (!this.preloadPoolActive || this.isGamInCooldown()) {
5734
+ if (!this.preloadPoolActive || epoch !== this.adBreakEpoch || this.isGamInCooldown()) {
5718
5735
  return [
5719
5736
  3,
5720
5737
  8
@@ -6147,7 +6164,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6147
6164
  key: "continuousFetchLoop",
6148
6165
  value: function continuousFetchLoop(baseVastUrl) {
6149
6166
  return _async_to_generator(function() {
6150
- var _this, _loop, _ret;
6167
+ var _this, _loop, epoch, _ret;
6151
6168
  return _ts_generator(this, function(_state) {
6152
6169
  switch(_state.label){
6153
6170
  case 0:
@@ -6257,9 +6274,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6257
6274
  }
6258
6275
  });
6259
6276
  };
6277
+ epoch = this.adBreakEpoch;
6260
6278
  _state.label = 1;
6261
6279
  case 1:
6262
- if (!(this.continuousFetchingActive && this.inAdBreak)) return [
6280
+ if (!(this.continuousFetchingActive && this.inAdBreak && epoch === this.adBreakEpoch)) return [
6263
6281
  3,
6264
6282
  3
6265
6283
  ];
@@ -6308,10 +6326,16 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6308
6326
  key: "tryNextAvailableAdWithRateLimit",
6309
6327
  value: function tryNextAvailableAdWithRateLimit() {
6310
6328
  return _async_to_generator(function() {
6311
- var backoffMultiplier, backoffDelay, effectiveMinInterval, timeSinceLastRequest, waitTime;
6329
+ var epoch, backoffMultiplier, backoffDelay, effectiveMinInterval, timeSinceLastRequest, waitTime;
6312
6330
  return _ts_generator(this, function(_state) {
6313
6331
  switch(_state.label){
6314
6332
  case 0:
6333
+ if (!this.inAdBreak) {
6334
+ return [
6335
+ 2
6336
+ ];
6337
+ }
6338
+ epoch = this.adBreakEpoch;
6315
6339
  if (this.consecutiveFailures >= this.maxConsecutiveFailures) {
6316
6340
  if (this.config.debugAdTiming) {
6317
6341
  console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Too many consecutive failures (".concat(this.consecutiveFailures, "), ending ad break gracefully"));
@@ -6343,6 +6367,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6343
6367
  _state.sent();
6344
6368
  _state.label = 2;
6345
6369
  case 2:
6370
+ if (!this.inAdBreak || epoch !== this.adBreakEpoch) {
6371
+ return [
6372
+ 2
6373
+ ];
6374
+ }
6346
6375
  return [
6347
6376
  2,
6348
6377
  this.tryNextAvailableAd(0)
@@ -6361,6 +6390,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6361
6390
  return _ts_generator(this, function(_state) {
6362
6391
  switch(_state.label){
6363
6392
  case 0:
6393
+ if (!this.inAdBreak) {
6394
+ return [
6395
+ 2
6396
+ ];
6397
+ }
6364
6398
  remaining = this.getRemainingAdMs();
6365
6399
  if (remaining <= 500) {
6366
6400
  if (this.config.debugAdTiming) {
@@ -7373,6 +7407,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7373
7407
  if (this.config.debugAdTiming) {
7374
7408
  console.log("[StormcloudVideoPlayer] \uD83C\uDFC1 Ad pod complete - cleaning up");
7375
7409
  }
7410
+ this.adBreakEpoch++;
7376
7411
  this.clearAdRequestWatchdog();
7377
7412
  this.clearAdFailsafeTimer();
7378
7413
  this.activeAdRequestToken = null;