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.
@@ -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,31 @@ 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)`);
3175
+ }
3176
+ const currentMuted = this.video.muted;
3177
+ const currentVolume = this.video.volume;
3178
+ this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3179
+ if (this.config.debugAdTiming) {
3180
+ console.log(`[CONTINUOUS-FETCH] \u{1F50A} Updated ad audio state: muted=${currentMuted}, volume=${currentVolume}`);
3174
3181
  }
3175
3182
  this.currentAdIndex++;
3183
+ this.successfulAdRequests.push(nextAdUrl);
3176
3184
  await this.playSingleAd(nextAdUrl).catch(() => {
3177
- this.tryNextAvailableAd();
3185
+ this.tryNextAvailableAd(0);
3178
3186
  });
3179
3187
  return;
3180
3188
  }
3181
3189
  }
3190
+ const maxRetries = 5;
3191
+ if (this.continuousFetchingActive && retryCount < maxRetries && remaining > 2e3) {
3192
+ if (this.config.debugAdTiming) {
3193
+ console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting... (retry ${retryCount + 1}/${maxRetries})`);
3194
+ }
3195
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
3196
+ await this.tryNextAvailableAd(retryCount + 1);
3197
+ return;
3198
+ }
3182
3199
  if (!this.isShowingPlaceholder && remaining > 1e3) {
3183
3200
  this.showPlaceholderAndWaitForAds();
3184
3201
  } else {
@@ -3215,9 +3232,13 @@ var StormcloudVideoPlayer = class {
3215
3232
  this.isShowingPlaceholder = false;
3216
3233
  this.placeholderStartTimeMs = null;
3217
3234
  this.ima.hidePlaceholder();
3235
+ const currentMuted = this.video.muted;
3236
+ const currentVolume = this.video.volume;
3237
+ this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3218
3238
  const nextAdUrl = this.adRequestQueue.shift();
3219
3239
  if (nextAdUrl) {
3220
3240
  this.currentAdIndex++;
3241
+ this.successfulAdRequests.push(nextAdUrl);
3221
3242
  await this.playSingleAd(nextAdUrl).catch(() => {
3222
3243
  this.tryNextAvailableAd();
3223
3244
  });