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.cjs CHANGED
@@ -3277,7 +3277,8 @@ var StormcloudVideoPlayer = class {
3277
3277
  console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
3278
3278
  return;
3279
3279
  }
3280
- await new Promise((resolve) => setTimeout(resolve, 500));
3280
+ const waitTime = this.isAdaptiveMode ? 1500 : 500;
3281
+ await new Promise((resolve) => setTimeout(resolve, waitTime));
3281
3282
  const firstPreloaded = this.findNextPreloadedAd();
3282
3283
  if (!firstPreloaded) {
3283
3284
  console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads after wait, trying first ad");
@@ -3722,22 +3723,12 @@ var StormcloudVideoPlayer = class {
3722
3723
  );
3723
3724
  if (this.config.debugAdTiming) {
3724
3725
  console.log(
3725
- `[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue`
3726
+ `[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue (will be preloaded sequentially)`
3726
3727
  );
3727
3728
  }
3728
3729
  this.adPodAllUrls.push(...newUrls);
3729
3730
  this.adPodQueue.push(...newUrls);
3730
3731
  this.totalAdsInBreak += newUrls.length;
3731
- for (const url of newUrls) {
3732
- this.preloadSingleAd(url).catch((error) => {
3733
- if (this.config.debugAdTiming) {
3734
- console.warn(
3735
- `[ADAPTIVE-POD] Failed to preload adaptive ad:`,
3736
- error
3737
- );
3738
- }
3739
- });
3740
- }
3741
3732
  }
3742
3733
  async preloadMediaFile(mediaUrl) {
3743
3734
  if (this.preloadedMediaUrls.has(mediaUrl)) {
@@ -3783,26 +3774,65 @@ var StormcloudVideoPlayer = class {
3783
3774
  if (this.adPodAllUrls.length === 0) {
3784
3775
  return;
3785
3776
  }
3786
- if (this.config.debugAdTiming) {
3787
- console.log(
3788
- `[StormcloudVideoPlayer] Starting parallel preload of ${this.adPodAllUrls.length} ads`
3789
- );
3790
- }
3791
- const preloadPromises = this.adPodAllUrls.map(
3792
- (vastTagUrl) => this.preloadSingleAd(vastTagUrl).catch((error) => {
3793
- if (this.config.debugAdTiming) {
3794
- console.warn(
3795
- `[StormcloudVideoPlayer] Preload failed for ${vastTagUrl}:`,
3796
- error
3797
- );
3777
+ if (this.isAdaptiveMode) {
3778
+ if (this.config.debugAdTiming) {
3779
+ console.log(
3780
+ `[ADAPTIVE-POD] Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
3781
+ );
3782
+ }
3783
+ const processedUrls = /* @__PURE__ */ new Set();
3784
+ while (true) {
3785
+ const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
3786
+ if (!nextUrl) {
3787
+ break;
3798
3788
  }
3799
- })
3800
- );
3801
- await Promise.all(preloadPromises);
3802
- if (this.config.debugAdTiming) {
3803
- console.log(
3804
- `[StormcloudVideoPlayer] Background preloading completed for all ads`
3789
+ processedUrls.add(nextUrl);
3790
+ try {
3791
+ await this.preloadSingleAd(nextUrl);
3792
+ } catch (error) {
3793
+ if (this.config.debugAdTiming) {
3794
+ console.warn(
3795
+ `[ADAPTIVE-POD] Preload failed for ${nextUrl}:`,
3796
+ error
3797
+ );
3798
+ }
3799
+ }
3800
+ if (this.calculateAdditionalAdsNeeded() === 0) {
3801
+ if (this.config.debugAdTiming) {
3802
+ console.log(
3803
+ `[ADAPTIVE-POD] \u2705 Target duration reached, stopping preload`
3804
+ );
3805
+ }
3806
+ break;
3807
+ }
3808
+ }
3809
+ if (this.config.debugAdTiming) {
3810
+ console.log(
3811
+ `[ADAPTIVE-POD] Sequential preloading completed (${processedUrls.size} ads preloaded)`
3812
+ );
3813
+ }
3814
+ } else {
3815
+ if (this.config.debugAdTiming) {
3816
+ console.log(
3817
+ `[StormcloudVideoPlayer] Starting parallel preload of ${this.adPodAllUrls.length} ads`
3818
+ );
3819
+ }
3820
+ const preloadPromises = this.adPodAllUrls.map(
3821
+ (vastTagUrl) => this.preloadSingleAd(vastTagUrl).catch((error) => {
3822
+ if (this.config.debugAdTiming) {
3823
+ console.warn(
3824
+ `[StormcloudVideoPlayer] Preload failed for ${vastTagUrl}:`,
3825
+ error
3826
+ );
3827
+ }
3828
+ })
3805
3829
  );
3830
+ await Promise.all(preloadPromises);
3831
+ if (this.config.debugAdTiming) {
3832
+ console.log(
3833
+ `[StormcloudVideoPlayer] Background preloading completed for all ads`
3834
+ );
3835
+ }
3806
3836
  }
3807
3837
  }
3808
3838
  async preloadSingleAd(vastTagUrl) {