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.
@@ -3188,21 +3188,38 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3188
3188
  this.adPodQueue = [...vastTagUrls];
3189
3189
  if (this.isAdaptiveMode) {
3190
3190
  if (this.config.debugAdTiming) {
3191
- console.log("[ADAPTIVE-POD] Waiting for sequential preloading to complete...");
3191
+ console.log("[ADAPTIVE-POD] \u{1F680} Preloading first 2 ads before starting playback...");
3192
3192
  }
3193
3193
  try {
3194
- await this.preloadAllAdsInBackground();
3194
+ const adsToPreloadBeforeStart = Math.min(2, this.adPodAllUrls.length);
3195
+ for (let i = 0; i < adsToPreloadBeforeStart; i++) {
3196
+ const url = this.adPodAllUrls[i];
3197
+ if (url) {
3198
+ await this.preloadSingleAd(url);
3199
+ if (this.config.debugAdTiming) {
3200
+ console.log(`[ADAPTIVE-POD] \u2705 Preloaded ad ${i + 1}/${adsToPreloadBeforeStart}`);
3201
+ }
3202
+ }
3203
+ }
3195
3204
  if (this.config.debugAdTiming) {
3196
- console.log("[ADAPTIVE-POD] Preloading complete, starting playback");
3205
+ console.log("[ADAPTIVE-POD] \u{1F3AC} First ads preloaded, starting playback immediately");
3197
3206
  }
3198
3207
  } catch (error) {
3199
3208
  if (this.config.debugAdTiming) {
3200
3209
  console.warn(
3201
- "[ADAPTIVE-POD] Error in preloading:",
3210
+ "[ADAPTIVE-POD] \u26A0\uFE0F Error preloading initial ads:",
3202
3211
  error
3203
3212
  );
3204
3213
  }
3205
3214
  }
3215
+ this.preloadAllAdsInBackground().catch((error) => {
3216
+ if (this.config.debugAdTiming) {
3217
+ console.warn(
3218
+ "[ADAPTIVE-POD] Error in background preloading:",
3219
+ error
3220
+ );
3221
+ }
3222
+ });
3206
3223
  await this.playAdPod();
3207
3224
  } else {
3208
3225
  this.preloadAllAdsInBackground().catch((error) => {
@@ -3227,7 +3244,7 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3227
3244
  console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
3228
3245
  return;
3229
3246
  }
3230
- const waitTime = this.isAdaptiveMode ? 100 : 500;
3247
+ const waitTime = this.isAdaptiveMode ? 50 : 500;
3231
3248
  await new Promise((resolve) => setTimeout(resolve, waitTime));
3232
3249
  if (this.config.debugAdTiming) {
3233
3250
  console.log(
@@ -3709,21 +3726,24 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3709
3726
  for (const duration of this.fetchedAdDurations.values()) {
3710
3727
  totalFetchedDurationMs += duration * 1e3;
3711
3728
  }
3712
- const remainingTimeMs = this.targetAdBreakDurationMs - totalFetchedDurationMs;
3729
+ const fetchedCount = this.fetchedAdDurations.size;
3730
+ const averageDurationMs = fetchedCount > 0 ? totalFetchedDurationMs / fetchedCount : 30 * 1e3;
3731
+ const queuedButNotFetched = this.adPodAllUrls.length - fetchedCount;
3732
+ const estimatedQueuedDurationMs = queuedButNotFetched * averageDurationMs;
3733
+ const estimatedTotalDurationMs = totalFetchedDurationMs + estimatedQueuedDurationMs;
3734
+ const remainingTimeMs = this.targetAdBreakDurationMs - estimatedTotalDurationMs;
3713
3735
  if (remainingTimeMs <= 0) {
3714
3736
  if (this.config.debugAdTiming) {
3715
3737
  console.log(
3716
- `[ADAPTIVE-POD] \u2705 Target duration reached: ${totalFetchedDurationMs}ms / ${this.targetAdBreakDurationMs}ms`
3738
+ `[ADAPTIVE-POD] \u2705 Target duration met: Fetched=${totalFetchedDurationMs}ms + Queued(${queuedButNotFetched} ads)=${estimatedQueuedDurationMs}ms = ${estimatedTotalDurationMs}ms / Target=${this.targetAdBreakDurationMs}ms`
3717
3739
  );
3718
3740
  }
3719
3741
  return 0;
3720
3742
  }
3721
- const fetchedCount = this.fetchedAdDurations.size;
3722
- const averageDurationMs = fetchedCount > 0 ? totalFetchedDurationMs / fetchedCount : 30 * 1e3;
3723
3743
  const additionalAds = Math.ceil(remainingTimeMs / averageDurationMs);
3724
3744
  if (this.config.debugAdTiming) {
3725
3745
  console.log(
3726
- `[ADAPTIVE-POD] \u{1F4CA} Need ${additionalAds} more ads | Fetched: ${totalFetchedDurationMs}ms / Target: ${this.targetAdBreakDurationMs}ms | Remaining: ${remainingTimeMs}ms | Avg duration: ${averageDurationMs}ms`
3746
+ `[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`
3727
3747
  );
3728
3748
  }
3729
3749
  return additionalAds;
@@ -3790,16 +3810,27 @@ Error details: ${JSON.stringify(errorPayload)}` : ""
3790
3810
  }
3791
3811
  }
3792
3812
  async preloadAllAdsInBackground() {
3813
+ var _a, _b;
3793
3814
  if (this.adPodAllUrls.length === 0) {
3794
3815
  return;
3795
3816
  }
3796
3817
  if (this.isAdaptiveMode) {
3797
3818
  if (this.config.debugAdTiming) {
3798
3819
  console.log(
3799
- `[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
3820
+ `[ADAPTIVE-POD] \u{1F504} Starting sequential preload of remaining ads`
3800
3821
  );
3801
3822
  }
3802
3823
  const processedUrls = /* @__PURE__ */ new Set();
3824
+ for (const url of this.adPodAllUrls) {
3825
+ if (((_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, url)) || this.fetchedAdDurations.has(url)) {
3826
+ processedUrls.add(url);
3827
+ }
3828
+ }
3829
+ if (this.config.debugAdTiming && processedUrls.size > 0) {
3830
+ console.log(
3831
+ `[ADAPTIVE-POD] \u{1F4E6} Skipping ${processedUrls.size} already-preloaded ads`
3832
+ );
3833
+ }
3803
3834
  while (true) {
3804
3835
  const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
3805
3836
  if (!nextUrl) {