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