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