stormcloud-video-player 0.3.1 → 0.3.2

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
@@ -3259,12 +3259,7 @@ var StormcloudVideoPlayer = class {
3259
3259
  );
3260
3260
  }
3261
3261
  });
3262
- try {
3263
- await this.playAdPod();
3264
- } catch (error) {
3265
- console.error("[DEBUG-POD] \u274C Pod playback failed:", error);
3266
- this.handleAdFailure();
3267
- }
3262
+ await this.playAdPod();
3268
3263
  }
3269
3264
  if (this.expectedAdBreakDurationMs == null && (scheduled == null ? void 0 : scheduled.durationMs) != null) {
3270
3265
  this.expectedAdBreakDurationMs = scheduled.durationMs;
@@ -3285,13 +3280,22 @@ var StormcloudVideoPlayer = class {
3285
3280
  const firstAd = this.adPodQueue.shift();
3286
3281
  if (firstAd) {
3287
3282
  this.currentAdIndex++;
3288
- await this.playSingleAd(firstAd);
3283
+ try {
3284
+ await this.playSingleAd(firstAd);
3285
+ } catch (error) {
3286
+ console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
3287
+ return;
3288
+ }
3289
3289
  }
3290
3290
  return;
3291
3291
  }
3292
3292
  this.currentAdIndex++;
3293
3293
  console.log(`[DEBUG-POD] \u{1F680} Starting pod with ad ${this.currentAdIndex}/${this.totalAdsInBreak}`);
3294
- await this.playSingleAd(firstPreloaded);
3294
+ try {
3295
+ await this.playSingleAd(firstPreloaded);
3296
+ } catch (error) {
3297
+ console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
3298
+ }
3295
3299
  }
3296
3300
  findCurrentOrNextBreak(nowMs) {
3297
3301
  var _a;
@@ -3500,6 +3504,13 @@ var StormcloudVideoPlayer = class {
3500
3504
  console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
3501
3505
  const remaining = this.getRemainingAdMs();
3502
3506
  if (remaining > 500 && this.adPodQueue.length > 0) {
3507
+ if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
3508
+ console.log("[ADAPTIVE-POD] \u23F3 First ad failed, waiting for sequential preload to catch up...");
3509
+ setTimeout(() => {
3510
+ this.tryNextAdWithRetry(0);
3511
+ }, 1500);
3512
+ return;
3513
+ }
3503
3514
  const nextPreloaded = this.findNextPreloadedAd();
3504
3515
  if (nextPreloaded) {
3505
3516
  this.currentAdIndex++;
@@ -3513,6 +3524,42 @@ var StormcloudVideoPlayer = class {
3513
3524
  console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
3514
3525
  this.handleAdPodComplete();
3515
3526
  }
3527
+ tryNextAdWithRetry(retryCount) {
3528
+ const maxRetries = 3;
3529
+ const remaining = this.getRemainingAdMs();
3530
+ if (this.config.debugAdTiming) {
3531
+ console.log(
3532
+ `[ADAPTIVE-POD] \u{1F50D} Retry attempt ${retryCount}: remaining=${remaining}ms, queue=${this.adPodQueue.length}, totalAds=${this.totalAdsInBreak}`
3533
+ );
3534
+ }
3535
+ if (remaining <= 500 || this.adPodQueue.length === 0) {
3536
+ console.log("[ADAPTIVE-POD] \u23F9\uFE0F No more time or ads available");
3537
+ this.handleAdPodComplete();
3538
+ return;
3539
+ }
3540
+ const nextPreloaded = this.findNextPreloadedAd();
3541
+ if (nextPreloaded) {
3542
+ this.currentAdIndex++;
3543
+ console.log(
3544
+ `[ADAPTIVE-POD] \u2705 Found preloaded ad after retry ${retryCount}, playing (${this.currentAdIndex}/${this.totalAdsInBreak})`
3545
+ );
3546
+ this.playSingleAd(nextPreloaded).catch(() => {
3547
+ this.handleAdPodComplete();
3548
+ });
3549
+ } else if (retryCount < maxRetries) {
3550
+ console.log(
3551
+ `[ADAPTIVE-POD] \u23F3 No preloaded ads yet (queue has ${this.adPodQueue.length} URLs), retry ${retryCount + 1}/${maxRetries} in 1s...`
3552
+ );
3553
+ setTimeout(() => {
3554
+ this.tryNextAdWithRetry(retryCount + 1);
3555
+ }, 1e3);
3556
+ } else {
3557
+ console.log(
3558
+ `[ADAPTIVE-POD] \u274C Max retries reached, no preloaded ads available (queue=${this.adPodQueue.length} URLs)`
3559
+ );
3560
+ this.handleAdPodComplete();
3561
+ }
3562
+ }
3516
3563
  startAdRequestWatchdog(token) {
3517
3564
  var _a;
3518
3565
  this.clearAdRequestWatchdog();
@@ -3777,22 +3824,30 @@ var StormcloudVideoPlayer = class {
3777
3824
  if (this.isAdaptiveMode) {
3778
3825
  if (this.config.debugAdTiming) {
3779
3826
  console.log(
3780
- `[ADAPTIVE-POD] Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
3827
+ `[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
3781
3828
  );
3782
3829
  }
3783
3830
  const processedUrls = /* @__PURE__ */ new Set();
3784
3831
  while (true) {
3785
3832
  const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
3786
3833
  if (!nextUrl) {
3834
+ if (this.config.debugAdTiming) {
3835
+ console.log(`[ADAPTIVE-POD] \u2705 All queued ads processed (${processedUrls.size} total)`);
3836
+ }
3787
3837
  break;
3788
3838
  }
3789
3839
  processedUrls.add(nextUrl);
3840
+ if (this.config.debugAdTiming) {
3841
+ console.log(
3842
+ `[ADAPTIVE-POD] \u{1F4E5} Preloading ad ${processedUrls.size}/${this.adPodAllUrls.length}...`
3843
+ );
3844
+ }
3790
3845
  try {
3791
3846
  await this.preloadSingleAd(nextUrl);
3792
3847
  } catch (error) {
3793
3848
  if (this.config.debugAdTiming) {
3794
3849
  console.warn(
3795
- `[ADAPTIVE-POD] Preload failed for ${nextUrl}:`,
3850
+ `[ADAPTIVE-POD] \u26A0\uFE0F Preload failed for ad ${processedUrls.size}:`,
3796
3851
  error
3797
3852
  );
3798
3853
  }
@@ -3800,7 +3855,7 @@ var StormcloudVideoPlayer = class {
3800
3855
  if (this.calculateAdditionalAdsNeeded() === 0) {
3801
3856
  if (this.config.debugAdTiming) {
3802
3857
  console.log(
3803
- `[ADAPTIVE-POD] \u2705 Target duration reached, stopping preload`
3858
+ `[ADAPTIVE-POD] \u2705 Target duration reached (${processedUrls.size} ads preloaded), stopping`
3804
3859
  );
3805
3860
  }
3806
3861
  break;
@@ -3808,7 +3863,7 @@ var StormcloudVideoPlayer = class {
3808
3863
  }
3809
3864
  if (this.config.debugAdTiming) {
3810
3865
  console.log(
3811
- `[ADAPTIVE-POD] Sequential preloading completed (${processedUrls.size} ads preloaded)`
3866
+ `[ADAPTIVE-POD] \u2705 Sequential preloading completed (${processedUrls.size} ads ready)`
3812
3867
  );
3813
3868
  }
3814
3869
  } else {