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.
package/lib/index.cjs CHANGED
@@ -2499,10 +2499,12 @@ var StormcloudVideoPlayer = class {
2499
2499
  this.handleAdPodComplete();
2500
2500
  }
2501
2501
  });
2502
- this.ima.on("ad_error", () => {
2502
+ this.ima.on("ad_error", (errorPayload) => {
2503
2503
  const remaining = this.getRemainingAdMs();
2504
- console.log(
2505
- `[DEBUG-POD] \u274C ad_error event | inBreak=${this.inAdBreak}, queue=${this.adPodQueue.length}, remaining=${remaining}ms`
2504
+ console.error(
2505
+ `[DEBUG-POD] \u274C ad_error event | inBreak=${this.inAdBreak}, queue=${this.adPodQueue.length}, remaining=${remaining}ms`,
2506
+ errorPayload ? `
2507
+ Error details: ${JSON.stringify(errorPayload)}` : ""
2506
2508
  );
2507
2509
  if (this.inAdBreak) {
2508
2510
  if (remaining > 500 && this.adPodQueue.length > 0) {
@@ -2529,7 +2531,7 @@ var StormcloudVideoPlayer = class {
2529
2531
  }
2530
2532
  });
2531
2533
  this.ima.on("content_pause", () => {
2532
- console.log(`[DEBUG-POD] \u{1F3AF} content_pause | ad ${this.currentAdIndex}/${this.totalAdsInBreak}, queue=${this.adPodQueue.length}`);
2534
+ console.log(`[DEBUG-POD] \u{1F3AF} content_pause (AD STARTING!) | ad ${this.currentAdIndex}/${this.totalAdsInBreak}, queue=${this.adPodQueue.length}`);
2533
2535
  this.clearAdFailsafeTimer();
2534
2536
  this.clearAdRequestWatchdog();
2535
2537
  this.activeAdRequestToken = null;
@@ -3251,15 +3253,35 @@ var StormcloudVideoPlayer = class {
3251
3253
  this.currentAdIndex = 0;
3252
3254
  this.totalAdsInBreak = vastTagUrls.length;
3253
3255
  this.adPodQueue = [...vastTagUrls];
3254
- this.preloadAllAdsInBackground().catch((error) => {
3256
+ if (this.isAdaptiveMode) {
3255
3257
  if (this.config.debugAdTiming) {
3256
- console.warn(
3257
- "[StormcloudVideoPlayer] Error in background preloading:",
3258
- error
3259
- );
3258
+ console.log("[ADAPTIVE-POD] Waiting for sequential preloading to complete...");
3260
3259
  }
3261
- });
3262
- await this.playAdPod();
3260
+ try {
3261
+ await this.preloadAllAdsInBackground();
3262
+ if (this.config.debugAdTiming) {
3263
+ console.log("[ADAPTIVE-POD] Preloading complete, starting playback");
3264
+ }
3265
+ } catch (error) {
3266
+ if (this.config.debugAdTiming) {
3267
+ console.warn(
3268
+ "[ADAPTIVE-POD] Error in preloading:",
3269
+ error
3270
+ );
3271
+ }
3272
+ }
3273
+ await this.playAdPod();
3274
+ } else {
3275
+ this.preloadAllAdsInBackground().catch((error) => {
3276
+ if (this.config.debugAdTiming) {
3277
+ console.warn(
3278
+ "[StormcloudVideoPlayer] Error in background preloading:",
3279
+ error
3280
+ );
3281
+ }
3282
+ });
3283
+ await this.playAdPod();
3284
+ }
3263
3285
  }
3264
3286
  if (this.expectedAdBreakDurationMs == null && (scheduled == null ? void 0 : scheduled.durationMs) != null) {
3265
3287
  this.expectedAdBreakDurationMs = scheduled.durationMs;
@@ -3272,20 +3294,28 @@ var StormcloudVideoPlayer = class {
3272
3294
  console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
3273
3295
  return;
3274
3296
  }
3275
- const waitTime = this.isAdaptiveMode ? 1500 : 500;
3297
+ const waitTime = this.isAdaptiveMode ? 100 : 500;
3276
3298
  await new Promise((resolve) => setTimeout(resolve, waitTime));
3299
+ if (this.config.debugAdTiming) {
3300
+ console.log(
3301
+ `[DEBUG-POD] \u{1F50D} Looking for preloaded ad in queue of ${this.adPodQueue.length} URLs`
3302
+ );
3303
+ }
3277
3304
  const firstPreloaded = this.findNextPreloadedAd();
3278
3305
  if (!firstPreloaded) {
3279
- console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads after wait, trying first ad");
3306
+ console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads found, trying first ad from queue");
3280
3307
  const firstAd = this.adPodQueue.shift();
3281
3308
  if (firstAd) {
3282
3309
  this.currentAdIndex++;
3310
+ console.log(`[DEBUG-POD] \u{1F3AC} Attempting to play first ad (not preloaded): ${firstAd.substring(0, 60)}...`);
3283
3311
  try {
3284
3312
  await this.playSingleAd(firstAd);
3285
3313
  } catch (error) {
3286
3314
  console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
3287
3315
  return;
3288
3316
  }
3317
+ } else {
3318
+ console.log("[DEBUG-POD] \u274C No ads available in queue");
3289
3319
  }
3290
3320
  return;
3291
3321
  }
@@ -3426,22 +3456,31 @@ var StormcloudVideoPlayer = class {
3426
3456
  console.log(`[DEBUG-POD] \u{1F4DD} Request token=${requestToken}, preloaded=${wasPreloaded}`);
3427
3457
  this.startAdRequestWatchdog(requestToken);
3428
3458
  try {
3459
+ console.log(`[DEBUG-POD] \u{1F4E1} Calling ima.requestAds() for token=${requestToken}...`);
3429
3460
  await this.ima.requestAds(vastTagUrl);
3461
+ console.log(`[DEBUG-POD] \u2705 ima.requestAds() completed successfully`);
3430
3462
  this.clearAdRequestWatchdog();
3431
3463
  if (this.activeAdRequestToken !== requestToken) {
3432
3464
  console.warn(`[DEBUG-POD] \u26A0\uFE0F Token mismatch after requestAds (stale request)`);
3433
3465
  return;
3434
3466
  }
3467
+ console.log(`[DEBUG-POD] \u{1F4FA} Calling ima.play() to start ad playback...`);
3468
+ console.log(`[DEBUG-POD] \u{1F4CA} Video element state: paused=${this.video.paused}, muted=${this.video.muted}, readyState=${this.video.readyState}`);
3435
3469
  try {
3436
3470
  this.startAdFailsafeTimer(requestToken);
3437
3471
  await this.ima.play();
3438
3472
  if (this.activeAdRequestToken === requestToken) {
3439
- console.log(`[DEBUG-POD] \u2705 Ad play initiated (token=${requestToken})`);
3473
+ console.log(`[DEBUG-POD] \u2705 Ad play initiated successfully (token=${requestToken})`);
3440
3474
  } else {
3441
3475
  console.warn(`[DEBUG-POD] \u26A0\uFE0F Token mismatch after play (stale request)`);
3442
3476
  }
3443
3477
  } catch (playError) {
3444
- console.log("[DEBUG-POD] \u26A0\uFE0F No ads available from play()");
3478
+ console.error(
3479
+ "[DEBUG-POD] \u274C Failed to play ad:",
3480
+ playError instanceof Error ? playError.message : playError,
3481
+ "\nFull error:",
3482
+ playError
3483
+ );
3445
3484
  this.clearAdFailsafeTimer();
3446
3485
  if (this.activeAdRequestToken === requestToken) {
3447
3486
  this.activeAdRequestToken = null;
@@ -3960,17 +3999,26 @@ var StormcloudVideoPlayer = class {
3960
3999
  }
3961
4000
  findNextPreloadedAd() {
3962
4001
  var _a, _b, _c;
4002
+ if (this.config.debugAdTiming) {
4003
+ console.log(
4004
+ `[DEBUG-POD] \u{1F50E} Searching for preloaded ad in queue (${this.adPodQueue.length} URLs, ${this.preloadedMediaUrls.size} media preloaded, ${this.vastToMediaUrlMap.size} VAST mappings)`
4005
+ );
4006
+ }
3963
4007
  for (let i = 0; i < this.adPodQueue.length; i++) {
3964
4008
  const vastTagUrl = this.adPodQueue[i];
3965
4009
  if (!vastTagUrl) continue;
3966
4010
  const hasImaPreload = (_c = (_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, vastTagUrl)) != null ? _c : false;
3967
4011
  const mediaUrls = this.vastToMediaUrlMap.get(vastTagUrl);
3968
4012
  const hasMediaPreload = mediaUrls && mediaUrls.length > 0 ? this.preloadedMediaUrls.has(mediaUrls[0]) : false;
4013
+ if (this.config.debugAdTiming) {
4014
+ console.log(
4015
+ `[DEBUG-POD] Ad ${i}: IMA=${hasImaPreload}, Media=${hasMediaPreload}, MediaURLs=${(mediaUrls == null ? void 0 : mediaUrls.length) || 0}, URL=${vastTagUrl.substring(0, 60)}...`
4016
+ );
4017
+ }
3969
4018
  if (hasImaPreload || hasMediaPreload) {
3970
4019
  if (this.config.debugAdTiming) {
3971
4020
  console.log(
3972
- `[StormcloudVideoPlayer] Found preloaded ad at index ${i}: ${vastTagUrl}`,
3973
- { hasImaPreload, hasMediaPreload }
4021
+ `[DEBUG-POD] \u2705 Found preloaded ad at index ${i}`
3974
4022
  );
3975
4023
  }
3976
4024
  this.adPodQueue.splice(0, i + 1);
@@ -3979,7 +4027,7 @@ var StormcloudVideoPlayer = class {
3979
4027
  }
3980
4028
  if (this.config.debugAdTiming) {
3981
4029
  console.log(
3982
- "[StormcloudVideoPlayer] No preloaded ads found in queue"
4030
+ `[DEBUG-POD] \u274C No preloaded ads found in queue`
3983
4031
  );
3984
4032
  }
3985
4033
  return void 0;