stormcloud-video-player 0.3.0 → 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;
@@ -3210,20 +3205,30 @@ var StormcloudVideoPlayer = class {
3210
3205
  console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
3211
3206
  return;
3212
3207
  }
3213
- await new Promise((resolve) => setTimeout(resolve, 500));
3208
+ const waitTime = this.isAdaptiveMode ? 1500 : 500;
3209
+ await new Promise((resolve) => setTimeout(resolve, waitTime));
3214
3210
  const firstPreloaded = this.findNextPreloadedAd();
3215
3211
  if (!firstPreloaded) {
3216
3212
  console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads after wait, trying first ad");
3217
3213
  const firstAd = this.adPodQueue.shift();
3218
3214
  if (firstAd) {
3219
3215
  this.currentAdIndex++;
3220
- 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
+ }
3221
3222
  }
3222
3223
  return;
3223
3224
  }
3224
3225
  this.currentAdIndex++;
3225
3226
  console.log(`[DEBUG-POD] \u{1F680} Starting pod with ad ${this.currentAdIndex}/${this.totalAdsInBreak}`);
3226
- 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
+ }
3227
3232
  }
3228
3233
  findCurrentOrNextBreak(nowMs) {
3229
3234
  var _a;
@@ -3432,6 +3437,13 @@ var StormcloudVideoPlayer = class {
3432
3437
  console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
3433
3438
  const remaining = this.getRemainingAdMs();
3434
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
+ }
3435
3447
  const nextPreloaded = this.findNextPreloadedAd();
3436
3448
  if (nextPreloaded) {
3437
3449
  this.currentAdIndex++;
@@ -3445,6 +3457,42 @@ var StormcloudVideoPlayer = class {
3445
3457
  console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
3446
3458
  this.handleAdPodComplete();
3447
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
+ }
3448
3496
  startAdRequestWatchdog(token) {
3449
3497
  var _a;
3450
3498
  this.clearAdRequestWatchdog();
@@ -3655,22 +3703,12 @@ var StormcloudVideoPlayer = class {
3655
3703
  );
3656
3704
  if (this.config.debugAdTiming) {
3657
3705
  console.log(
3658
- `[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue`
3706
+ `[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue (will be preloaded sequentially)`
3659
3707
  );
3660
3708
  }
3661
3709
  this.adPodAllUrls.push(...newUrls);
3662
3710
  this.adPodQueue.push(...newUrls);
3663
3711
  this.totalAdsInBreak += newUrls.length;
3664
- for (const url of newUrls) {
3665
- this.preloadSingleAd(url).catch((error) => {
3666
- if (this.config.debugAdTiming) {
3667
- console.warn(
3668
- `[ADAPTIVE-POD] Failed to preload adaptive ad:`,
3669
- error
3670
- );
3671
- }
3672
- });
3673
- }
3674
3712
  }
3675
3713
  async preloadMediaFile(mediaUrl) {
3676
3714
  if (this.preloadedMediaUrls.has(mediaUrl)) {
@@ -3716,26 +3754,73 @@ var StormcloudVideoPlayer = class {
3716
3754
  if (this.adPodAllUrls.length === 0) {
3717
3755
  return;
3718
3756
  }
3719
- if (this.config.debugAdTiming) {
3720
- console.log(
3721
- `[StormcloudVideoPlayer] Starting parallel preload of ${this.adPodAllUrls.length} ads`
3722
- );
3723
- }
3724
- const preloadPromises = this.adPodAllUrls.map(
3725
- (vastTagUrl) => this.preloadSingleAd(vastTagUrl).catch((error) => {
3757
+ if (this.isAdaptiveMode) {
3758
+ if (this.config.debugAdTiming) {
3759
+ console.log(
3760
+ `[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
3761
+ );
3762
+ }
3763
+ const processedUrls = /* @__PURE__ */ new Set();
3764
+ while (true) {
3765
+ const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
3766
+ if (!nextUrl) {
3767
+ if (this.config.debugAdTiming) {
3768
+ console.log(`[ADAPTIVE-POD] \u2705 All queued ads processed (${processedUrls.size} total)`);
3769
+ }
3770
+ break;
3771
+ }
3772
+ processedUrls.add(nextUrl);
3726
3773
  if (this.config.debugAdTiming) {
3727
- console.warn(
3728
- `[StormcloudVideoPlayer] Preload failed for ${vastTagUrl}:`,
3729
- error
3774
+ console.log(
3775
+ `[ADAPTIVE-POD] \u{1F4E5} Preloading ad ${processedUrls.size}/${this.adPodAllUrls.length}...`
3730
3776
  );
3731
3777
  }
3732
- })
3733
- );
3734
- await Promise.all(preloadPromises);
3735
- if (this.config.debugAdTiming) {
3736
- console.log(
3737
- `[StormcloudVideoPlayer] Background preloading completed for all ads`
3778
+ try {
3779
+ await this.preloadSingleAd(nextUrl);
3780
+ } catch (error) {
3781
+ if (this.config.debugAdTiming) {
3782
+ console.warn(
3783
+ `[ADAPTIVE-POD] \u26A0\uFE0F Preload failed for ad ${processedUrls.size}:`,
3784
+ error
3785
+ );
3786
+ }
3787
+ }
3788
+ if (this.calculateAdditionalAdsNeeded() === 0) {
3789
+ if (this.config.debugAdTiming) {
3790
+ console.log(
3791
+ `[ADAPTIVE-POD] \u2705 Target duration reached (${processedUrls.size} ads preloaded), stopping`
3792
+ );
3793
+ }
3794
+ break;
3795
+ }
3796
+ }
3797
+ if (this.config.debugAdTiming) {
3798
+ console.log(
3799
+ `[ADAPTIVE-POD] \u2705 Sequential preloading completed (${processedUrls.size} ads ready)`
3800
+ );
3801
+ }
3802
+ } else {
3803
+ if (this.config.debugAdTiming) {
3804
+ console.log(
3805
+ `[StormcloudVideoPlayer] Starting parallel preload of ${this.adPodAllUrls.length} ads`
3806
+ );
3807
+ }
3808
+ const preloadPromises = this.adPodAllUrls.map(
3809
+ (vastTagUrl) => this.preloadSingleAd(vastTagUrl).catch((error) => {
3810
+ if (this.config.debugAdTiming) {
3811
+ console.warn(
3812
+ `[StormcloudVideoPlayer] Preload failed for ${vastTagUrl}:`,
3813
+ error
3814
+ );
3815
+ }
3816
+ })
3738
3817
  );
3818
+ await Promise.all(preloadPromises);
3819
+ if (this.config.debugAdTiming) {
3820
+ console.log(
3821
+ `[StormcloudVideoPlayer] Background preloading completed for all ads`
3822
+ );
3823
+ }
3739
3824
  }
3740
3825
  }
3741
3826
  async preloadSingleAd(vastTagUrl) {