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.
@@ -383,12 +383,8 @@ function createImaController(video, options) {
383
383
  let adsLoadedReject;
384
384
  function makeAdsRequest(google, vastTagUrl) {
385
385
  const adsRequest = new google.ima.AdsRequest();
386
- const preloadedResponse = preloadedVast.get(vastTagUrl);
387
- if (preloadedResponse) {
388
- adsRequest.adsResponse = preloadedResponse;
389
- } else {
390
- adsRequest.adTagUrl = vastTagUrl;
391
- }
386
+ console.log("[IMA] \u{1F4E1} Requesting VAST from URL (letting IMA fetch fresh)");
387
+ adsRequest.adTagUrl = vastTagUrl;
392
388
  const videoWidth = video.offsetWidth || video.clientWidth || 640;
393
389
  const videoHeight = video.offsetHeight || video.clientHeight || 360;
394
390
  adsRequest.linearAdSlotWidth = videoWidth;
@@ -411,11 +407,8 @@ function createImaController(video, options) {
411
407
  console.warn("[IMA] Failed to call setAdWillPlayMuted:", error);
412
408
  }
413
409
  }
414
- adsRequest.vastLoadTimeout = 5e3;
410
+ adsRequest.vastLoadTimeout = 1e4;
415
411
  adsLoader.requestAds(adsRequest);
416
- if (preloadedResponse) {
417
- preloadedVast.delete(vastTagUrl);
418
- }
419
412
  }
420
413
  function ensurePlaceholderContainer() {
421
414
  var _a;
@@ -2130,6 +2123,7 @@ var StormcloudVideoPlayer = class {
2130
2123
  this.fetchedAdDurations = /* @__PURE__ */ new Map();
2131
2124
  this.targetAdBreakDurationMs = null;
2132
2125
  this.isAdaptiveMode = false;
2126
+ this.failedVastUrls = /* @__PURE__ */ new Set();
2133
2127
  initializePolyfills();
2134
2128
  const browserOverrides = getBrowserConfigOverrides();
2135
2129
  this.config = { ...config, ...browserOverrides };
@@ -3109,6 +3103,7 @@ var StormcloudVideoPlayer = class {
3109
3103
  this.vastToMediaUrlMap.clear();
3110
3104
  this.preloadedMediaUrls.clear();
3111
3105
  this.preloadingMediaUrls.clear();
3106
+ this.failedVastUrls.clear();
3112
3107
  const currentMuted = this.video.muted;
3113
3108
  const currentVolume = this.video.volume;
3114
3109
  this.ima.updateOriginalMutedState(currentMuted, currentVolume);
@@ -3309,6 +3304,11 @@ var StormcloudVideoPlayer = class {
3309
3304
  if (this.ima.isAdPlaying()) {
3310
3305
  return;
3311
3306
  }
3307
+ if (this.failedVastUrls.has(vastTagUrl)) {
3308
+ console.warn("[AD-ERROR] Skipping already-failed VAST URL:", vastTagUrl.substring(0, 60));
3309
+ this.handleAdFailure();
3310
+ return;
3311
+ }
3312
3312
  const requestToken = ++this.adRequestTokenCounter;
3313
3313
  this.activeAdRequestToken = requestToken;
3314
3314
  this.startAdRequestWatchdog(requestToken);
@@ -3323,6 +3323,7 @@ var StormcloudVideoPlayer = class {
3323
3323
  await this.ima.play();
3324
3324
  } catch (playError) {
3325
3325
  console.error("[AD-ERROR] Failed to play ad:", playError);
3326
+ this.failedVastUrls.add(vastTagUrl);
3326
3327
  this.clearAdFailsafeTimer();
3327
3328
  if (this.activeAdRequestToken === requestToken) {
3328
3329
  this.activeAdRequestToken = null;
@@ -3332,6 +3333,7 @@ var StormcloudVideoPlayer = class {
3332
3333
  }
3333
3334
  } catch (error) {
3334
3335
  console.error("[AD-ERROR] Ad request failed:", error == null ? void 0 : error.message);
3336
+ this.failedVastUrls.add(vastTagUrl);
3335
3337
  this.clearAdRequestWatchdog();
3336
3338
  this.clearAdFailsafeTimer();
3337
3339
  if (this.activeAdRequestToken === requestToken) {
@@ -3376,7 +3378,8 @@ var StormcloudVideoPlayer = class {
3376
3378
  }
3377
3379
  handleAdFailure() {
3378
3380
  const remaining = this.getRemainingAdMs();
3379
- if (remaining > 500 && this.adPodQueue.length > 0) {
3381
+ const availableAds = this.adPodQueue.filter((url) => !this.failedVastUrls.has(url)).length;
3382
+ if (remaining > 500 && availableAds > 0) {
3380
3383
  if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
3381
3384
  console.log("[ADAPTIVE-POD] \u23F3 First ad failed, waiting for sequential preload to catch up...");
3382
3385
  setTimeout(() => {
@@ -3393,6 +3396,7 @@ var StormcloudVideoPlayer = class {
3393
3396
  return;
3394
3397
  }
3395
3398
  }
3399
+ console.error("[AD-ERROR] All ads failed or time expired. Failed URLs:", this.failedVastUrls.size);
3396
3400
  this.handleAdPodComplete();
3397
3401
  }
3398
3402
  tryNextAdWithRetry(retryCount) {
@@ -3824,6 +3828,12 @@ var StormcloudVideoPlayer = class {
3824
3828
  );
3825
3829
  }
3826
3830
  mediaUrls = await this.fetchAndParseVastXml(vastTagUrl);
3831
+ if (this.config.debugAdTiming) {
3832
+ console.log(
3833
+ `[StormcloudVideoPlayer] Extracted ${mediaUrls.length} media URLs:`,
3834
+ mediaUrls
3835
+ );
3836
+ }
3827
3837
  if (mediaUrls.length > 0) {
3828
3838
  this.vastToMediaUrlMap.set(vastTagUrl, mediaUrls);
3829
3839
  }
@@ -3848,6 +3858,10 @@ var StormcloudVideoPlayer = class {
3848
3858
  for (let i = 0; i < this.adPodQueue.length; i++) {
3849
3859
  const vastTagUrl = this.adPodQueue[i];
3850
3860
  if (!vastTagUrl) continue;
3861
+ if (this.failedVastUrls.has(vastTagUrl)) {
3862
+ console.warn("[AD-ERROR] Skipping failed URL in queue");
3863
+ continue;
3864
+ }
3851
3865
  const hasImaPreload = (_c = (_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, vastTagUrl)) != null ? _c : false;
3852
3866
  const mediaUrls = this.vastToMediaUrlMap.get(vastTagUrl);
3853
3867
  const hasMediaPreload = mediaUrls && mediaUrls.length > 0 ? this.preloadedMediaUrls.has(mediaUrls[0]) : false;