stormcloud-video-player 0.3.2 → 0.3.4

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.
@@ -2432,10 +2432,12 @@ var StormcloudVideoPlayer = class {
2432
2432
  this.handleAdPodComplete();
2433
2433
  }
2434
2434
  });
2435
- this.ima.on("ad_error", () => {
2435
+ this.ima.on("ad_error", (errorPayload) => {
2436
2436
  const remaining = this.getRemainingAdMs();
2437
- console.log(
2438
- `[DEBUG-POD] \u274C ad_error event | inBreak=${this.inAdBreak}, queue=${this.adPodQueue.length}, remaining=${remaining}ms`
2437
+ console.error(
2438
+ `[DEBUG-POD] \u274C ad_error event | inBreak=${this.inAdBreak}, queue=${this.adPodQueue.length}, remaining=${remaining}ms`,
2439
+ errorPayload ? `
2440
+ Error details: ${JSON.stringify(errorPayload)}` : ""
2439
2441
  );
2440
2442
  if (this.inAdBreak) {
2441
2443
  if (remaining > 500 && this.adPodQueue.length > 0) {
@@ -2462,7 +2464,7 @@ var StormcloudVideoPlayer = class {
2462
2464
  }
2463
2465
  });
2464
2466
  this.ima.on("content_pause", () => {
2465
- console.log(`[DEBUG-POD] \u{1F3AF} content_pause | ad ${this.currentAdIndex}/${this.totalAdsInBreak}, queue=${this.adPodQueue.length}`);
2467
+ console.log(`[DEBUG-POD] \u{1F3AF} content_pause (AD STARTING!) | ad ${this.currentAdIndex}/${this.totalAdsInBreak}, queue=${this.adPodQueue.length}`);
2466
2468
  this.clearAdFailsafeTimer();
2467
2469
  this.clearAdRequestWatchdog();
2468
2470
  this.activeAdRequestToken = null;
@@ -3184,15 +3186,35 @@ var StormcloudVideoPlayer = class {
3184
3186
  this.currentAdIndex = 0;
3185
3187
  this.totalAdsInBreak = vastTagUrls.length;
3186
3188
  this.adPodQueue = [...vastTagUrls];
3187
- this.preloadAllAdsInBackground().catch((error) => {
3189
+ if (this.isAdaptiveMode) {
3188
3190
  if (this.config.debugAdTiming) {
3189
- console.warn(
3190
- "[StormcloudVideoPlayer] Error in background preloading:",
3191
- error
3192
- );
3191
+ console.log("[ADAPTIVE-POD] Waiting for sequential preloading to complete...");
3193
3192
  }
3194
- });
3195
- await this.playAdPod();
3193
+ try {
3194
+ await this.preloadAllAdsInBackground();
3195
+ if (this.config.debugAdTiming) {
3196
+ console.log("[ADAPTIVE-POD] Preloading complete, starting playback");
3197
+ }
3198
+ } catch (error) {
3199
+ if (this.config.debugAdTiming) {
3200
+ console.warn(
3201
+ "[ADAPTIVE-POD] Error in preloading:",
3202
+ error
3203
+ );
3204
+ }
3205
+ }
3206
+ await this.playAdPod();
3207
+ } else {
3208
+ this.preloadAllAdsInBackground().catch((error) => {
3209
+ if (this.config.debugAdTiming) {
3210
+ console.warn(
3211
+ "[StormcloudVideoPlayer] Error in background preloading:",
3212
+ error
3213
+ );
3214
+ }
3215
+ });
3216
+ await this.playAdPod();
3217
+ }
3196
3218
  }
3197
3219
  if (this.expectedAdBreakDurationMs == null && (scheduled == null ? void 0 : scheduled.durationMs) != null) {
3198
3220
  this.expectedAdBreakDurationMs = scheduled.durationMs;
@@ -3205,20 +3227,28 @@ var StormcloudVideoPlayer = class {
3205
3227
  console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
3206
3228
  return;
3207
3229
  }
3208
- const waitTime = this.isAdaptiveMode ? 1500 : 500;
3230
+ const waitTime = this.isAdaptiveMode ? 100 : 500;
3209
3231
  await new Promise((resolve) => setTimeout(resolve, waitTime));
3232
+ if (this.config.debugAdTiming) {
3233
+ console.log(
3234
+ `[DEBUG-POD] \u{1F50D} Looking for preloaded ad in queue of ${this.adPodQueue.length} URLs`
3235
+ );
3236
+ }
3210
3237
  const firstPreloaded = this.findNextPreloadedAd();
3211
3238
  if (!firstPreloaded) {
3212
- console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads after wait, trying first ad");
3239
+ console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads found, trying first ad from queue");
3213
3240
  const firstAd = this.adPodQueue.shift();
3214
3241
  if (firstAd) {
3215
3242
  this.currentAdIndex++;
3243
+ console.log(`[DEBUG-POD] \u{1F3AC} Attempting to play first ad (not preloaded): ${firstAd.substring(0, 60)}...`);
3216
3244
  try {
3217
3245
  await this.playSingleAd(firstAd);
3218
3246
  } catch (error) {
3219
3247
  console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
3220
3248
  return;
3221
3249
  }
3250
+ } else {
3251
+ console.log("[DEBUG-POD] \u274C No ads available in queue");
3222
3252
  }
3223
3253
  return;
3224
3254
  }
@@ -3359,22 +3389,31 @@ var StormcloudVideoPlayer = class {
3359
3389
  console.log(`[DEBUG-POD] \u{1F4DD} Request token=${requestToken}, preloaded=${wasPreloaded}`);
3360
3390
  this.startAdRequestWatchdog(requestToken);
3361
3391
  try {
3392
+ console.log(`[DEBUG-POD] \u{1F4E1} Calling ima.requestAds() for token=${requestToken}...`);
3362
3393
  await this.ima.requestAds(vastTagUrl);
3394
+ console.log(`[DEBUG-POD] \u2705 ima.requestAds() completed successfully`);
3363
3395
  this.clearAdRequestWatchdog();
3364
3396
  if (this.activeAdRequestToken !== requestToken) {
3365
3397
  console.warn(`[DEBUG-POD] \u26A0\uFE0F Token mismatch after requestAds (stale request)`);
3366
3398
  return;
3367
3399
  }
3400
+ console.log(`[DEBUG-POD] \u{1F4FA} Calling ima.play() to start ad playback...`);
3401
+ console.log(`[DEBUG-POD] \u{1F4CA} Video element state: paused=${this.video.paused}, muted=${this.video.muted}, readyState=${this.video.readyState}`);
3368
3402
  try {
3369
3403
  this.startAdFailsafeTimer(requestToken);
3370
3404
  await this.ima.play();
3371
3405
  if (this.activeAdRequestToken === requestToken) {
3372
- console.log(`[DEBUG-POD] \u2705 Ad play initiated (token=${requestToken})`);
3406
+ console.log(`[DEBUG-POD] \u2705 Ad play initiated successfully (token=${requestToken})`);
3373
3407
  } else {
3374
3408
  console.warn(`[DEBUG-POD] \u26A0\uFE0F Token mismatch after play (stale request)`);
3375
3409
  }
3376
3410
  } catch (playError) {
3377
- console.log("[DEBUG-POD] \u26A0\uFE0F No ads available from play()");
3411
+ console.error(
3412
+ "[DEBUG-POD] \u274C Failed to play ad:",
3413
+ playError instanceof Error ? playError.message : playError,
3414
+ "\nFull error:",
3415
+ playError
3416
+ );
3378
3417
  this.clearAdFailsafeTimer();
3379
3418
  if (this.activeAdRequestToken === requestToken) {
3380
3419
  this.activeAdRequestToken = null;
@@ -3893,17 +3932,26 @@ var StormcloudVideoPlayer = class {
3893
3932
  }
3894
3933
  findNextPreloadedAd() {
3895
3934
  var _a, _b, _c;
3935
+ if (this.config.debugAdTiming) {
3936
+ console.log(
3937
+ `[DEBUG-POD] \u{1F50E} Searching for preloaded ad in queue (${this.adPodQueue.length} URLs, ${this.preloadedMediaUrls.size} media preloaded, ${this.vastToMediaUrlMap.size} VAST mappings)`
3938
+ );
3939
+ }
3896
3940
  for (let i = 0; i < this.adPodQueue.length; i++) {
3897
3941
  const vastTagUrl = this.adPodQueue[i];
3898
3942
  if (!vastTagUrl) continue;
3899
3943
  const hasImaPreload = (_c = (_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, vastTagUrl)) != null ? _c : false;
3900
3944
  const mediaUrls = this.vastToMediaUrlMap.get(vastTagUrl);
3901
3945
  const hasMediaPreload = mediaUrls && mediaUrls.length > 0 ? this.preloadedMediaUrls.has(mediaUrls[0]) : false;
3946
+ if (this.config.debugAdTiming) {
3947
+ console.log(
3948
+ `[DEBUG-POD] Ad ${i}: IMA=${hasImaPreload}, Media=${hasMediaPreload}, MediaURLs=${(mediaUrls == null ? void 0 : mediaUrls.length) || 0}, URL=${vastTagUrl.substring(0, 60)}...`
3949
+ );
3950
+ }
3902
3951
  if (hasImaPreload || hasMediaPreload) {
3903
3952
  if (this.config.debugAdTiming) {
3904
3953
  console.log(
3905
- `[StormcloudVideoPlayer] Found preloaded ad at index ${i}: ${vastTagUrl}`,
3906
- { hasImaPreload, hasMediaPreload }
3954
+ `[DEBUG-POD] \u2705 Found preloaded ad at index ${i}`
3907
3955
  );
3908
3956
  }
3909
3957
  this.adPodQueue.splice(0, i + 1);
@@ -3912,7 +3960,7 @@ var StormcloudVideoPlayer = class {
3912
3960
  }
3913
3961
  if (this.config.debugAdTiming) {
3914
3962
  console.log(
3915
- "[StormcloudVideoPlayer] No preloaded ads found in queue"
3963
+ `[DEBUG-POD] \u274C No preloaded ads found in queue`
3916
3964
  );
3917
3965
  }
3918
3966
  return void 0;