stormcloud-video-player 0.3.4 → 0.3.6

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.
@@ -3230,21 +3230,38 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3230
3230
  this.adPodQueue = [...vastTagUrls];
3231
3231
  if (this.isAdaptiveMode) {
3232
3232
  if (this.config.debugAdTiming) {
3233
- console.log("[ADAPTIVE-POD] Waiting for sequential preloading to complete...");
3233
+ console.log("[ADAPTIVE-POD] \u{1F680} Preloading first 2 ads before starting playback...");
3234
3234
  }
3235
3235
  try {
3236
- await this.preloadAllAdsInBackground();
3236
+ const adsToPreloadBeforeStart = Math.min(2, this.adPodAllUrls.length);
3237
+ for (let i = 0; i < adsToPreloadBeforeStart; i++) {
3238
+ const url = this.adPodAllUrls[i];
3239
+ if (url) {
3240
+ await this.preloadSingleAd(url);
3241
+ if (this.config.debugAdTiming) {
3242
+ console.log(`[ADAPTIVE-POD] \u2705 Preloaded ad ${i + 1}/${adsToPreloadBeforeStart}`);
3243
+ }
3244
+ }
3245
+ }
3237
3246
  if (this.config.debugAdTiming) {
3238
- console.log("[ADAPTIVE-POD] Preloading complete, starting playback");
3247
+ console.log("[ADAPTIVE-POD] \u{1F3AC} First ads preloaded, starting playback immediately");
3239
3248
  }
3240
3249
  } catch (error) {
3241
3250
  if (this.config.debugAdTiming) {
3242
3251
  console.warn(
3243
- "[ADAPTIVE-POD] Error in preloading:",
3252
+ "[ADAPTIVE-POD] \u26A0\uFE0F Error preloading initial ads:",
3244
3253
  error
3245
3254
  );
3246
3255
  }
3247
3256
  }
3257
+ this.preloadAllAdsInBackground().catch((error) => {
3258
+ if (this.config.debugAdTiming) {
3259
+ console.warn(
3260
+ "[ADAPTIVE-POD] Error in background preloading:",
3261
+ error
3262
+ );
3263
+ }
3264
+ });
3248
3265
  await this.playAdPod();
3249
3266
  } else {
3250
3267
  this.preloadAllAdsInBackground().catch((error) => {
@@ -3269,7 +3286,7 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3269
3286
  console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
3270
3287
  return;
3271
3288
  }
3272
- const waitTime = this.isAdaptiveMode ? 100 : 500;
3289
+ const waitTime = this.isAdaptiveMode ? 50 : 500;
3273
3290
  await new Promise((resolve) => setTimeout(resolve, waitTime));
3274
3291
  if (this.config.debugAdTiming) {
3275
3292
  console.log(
@@ -3751,21 +3768,24 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3751
3768
  for (const duration of this.fetchedAdDurations.values()) {
3752
3769
  totalFetchedDurationMs += duration * 1e3;
3753
3770
  }
3754
- const remainingTimeMs = this.targetAdBreakDurationMs - totalFetchedDurationMs;
3771
+ const fetchedCount = this.fetchedAdDurations.size;
3772
+ const averageDurationMs = fetchedCount > 0 ? totalFetchedDurationMs / fetchedCount : 30 * 1e3;
3773
+ const queuedButNotFetched = this.adPodAllUrls.length - fetchedCount;
3774
+ const estimatedQueuedDurationMs = queuedButNotFetched * averageDurationMs;
3775
+ const estimatedTotalDurationMs = totalFetchedDurationMs + estimatedQueuedDurationMs;
3776
+ const remainingTimeMs = this.targetAdBreakDurationMs - estimatedTotalDurationMs;
3755
3777
  if (remainingTimeMs <= 0) {
3756
3778
  if (this.config.debugAdTiming) {
3757
3779
  console.log(
3758
- `[ADAPTIVE-POD] \u2705 Target duration reached: ${totalFetchedDurationMs}ms / ${this.targetAdBreakDurationMs}ms`
3780
+ `[ADAPTIVE-POD] \u2705 Target duration met: Fetched=${totalFetchedDurationMs}ms + Queued(${queuedButNotFetched} ads)=${estimatedQueuedDurationMs}ms = ${estimatedTotalDurationMs}ms / Target=${this.targetAdBreakDurationMs}ms`
3759
3781
  );
3760
3782
  }
3761
3783
  return 0;
3762
3784
  }
3763
- const fetchedCount = this.fetchedAdDurations.size;
3764
- const averageDurationMs = fetchedCount > 0 ? totalFetchedDurationMs / fetchedCount : 30 * 1e3;
3765
3785
  const additionalAds = Math.ceil(remainingTimeMs / averageDurationMs);
3766
3786
  if (this.config.debugAdTiming) {
3767
3787
  console.log(
3768
- `[ADAPTIVE-POD] \u{1F4CA} Need ${additionalAds} more ads | Fetched: ${totalFetchedDurationMs}ms / Target: ${this.targetAdBreakDurationMs}ms | Remaining: ${remainingTimeMs}ms | Avg duration: ${averageDurationMs}ms`
3788
+ `[ADAPTIVE-POD] \u{1F4CA} Need ${additionalAds} more ads | Fetched: ${totalFetchedDurationMs}ms (${fetchedCount} ads) | Queued: ${estimatedQueuedDurationMs}ms (${queuedButNotFetched} ads) | Target: ${this.targetAdBreakDurationMs}ms | Remaining: ${remainingTimeMs}ms | Avg duration: ${averageDurationMs}ms`
3769
3789
  );
3770
3790
  }
3771
3791
  return additionalAds;
@@ -3832,16 +3852,27 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3832
3852
  }
3833
3853
  }
3834
3854
  async preloadAllAdsInBackground() {
3855
+ var _a, _b;
3835
3856
  if (this.adPodAllUrls.length === 0) {
3836
3857
  return;
3837
3858
  }
3838
3859
  if (this.isAdaptiveMode) {
3839
3860
  if (this.config.debugAdTiming) {
3840
3861
  console.log(
3841
- `[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
3862
+ `[ADAPTIVE-POD] \u{1F504} Starting sequential preload of remaining ads`
3842
3863
  );
3843
3864
  }
3844
3865
  const processedUrls = /* @__PURE__ */ new Set();
3866
+ for (const url of this.adPodAllUrls) {
3867
+ if (((_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, url)) || this.fetchedAdDurations.has(url)) {
3868
+ processedUrls.add(url);
3869
+ }
3870
+ }
3871
+ if (this.config.debugAdTiming && processedUrls.size > 0) {
3872
+ console.log(
3873
+ `[ADAPTIVE-POD] \u{1F4E6} Skipping ${processedUrls.size} already-preloaded ads`
3874
+ );
3875
+ }
3845
3876
  while (true) {
3846
3877
  const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
3847
3878
  if (!nextUrl) {