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