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