stormcloud-video-player 0.3.10 → 0.3.12

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.
@@ -3104,9 +3104,10 @@ var StormcloudVideoPlayer = class {
3104
3104
  }
3105
3105
  break;
3106
3106
  }
3107
- if (this.adRequestQueue.length > 0) {
3107
+ const maxQueueSize = 3;
3108
+ if (this.adRequestQueue.length >= maxQueueSize) {
3108
3109
  if (this.config.debugAdTiming) {
3109
- console.log(`[CONTINUOUS-FETCH] \u23F3 Already have ${this.adRequestQueue.length} ads queued, waiting...`);
3110
+ console.log(`[CONTINUOUS-FETCH] \u23F8\uFE0F Queue full (${this.adRequestQueue.length}), pausing fetching...`);
3110
3111
  }
3111
3112
  await new Promise((resolve) => setTimeout(resolve, 2e3));
3112
3113
  continue;
@@ -3117,7 +3118,7 @@ var StormcloudVideoPlayer = class {
3117
3118
  continue;
3118
3119
  }
3119
3120
  if (this.config.debugAdTiming) {
3120
- console.log("[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch additional ad...");
3121
+ console.log(`[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch ad (${this.successfulAdRequests.length + this.adRequestQueue.length + 1} total)...`);
3121
3122
  }
3122
3123
  try {
3123
3124
  const response = await fetch(newAdUrl, { mode: "cors" });
@@ -3137,17 +3138,17 @@ var StormcloudVideoPlayer = class {
3137
3138
  continue;
3138
3139
  }
3139
3140
  if (this.config.debugAdTiming) {
3140
- console.log("[CONTINUOUS-FETCH] \u2705 Successfully fetched new ad, adding to queue");
3141
+ console.log(`[CONTINUOUS-FETCH] \u2705 Successfully fetched ad, adding to queue (queue size: ${this.adRequestQueue.length + 1})`);
3141
3142
  }
3142
3143
  this.adRequestQueue.push(newAdUrl);
3143
3144
  this.totalAdsInBreak++;
3144
- await new Promise((resolve) => setTimeout(resolve, 2e3));
3145
+ await new Promise((resolve) => setTimeout(resolve, 500));
3145
3146
  } catch (error) {
3146
3147
  if (this.config.debugAdTiming) {
3147
3148
  console.log("[CONTINUOUS-FETCH] \u274C Ad fetch failed:", error.message);
3148
3149
  }
3149
3150
  this.failedVastUrls.add(newAdUrl);
3150
- await new Promise((resolve) => setTimeout(resolve, 3e3));
3151
+ await new Promise((resolve) => setTimeout(resolve, 2e3));
3151
3152
  }
3152
3153
  }
3153
3154
  if (this.config.debugAdTiming) {
@@ -3160,7 +3161,7 @@ var StormcloudVideoPlayer = class {
3160
3161
  console.log("[CONTINUOUS-FETCH] \u{1F6D1} Stopping continuous ad fetching");
3161
3162
  }
3162
3163
  }
3163
- async tryNextAvailableAd() {
3164
+ async tryNextAvailableAd(retryCount = 0) {
3164
3165
  const remaining = this.getRemainingAdMs();
3165
3166
  if (remaining <= 500) {
3166
3167
  if (this.config.debugAdTiming) {
@@ -3173,15 +3174,31 @@ var StormcloudVideoPlayer = class {
3173
3174
  const nextAdUrl = this.adRequestQueue.shift();
3174
3175
  if (nextAdUrl) {
3175
3176
  if (this.config.debugAdTiming) {
3176
- console.log("[CONTINUOUS-FETCH] \u{1F3AC} Playing next queued ad");
3177
+ console.log(`[CONTINUOUS-FETCH] \u{1F3AC} Playing next queued ad (${this.currentAdIndex + 1}/${this.totalAdsInBreak}, ${this.adRequestQueue.length} remaining in queue)`);
3178
+ }
3179
+ const currentMuted = this.video.muted;
3180
+ const currentVolume = this.video.volume;
3181
+ this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3182
+ if (this.config.debugAdTiming) {
3183
+ console.log(`[CONTINUOUS-FETCH] \u{1F50A} Updated ad audio state: muted=${currentMuted}, volume=${currentVolume}`);
3177
3184
  }
3178
3185
  this.currentAdIndex++;
3186
+ this.successfulAdRequests.push(nextAdUrl);
3179
3187
  await this.playSingleAd(nextAdUrl).catch(() => {
3180
- this.tryNextAvailableAd();
3188
+ this.tryNextAvailableAd(0);
3181
3189
  });
3182
3190
  return;
3183
3191
  }
3184
3192
  }
3193
+ const maxRetries = 5;
3194
+ if (this.continuousFetchingActive && retryCount < maxRetries && remaining > 2e3) {
3195
+ if (this.config.debugAdTiming) {
3196
+ console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting... (retry ${retryCount + 1}/${maxRetries})`);
3197
+ }
3198
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
3199
+ await this.tryNextAvailableAd(retryCount + 1);
3200
+ return;
3201
+ }
3185
3202
  if (!this.isShowingPlaceholder && remaining > 1e3) {
3186
3203
  this.showPlaceholderAndWaitForAds();
3187
3204
  } else {
@@ -3218,9 +3235,13 @@ var StormcloudVideoPlayer = class {
3218
3235
  this.isShowingPlaceholder = false;
3219
3236
  this.placeholderStartTimeMs = null;
3220
3237
  this.ima.hidePlaceholder();
3238
+ const currentMuted = this.video.muted;
3239
+ const currentVolume = this.video.volume;
3240
+ this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3221
3241
  const nextAdUrl = this.adRequestQueue.shift();
3222
3242
  if (nextAdUrl) {
3223
3243
  this.currentAdIndex++;
3244
+ this.successfulAdRequests.push(nextAdUrl);
3224
3245
  await this.playSingleAd(nextAdUrl).catch(() => {
3225
3246
  this.tryNextAvailableAd();
3226
3247
  });