stormcloud-video-player 0.3.12 → 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() {
@@ -3187,20 +3185,27 @@ var StormcloudVideoPlayer = class {
3187
3185
  return;
3188
3186
  }
3189
3187
  }
3190
- const maxRetries = 5;
3191
- 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) {
3192
3193
  if (this.config.debugAdTiming) {
3193
- 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)`);
3194
3195
  }
3195
- await new Promise((resolve) => setTimeout(resolve, 1e3));
3196
+ await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
3196
3197
  await this.tryNextAvailableAd(retryCount + 1);
3197
3198
  return;
3198
3199
  }
3199
- 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
+ }
3200
3205
  this.showPlaceholderAndWaitForAds();
3201
3206
  } else {
3202
3207
  if (this.config.debugAdTiming) {
3203
- 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`);
3204
3209
  }
3205
3210
  this.handleAdPodComplete();
3206
3211
  }
@@ -3208,26 +3213,36 @@ var StormcloudVideoPlayer = class {
3208
3213
  async showPlaceholderAndWaitForAds() {
3209
3214
  const remaining = this.getRemainingAdMs();
3210
3215
  const waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
3211
- 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
+ }
3212
3220
  this.handleAdPodComplete();
3213
3221
  return;
3214
3222
  }
3215
3223
  if (this.config.debugAdTiming) {
3216
- 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)`);
3217
3225
  }
3218
3226
  this.isShowingPlaceholder = true;
3219
3227
  this.placeholderStartTimeMs = Date.now();
3220
3228
  this.ima.showPlaceholder();
3221
- const checkInterval = 500;
3229
+ const checkInterval = 300;
3222
3230
  const maxChecks = Math.floor(waitTime / checkInterval);
3223
3231
  for (let i = 0; i < maxChecks; i++) {
3224
3232
  await new Promise((resolve) => setTimeout(resolve, checkInterval));
3225
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();
3226
3240
  return;
3227
3241
  }
3228
3242
  if (this.adRequestQueue.length > 0) {
3243
+ const elapsedInPlaceholder = Date.now() - (this.placeholderStartTimeMs || Date.now());
3229
3244
  if (this.config.debugAdTiming) {
3230
- 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)`);
3231
3246
  }
3232
3247
  this.isShowingPlaceholder = false;
3233
3248
  this.placeholderStartTimeMs = null;
@@ -3246,8 +3261,9 @@ var StormcloudVideoPlayer = class {
3246
3261
  return;
3247
3262
  }
3248
3263
  }
3264
+ const totalPlaceholderTime = Date.now() - (this.placeholderStartTimeMs || Date.now());
3249
3265
  if (this.config.debugAdTiming) {
3250
- 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`);
3251
3267
  }
3252
3268
  this.isShowingPlaceholder = false;
3253
3269
  this.placeholderStartTimeMs = null;