stormcloud-video-player 0.3.11 → 0.3.13

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.
@@ -1251,15 +1251,10 @@ function createHlsAdPlayer(contentVideo, options) {
1251
1251
  setAdPlayingFlag(false);
1252
1252
  emit("content_resume");
1253
1253
  setTimeout(() => {
1254
- const stillInPod = contentVideo.dataset.stormcloudAdPlaying === "true";
1255
- if (stillInPod) {
1256
- console.log(
1257
- "[HlsAdPlayer] Still in ad pod - keeping ad container visible (black screen)"
1258
- );
1259
- if (adContainerEl) {
1260
- adContainerEl.style.display = "flex";
1261
- adContainerEl.style.pointerEvents = "auto";
1262
- }
1254
+ if (!adPlaying && adContainerEl) {
1255
+ adContainerEl.style.display = "none";
1256
+ adContainerEl.style.pointerEvents = "none";
1257
+ console.log("[HlsAdPlayer] Ad container hidden after completion (waiting for next ad)");
1263
1258
  }
1264
1259
  }, 50);
1265
1260
  }
@@ -3115,7 +3110,7 @@ var StormcloudVideoPlayer = class {
3115
3110
  continue;
3116
3111
  }
3117
3112
  if (this.config.debugAdTiming) {
3118
- console.log(`[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch ad (${this.successfulAdRequests.length + this.adRequestQueue.length + 1} total)...`);
3113
+ console.log(`[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch ad #${this.successfulAdRequests.length + this.adRequestQueue.length + 1} (queue: ${this.adRequestQueue.length}, remaining: ${Math.round(remaining / 1e3)}s)...`);
3119
3114
  }
3120
3115
  try {
3121
3116
  const response = await fetch(newAdUrl, { mode: "cors" });
@@ -3131,7 +3126,8 @@ var StormcloudVideoPlayer = class {
3131
3126
  console.log("[CONTINUOUS-FETCH] \u26A0\uFE0F VAST response has no media files, skipping");
3132
3127
  }
3133
3128
  this.failedVastUrls.add(newAdUrl);
3134
- await new Promise((resolve) => setTimeout(resolve, 1e3));
3129
+ const retryDelay = this.adRequestQueue.length > 0 ? 1e3 : 500;
3130
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
3135
3131
  continue;
3136
3132
  }
3137
3133
  if (this.config.debugAdTiming) {
@@ -3139,17 +3135,19 @@ var StormcloudVideoPlayer = class {
3139
3135
  }
3140
3136
  this.adRequestQueue.push(newAdUrl);
3141
3137
  this.totalAdsInBreak++;
3142
- await new Promise((resolve) => setTimeout(resolve, 500));
3138
+ const successDelay = this.adRequestQueue.length <= 1 ? 300 : 500;
3139
+ await new Promise((resolve) => setTimeout(resolve, successDelay));
3143
3140
  } catch (error) {
3144
3141
  if (this.config.debugAdTiming) {
3145
3142
  console.log("[CONTINUOUS-FETCH] \u274C Ad fetch failed:", error.message);
3146
3143
  }
3147
3144
  this.failedVastUrls.add(newAdUrl);
3148
- await new Promise((resolve) => setTimeout(resolve, 2e3));
3145
+ const retryDelay = this.adRequestQueue.length > 0 ? 2e3 : 1e3;
3146
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
3149
3147
  }
3150
3148
  }
3151
3149
  if (this.config.debugAdTiming) {
3152
- console.log("[CONTINUOUS-FETCH] \u{1F6D1} Continuous fetch loop ended");
3150
+ console.log(`[CONTINUOUS-FETCH] \u{1F6D1} Continuous fetch loop ended (fetched ${this.successfulAdRequests.length} ads, ${this.adRequestQueue.length} in queue)`);
3153
3151
  }
3154
3152
  }
3155
3153
  stopContinuousFetching() {
@@ -3173,6 +3171,12 @@ var StormcloudVideoPlayer = class {
3173
3171
  if (this.config.debugAdTiming) {
3174
3172
  console.log(`[CONTINUOUS-FETCH] \u{1F3AC} Playing next queued ad (${this.currentAdIndex + 1}/${this.totalAdsInBreak}, ${this.adRequestQueue.length} remaining in queue)`);
3175
3173
  }
3174
+ const currentMuted = this.video.muted;
3175
+ const currentVolume = this.video.volume;
3176
+ this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3177
+ if (this.config.debugAdTiming) {
3178
+ console.log(`[CONTINUOUS-FETCH] \u{1F50A} Updated ad audio state: muted=${currentMuted}, volume=${currentVolume}`);
3179
+ }
3176
3180
  this.currentAdIndex++;
3177
3181
  this.successfulAdRequests.push(nextAdUrl);
3178
3182
  await this.playSingleAd(nextAdUrl).catch(() => {
@@ -3181,20 +3185,27 @@ var StormcloudVideoPlayer = class {
3181
3185
  return;
3182
3186
  }
3183
3187
  }
3184
- const maxRetries = 5;
3185
- if (this.continuousFetchingActive && retryCount < maxRetries && remaining > 2e3) {
3188
+ const hasPlayedAtLeastOneAd = this.successfulAdRequests.length > 0;
3189
+ const maxRetries = hasPlayedAtLeastOneAd ? 10 : 5;
3190
+ const retryDelayMs = hasPlayedAtLeastOneAd ? 500 : 1e3;
3191
+ const minRemainingForRetry = 1e3;
3192
+ if (this.continuousFetchingActive && retryCount < maxRetries && remaining > minRemainingForRetry) {
3186
3193
  if (this.config.debugAdTiming) {
3187
- console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting... (retry ${retryCount + 1}/${maxRetries})`);
3194
+ console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting ${retryDelayMs}ms... (retry ${retryCount + 1}/${maxRetries}, remaining: ${remaining}ms)`);
3188
3195
  }
3189
- await new Promise((resolve) => setTimeout(resolve, 1e3));
3196
+ await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
3190
3197
  await this.tryNextAvailableAd(retryCount + 1);
3191
3198
  return;
3192
3199
  }
3193
- if (!this.isShowingPlaceholder && remaining > 1e3) {
3200
+ const minTimeForPlaceholder = 3e3;
3201
+ if (!this.isShowingPlaceholder && remaining >= minTimeForPlaceholder && this.continuousFetchingActive) {
3202
+ if (this.config.debugAdTiming) {
3203
+ console.log(`[CONTINUOUS-FETCH] \u2B1B Last resort: showing placeholder (${remaining}ms remaining)`);
3204
+ }
3194
3205
  this.showPlaceholderAndWaitForAds();
3195
3206
  } else {
3196
3207
  if (this.config.debugAdTiming) {
3197
- console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available, ending ad break");
3208
+ console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available or insufficient time remaining (${remaining}ms), ending ad break`);
3198
3209
  }
3199
3210
  this.handleAdPodComplete();
3200
3211
  }
@@ -3202,33 +3213,47 @@ var StormcloudVideoPlayer = class {
3202
3213
  async showPlaceholderAndWaitForAds() {
3203
3214
  const remaining = this.getRemainingAdMs();
3204
3215
  const waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
3205
- if (waitTime < 1e3) {
3216
+ if (waitTime < 3e3) {
3217
+ if (this.config.debugAdTiming) {
3218
+ console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F Insufficient time for placeholder (${waitTime}ms), ending ad break`);
3219
+ }
3206
3220
  this.handleAdPodComplete();
3207
3221
  return;
3208
3222
  }
3209
3223
  if (this.config.debugAdTiming) {
3210
- console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for ${waitTime}ms while waiting for ads`);
3224
+ console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for up to ${waitTime}ms while waiting for ads (last resort)`);
3211
3225
  }
3212
3226
  this.isShowingPlaceholder = true;
3213
3227
  this.placeholderStartTimeMs = Date.now();
3214
3228
  this.ima.showPlaceholder();
3215
- const checkInterval = 500;
3229
+ const checkInterval = 300;
3216
3230
  const maxChecks = Math.floor(waitTime / checkInterval);
3217
3231
  for (let i = 0; i < maxChecks; i++) {
3218
3232
  await new Promise((resolve) => setTimeout(resolve, checkInterval));
3219
3233
  if (!this.inAdBreak) {
3234
+ if (this.config.debugAdTiming) {
3235
+ console.log("[CONTINUOUS-FETCH] \u2139\uFE0F Ad break ended during placeholder wait");
3236
+ }
3237
+ this.isShowingPlaceholder = false;
3238
+ this.placeholderStartTimeMs = null;
3239
+ this.ima.hidePlaceholder();
3220
3240
  return;
3221
3241
  }
3222
3242
  if (this.adRequestQueue.length > 0) {
3243
+ const elapsedInPlaceholder = Date.now() - (this.placeholderStartTimeMs || Date.now());
3223
3244
  if (this.config.debugAdTiming) {
3224
- console.log("[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder");
3245
+ console.log(`[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder (after ${elapsedInPlaceholder}ms)`);
3225
3246
  }
3226
3247
  this.isShowingPlaceholder = false;
3227
3248
  this.placeholderStartTimeMs = null;
3228
3249
  this.ima.hidePlaceholder();
3250
+ const currentMuted = this.video.muted;
3251
+ const currentVolume = this.video.volume;
3252
+ this.ima.updateOriginalMutedState(currentMuted, currentVolume);
3229
3253
  const nextAdUrl = this.adRequestQueue.shift();
3230
3254
  if (nextAdUrl) {
3231
3255
  this.currentAdIndex++;
3256
+ this.successfulAdRequests.push(nextAdUrl);
3232
3257
  await this.playSingleAd(nextAdUrl).catch(() => {
3233
3258
  this.tryNextAvailableAd();
3234
3259
  });
@@ -3236,8 +3261,9 @@ var StormcloudVideoPlayer = class {
3236
3261
  return;
3237
3262
  }
3238
3263
  }
3264
+ const totalPlaceholderTime = Date.now() - (this.placeholderStartTimeMs || Date.now());
3239
3265
  if (this.config.debugAdTiming) {
3240
- console.log("[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached, no ads fetched");
3266
+ console.log(`[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached after ${totalPlaceholderTime}ms, no ads fetched`);
3241
3267
  }
3242
3268
  this.isShowingPlaceholder = false;
3243
3269
  this.placeholderStartTimeMs = null;