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.
@@ -3195,12 +3195,7 @@ var StormcloudVideoPlayer = class {
3195
3195
  );
3196
3196
  }
3197
3197
  });
3198
- try {
3199
- await this.playAdPod();
3200
- } catch (error) {
3201
- console.error("[DEBUG-POD] \u274C Pod playback failed:", error);
3202
- this.handleAdFailure();
3203
- }
3198
+ await this.playAdPod();
3204
3199
  }
3205
3200
  if (this.expectedAdBreakDurationMs == null && (scheduled == null ? void 0 : scheduled.durationMs) != null) {
3206
3201
  this.expectedAdBreakDurationMs = scheduled.durationMs;
@@ -3221,13 +3216,22 @@ var StormcloudVideoPlayer = class {
3221
3216
  const firstAd = this.adPodQueue.shift();
3222
3217
  if (firstAd) {
3223
3218
  this.currentAdIndex++;
3224
- await this.playSingleAd(firstAd);
3219
+ try {
3220
+ await this.playSingleAd(firstAd);
3221
+ } catch (error) {
3222
+ console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
3223
+ return;
3224
+ }
3225
3225
  }
3226
3226
  return;
3227
3227
  }
3228
3228
  this.currentAdIndex++;
3229
3229
  console.log(`[DEBUG-POD] \u{1F680} Starting pod with ad ${this.currentAdIndex}/${this.totalAdsInBreak}`);
3230
- await this.playSingleAd(firstPreloaded);
3230
+ try {
3231
+ await this.playSingleAd(firstPreloaded);
3232
+ } catch (error) {
3233
+ console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
3234
+ }
3231
3235
  }
3232
3236
  findCurrentOrNextBreak(nowMs) {
3233
3237
  var _a;
@@ -3436,6 +3440,13 @@ var StormcloudVideoPlayer = class {
3436
3440
  console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
3437
3441
  const remaining = this.getRemainingAdMs();
3438
3442
  if (remaining > 500 && this.adPodQueue.length > 0) {
3443
+ if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
3444
+ console.log("[ADAPTIVE-POD] \u23F3 First ad failed, waiting for sequential preload to catch up...");
3445
+ setTimeout(() => {
3446
+ this.tryNextAdWithRetry(0);
3447
+ }, 1500);
3448
+ return;
3449
+ }
3439
3450
  const nextPreloaded = this.findNextPreloadedAd();
3440
3451
  if (nextPreloaded) {
3441
3452
  this.currentAdIndex++;
@@ -3449,6 +3460,42 @@ var StormcloudVideoPlayer = class {
3449
3460
  console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
3450
3461
  this.handleAdPodComplete();
3451
3462
  }
3463
+ tryNextAdWithRetry(retryCount) {
3464
+ const maxRetries = 3;
3465
+ const remaining = this.getRemainingAdMs();
3466
+ if (this.config.debugAdTiming) {
3467
+ console.log(
3468
+ `[ADAPTIVE-POD] \u{1F50D} Retry attempt ${retryCount}: remaining=${remaining}ms, queue=${this.adPodQueue.length}, totalAds=${this.totalAdsInBreak}`
3469
+ );
3470
+ }
3471
+ if (remaining <= 500 || this.adPodQueue.length === 0) {
3472
+ console.log("[ADAPTIVE-POD] \u23F9\uFE0F No more time or ads available");
3473
+ this.handleAdPodComplete();
3474
+ return;
3475
+ }
3476
+ const nextPreloaded = this.findNextPreloadedAd();
3477
+ if (nextPreloaded) {
3478
+ this.currentAdIndex++;
3479
+ console.log(
3480
+ `[ADAPTIVE-POD] \u2705 Found preloaded ad after retry ${retryCount}, playing (${this.currentAdIndex}/${this.totalAdsInBreak})`
3481
+ );
3482
+ this.playSingleAd(nextPreloaded).catch(() => {
3483
+ this.handleAdPodComplete();
3484
+ });
3485
+ } else if (retryCount < maxRetries) {
3486
+ console.log(
3487
+ `[ADAPTIVE-POD] \u23F3 No preloaded ads yet (queue has ${this.adPodQueue.length} URLs), retry ${retryCount + 1}/${maxRetries} in 1s...`
3488
+ );
3489
+ setTimeout(() => {
3490
+ this.tryNextAdWithRetry(retryCount + 1);
3491
+ }, 1e3);
3492
+ } else {
3493
+ console.log(
3494
+ `[ADAPTIVE-POD] \u274C Max retries reached, no preloaded ads available (queue=${this.adPodQueue.length} URLs)`
3495
+ );
3496
+ this.handleAdPodComplete();
3497
+ }
3498
+ }
3452
3499
  startAdRequestWatchdog(token) {
3453
3500
  var _a;
3454
3501
  this.clearAdRequestWatchdog();
@@ -3713,22 +3760,30 @@ var StormcloudVideoPlayer = class {
3713
3760
  if (this.isAdaptiveMode) {
3714
3761
  if (this.config.debugAdTiming) {
3715
3762
  console.log(
3716
- `[ADAPTIVE-POD] Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
3763
+ `[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
3717
3764
  );
3718
3765
  }
3719
3766
  const processedUrls = /* @__PURE__ */ new Set();
3720
3767
  while (true) {
3721
3768
  const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
3722
3769
  if (!nextUrl) {
3770
+ if (this.config.debugAdTiming) {
3771
+ console.log(`[ADAPTIVE-POD] \u2705 All queued ads processed (${processedUrls.size} total)`);
3772
+ }
3723
3773
  break;
3724
3774
  }
3725
3775
  processedUrls.add(nextUrl);
3776
+ if (this.config.debugAdTiming) {
3777
+ console.log(
3778
+ `[ADAPTIVE-POD] \u{1F4E5} Preloading ad ${processedUrls.size}/${this.adPodAllUrls.length}...`
3779
+ );
3780
+ }
3726
3781
  try {
3727
3782
  await this.preloadSingleAd(nextUrl);
3728
3783
  } catch (error) {
3729
3784
  if (this.config.debugAdTiming) {
3730
3785
  console.warn(
3731
- `[ADAPTIVE-POD] Preload failed for ${nextUrl}:`,
3786
+ `[ADAPTIVE-POD] \u26A0\uFE0F Preload failed for ad ${processedUrls.size}:`,
3732
3787
  error
3733
3788
  );
3734
3789
  }
@@ -3736,7 +3791,7 @@ var StormcloudVideoPlayer = class {
3736
3791
  if (this.calculateAdditionalAdsNeeded() === 0) {
3737
3792
  if (this.config.debugAdTiming) {
3738
3793
  console.log(
3739
- `[ADAPTIVE-POD] \u2705 Target duration reached, stopping preload`
3794
+ `[ADAPTIVE-POD] \u2705 Target duration reached (${processedUrls.size} ads preloaded), stopping`
3740
3795
  );
3741
3796
  }
3742
3797
  break;
@@ -3744,7 +3799,7 @@ var StormcloudVideoPlayer = class {
3744
3799
  }
3745
3800
  if (this.config.debugAdTiming) {
3746
3801
  console.log(
3747
- `[ADAPTIVE-POD] Sequential preloading completed (${processedUrls.size} ads preloaded)`
3802
+ `[ADAPTIVE-POD] \u2705 Sequential preloading completed (${processedUrls.size} ads ready)`
3748
3803
  );
3749
3804
  }
3750
3805
  } else {