stormcloud-video-player 0.3.7 → 0.3.9

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
@@ -408,12 +408,8 @@ function createImaController(video, options) {
408
408
  let adsLoadedReject;
409
409
  function makeAdsRequest(google, vastTagUrl) {
410
410
  const adsRequest = new google.ima.AdsRequest();
411
- const preloadedResponse = preloadedVast.get(vastTagUrl);
412
- if (preloadedResponse) {
413
- adsRequest.adsResponse = preloadedResponse;
414
- } else {
415
- adsRequest.adTagUrl = vastTagUrl;
416
- }
411
+ console.log("[IMA] \u{1F4E1} Requesting VAST from URL (letting IMA fetch fresh)");
412
+ adsRequest.adTagUrl = vastTagUrl;
417
413
  const videoWidth = video.offsetWidth || video.clientWidth || 640;
418
414
  const videoHeight = video.offsetHeight || video.clientHeight || 360;
419
415
  adsRequest.linearAdSlotWidth = videoWidth;
@@ -436,11 +432,8 @@ function createImaController(video, options) {
436
432
  console.warn("[IMA] Failed to call setAdWillPlayMuted:", error);
437
433
  }
438
434
  }
439
- adsRequest.vastLoadTimeout = 5e3;
435
+ adsRequest.vastLoadTimeout = 1e4;
440
436
  adsLoader.requestAds(adsRequest);
441
- if (preloadedResponse) {
442
- preloadedVast.delete(vastTagUrl);
443
- }
444
437
  }
445
438
  function ensurePlaceholderContainer() {
446
439
  var _a;
@@ -2155,6 +2148,7 @@ var StormcloudVideoPlayer = class {
2155
2148
  this.fetchedAdDurations = /* @__PURE__ */ new Map();
2156
2149
  this.targetAdBreakDurationMs = null;
2157
2150
  this.isAdaptiveMode = false;
2151
+ this.failedVastUrls = /* @__PURE__ */ new Set();
2158
2152
  initializePolyfills();
2159
2153
  const browserOverrides = getBrowserConfigOverrides();
2160
2154
  this.config = { ...config, ...browserOverrides };
@@ -3134,6 +3128,7 @@ var StormcloudVideoPlayer = class {
3134
3128
  this.vastToMediaUrlMap.clear();
3135
3129
  this.preloadedMediaUrls.clear();
3136
3130
  this.preloadingMediaUrls.clear();
3131
+ this.failedVastUrls.clear();
3137
3132
  const currentMuted = this.video.muted;
3138
3133
  const currentVolume = this.video.volume;
3139
3134
  this.ima.updateOriginalMutedState(currentMuted, currentVolume);
@@ -3334,6 +3329,11 @@ var StormcloudVideoPlayer = class {
3334
3329
  if (this.ima.isAdPlaying()) {
3335
3330
  return;
3336
3331
  }
3332
+ if (this.failedVastUrls.has(vastTagUrl)) {
3333
+ console.warn("[AD-ERROR] Skipping already-failed VAST URL:", vastTagUrl.substring(0, 60));
3334
+ this.handleAdFailure();
3335
+ return;
3336
+ }
3337
3337
  const requestToken = ++this.adRequestTokenCounter;
3338
3338
  this.activeAdRequestToken = requestToken;
3339
3339
  this.startAdRequestWatchdog(requestToken);
@@ -3348,6 +3348,7 @@ var StormcloudVideoPlayer = class {
3348
3348
  await this.ima.play();
3349
3349
  } catch (playError) {
3350
3350
  console.error("[AD-ERROR] Failed to play ad:", playError);
3351
+ this.failedVastUrls.add(vastTagUrl);
3351
3352
  this.clearAdFailsafeTimer();
3352
3353
  if (this.activeAdRequestToken === requestToken) {
3353
3354
  this.activeAdRequestToken = null;
@@ -3357,6 +3358,7 @@ var StormcloudVideoPlayer = class {
3357
3358
  }
3358
3359
  } catch (error) {
3359
3360
  console.error("[AD-ERROR] Ad request failed:", error == null ? void 0 : error.message);
3361
+ this.failedVastUrls.add(vastTagUrl);
3360
3362
  this.clearAdRequestWatchdog();
3361
3363
  this.clearAdFailsafeTimer();
3362
3364
  if (this.activeAdRequestToken === requestToken) {
@@ -3401,7 +3403,8 @@ var StormcloudVideoPlayer = class {
3401
3403
  }
3402
3404
  handleAdFailure() {
3403
3405
  const remaining = this.getRemainingAdMs();
3404
- if (remaining > 500 && this.adPodQueue.length > 0) {
3406
+ const availableAds = this.adPodQueue.filter((url) => !this.failedVastUrls.has(url)).length;
3407
+ if (remaining > 500 && availableAds > 0) {
3405
3408
  if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
3406
3409
  console.log("[ADAPTIVE-POD] \u23F3 First ad failed, waiting for sequential preload to catch up...");
3407
3410
  setTimeout(() => {
@@ -3418,6 +3421,7 @@ var StormcloudVideoPlayer = class {
3418
3421
  return;
3419
3422
  }
3420
3423
  }
3424
+ console.error("[AD-ERROR] All ads failed or time expired. Failed URLs:", this.failedVastUrls.size);
3421
3425
  this.handleAdPodComplete();
3422
3426
  }
3423
3427
  tryNextAdWithRetry(retryCount) {
@@ -3849,6 +3853,12 @@ var StormcloudVideoPlayer = class {
3849
3853
  );
3850
3854
  }
3851
3855
  mediaUrls = await this.fetchAndParseVastXml(vastTagUrl);
3856
+ if (this.config.debugAdTiming) {
3857
+ console.log(
3858
+ `[StormcloudVideoPlayer] Extracted ${mediaUrls.length} media URLs:`,
3859
+ mediaUrls
3860
+ );
3861
+ }
3852
3862
  if (mediaUrls.length > 0) {
3853
3863
  this.vastToMediaUrlMap.set(vastTagUrl, mediaUrls);
3854
3864
  }
@@ -3873,6 +3883,10 @@ var StormcloudVideoPlayer = class {
3873
3883
  for (let i = 0; i < this.adPodQueue.length; i++) {
3874
3884
  const vastTagUrl = this.adPodQueue[i];
3875
3885
  if (!vastTagUrl) continue;
3886
+ if (this.failedVastUrls.has(vastTagUrl)) {
3887
+ console.warn("[AD-ERROR] Skipping failed URL in queue");
3888
+ continue;
3889
+ }
3876
3890
  const hasImaPreload = (_c = (_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, vastTagUrl)) != null ? _c : false;
3877
3891
  const mediaUrls = this.vastToMediaUrlMap.get(vastTagUrl);
3878
3892
  const hasMediaPreload = mediaUrls && mediaUrls.length > 0 ? this.preloadedMediaUrls.has(mediaUrls[0]) : false;