stormcloud-video-player 0.3.10 → 0.3.11

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.
@@ -3101,9 +3101,10 @@ var StormcloudVideoPlayer = class {
3101
3101
  }
3102
3102
  break;
3103
3103
  }
3104
- if (this.adRequestQueue.length > 0) {
3104
+ const maxQueueSize = 3;
3105
+ if (this.adRequestQueue.length >= maxQueueSize) {
3105
3106
  if (this.config.debugAdTiming) {
3106
- console.log(`[CONTINUOUS-FETCH] \u23F3 Already have ${this.adRequestQueue.length} ads queued, waiting...`);
3107
+ console.log(`[CONTINUOUS-FETCH] \u23F8\uFE0F Queue full (${this.adRequestQueue.length}), pausing fetching...`);
3107
3108
  }
3108
3109
  await new Promise((resolve) => setTimeout(resolve, 2e3));
3109
3110
  continue;
@@ -3114,7 +3115,7 @@ var StormcloudVideoPlayer = class {
3114
3115
  continue;
3115
3116
  }
3116
3117
  if (this.config.debugAdTiming) {
3117
- console.log("[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch additional ad...");
3118
+ console.log(`[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch ad (${this.successfulAdRequests.length + this.adRequestQueue.length + 1} total)...`);
3118
3119
  }
3119
3120
  try {
3120
3121
  const response = await fetch(newAdUrl, { mode: "cors" });
@@ -3134,17 +3135,17 @@ var StormcloudVideoPlayer = class {
3134
3135
  continue;
3135
3136
  }
3136
3137
  if (this.config.debugAdTiming) {
3137
- console.log("[CONTINUOUS-FETCH] \u2705 Successfully fetched new ad, adding to queue");
3138
+ console.log(`[CONTINUOUS-FETCH] \u2705 Successfully fetched ad, adding to queue (queue size: ${this.adRequestQueue.length + 1})`);
3138
3139
  }
3139
3140
  this.adRequestQueue.push(newAdUrl);
3140
3141
  this.totalAdsInBreak++;
3141
- await new Promise((resolve) => setTimeout(resolve, 2e3));
3142
+ await new Promise((resolve) => setTimeout(resolve, 500));
3142
3143
  } catch (error) {
3143
3144
  if (this.config.debugAdTiming) {
3144
3145
  console.log("[CONTINUOUS-FETCH] \u274C Ad fetch failed:", error.message);
3145
3146
  }
3146
3147
  this.failedVastUrls.add(newAdUrl);
3147
- await new Promise((resolve) => setTimeout(resolve, 3e3));
3148
+ await new Promise((resolve) => setTimeout(resolve, 2e3));
3148
3149
  }
3149
3150
  }
3150
3151
  if (this.config.debugAdTiming) {
@@ -3157,7 +3158,7 @@ var StormcloudVideoPlayer = class {
3157
3158
  console.log("[CONTINUOUS-FETCH] \u{1F6D1} Stopping continuous ad fetching");
3158
3159
  }
3159
3160
  }
3160
- async tryNextAvailableAd() {
3161
+ async tryNextAvailableAd(retryCount = 0) {
3161
3162
  const remaining = this.getRemainingAdMs();
3162
3163
  if (remaining <= 500) {
3163
3164
  if (this.config.debugAdTiming) {
@@ -3170,15 +3171,25 @@ var StormcloudVideoPlayer = class {
3170
3171
  const nextAdUrl = this.adRequestQueue.shift();
3171
3172
  if (nextAdUrl) {
3172
3173
  if (this.config.debugAdTiming) {
3173
- console.log("[CONTINUOUS-FETCH] \u{1F3AC} Playing next queued ad");
3174
+ console.log(`[CONTINUOUS-FETCH] \u{1F3AC} Playing next queued ad (${this.currentAdIndex + 1}/${this.totalAdsInBreak}, ${this.adRequestQueue.length} remaining in queue)`);
3174
3175
  }
3175
3176
  this.currentAdIndex++;
3177
+ this.successfulAdRequests.push(nextAdUrl);
3176
3178
  await this.playSingleAd(nextAdUrl).catch(() => {
3177
- this.tryNextAvailableAd();
3179
+ this.tryNextAvailableAd(0);
3178
3180
  });
3179
3181
  return;
3180
3182
  }
3181
3183
  }
3184
+ const maxRetries = 5;
3185
+ if (this.continuousFetchingActive && retryCount < maxRetries && remaining > 2e3) {
3186
+ if (this.config.debugAdTiming) {
3187
+ console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting... (retry ${retryCount + 1}/${maxRetries})`);
3188
+ }
3189
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
3190
+ await this.tryNextAvailableAd(retryCount + 1);
3191
+ return;
3192
+ }
3182
3193
  if (!this.isShowingPlaceholder && remaining > 1e3) {
3183
3194
  this.showPlaceholderAndWaitForAds();
3184
3195
  } else {