stormcloud-video-player 0.3.0 → 0.3.1

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.
@@ -3210,7 +3210,8 @@ var StormcloudVideoPlayer = class {
3210
3210
  console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
3211
3211
  return;
3212
3212
  }
3213
- await new Promise((resolve) => setTimeout(resolve, 500));
3213
+ const waitTime = this.isAdaptiveMode ? 1500 : 500;
3214
+ await new Promise((resolve) => setTimeout(resolve, waitTime));
3214
3215
  const firstPreloaded = this.findNextPreloadedAd();
3215
3216
  if (!firstPreloaded) {
3216
3217
  console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads after wait, trying first ad");
@@ -3655,22 +3656,12 @@ var StormcloudVideoPlayer = class {
3655
3656
  );
3656
3657
  if (this.config.debugAdTiming) {
3657
3658
  console.log(
3658
- `[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue`
3659
+ `[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue (will be preloaded sequentially)`
3659
3660
  );
3660
3661
  }
3661
3662
  this.adPodAllUrls.push(...newUrls);
3662
3663
  this.adPodQueue.push(...newUrls);
3663
3664
  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
3665
  }
3675
3666
  async preloadMediaFile(mediaUrl) {
3676
3667
  if (this.preloadedMediaUrls.has(mediaUrl)) {
@@ -3716,26 +3707,65 @@ var StormcloudVideoPlayer = class {
3716
3707
  if (this.adPodAllUrls.length === 0) {
3717
3708
  return;
3718
3709
  }
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) => {
3726
- if (this.config.debugAdTiming) {
3727
- console.warn(
3728
- `[StormcloudVideoPlayer] Preload failed for ${vastTagUrl}:`,
3729
- error
3730
- );
3710
+ if (this.isAdaptiveMode) {
3711
+ if (this.config.debugAdTiming) {
3712
+ console.log(
3713
+ `[ADAPTIVE-POD] Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
3714
+ );
3715
+ }
3716
+ const processedUrls = /* @__PURE__ */ new Set();
3717
+ while (true) {
3718
+ const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
3719
+ if (!nextUrl) {
3720
+ break;
3731
3721
  }
3732
- })
3733
- );
3734
- await Promise.all(preloadPromises);
3735
- if (this.config.debugAdTiming) {
3736
- console.log(
3737
- `[StormcloudVideoPlayer] Background preloading completed for all ads`
3722
+ processedUrls.add(nextUrl);
3723
+ try {
3724
+ await this.preloadSingleAd(nextUrl);
3725
+ } catch (error) {
3726
+ if (this.config.debugAdTiming) {
3727
+ console.warn(
3728
+ `[ADAPTIVE-POD] Preload failed for ${nextUrl}:`,
3729
+ error
3730
+ );
3731
+ }
3732
+ }
3733
+ if (this.calculateAdditionalAdsNeeded() === 0) {
3734
+ if (this.config.debugAdTiming) {
3735
+ console.log(
3736
+ `[ADAPTIVE-POD] \u2705 Target duration reached, stopping preload`
3737
+ );
3738
+ }
3739
+ break;
3740
+ }
3741
+ }
3742
+ if (this.config.debugAdTiming) {
3743
+ console.log(
3744
+ `[ADAPTIVE-POD] Sequential preloading completed (${processedUrls.size} ads preloaded)`
3745
+ );
3746
+ }
3747
+ } else {
3748
+ if (this.config.debugAdTiming) {
3749
+ console.log(
3750
+ `[StormcloudVideoPlayer] Starting parallel preload of ${this.adPodAllUrls.length} ads`
3751
+ );
3752
+ }
3753
+ const preloadPromises = this.adPodAllUrls.map(
3754
+ (vastTagUrl) => this.preloadSingleAd(vastTagUrl).catch((error) => {
3755
+ if (this.config.debugAdTiming) {
3756
+ console.warn(
3757
+ `[StormcloudVideoPlayer] Preload failed for ${vastTagUrl}:`,
3758
+ error
3759
+ );
3760
+ }
3761
+ })
3738
3762
  );
3763
+ await Promise.all(preloadPromises);
3764
+ if (this.config.debugAdTiming) {
3765
+ console.log(
3766
+ `[StormcloudVideoPlayer] Background preloading completed for all ads`
3767
+ );
3768
+ }
3739
3769
  }
3740
3770
  }
3741
3771
  async preloadSingleAd(vastTagUrl) {