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.
@@ -1293,15 +1293,10 @@ function createHlsAdPlayer(contentVideo, options) {
1293
1293
  setAdPlayingFlag(false);
1294
1294
  emit("content_resume");
1295
1295
  setTimeout(() => {
1296
- const stillInPod = contentVideo.dataset.stormcloudAdPlaying === "true";
1297
- if (stillInPod) {
1298
- console.log(
1299
- "[HlsAdPlayer] Still in ad pod - keeping ad container visible (black screen)"
1300
- );
1301
- if (adContainerEl) {
1302
- adContainerEl.style.display = "flex";
1303
- adContainerEl.style.pointerEvents = "auto";
1304
- }
1296
+ if (!adPlaying && adContainerEl) {
1297
+ adContainerEl.style.display = "none";
1298
+ adContainerEl.style.pointerEvents = "none";
1299
+ console.log("[HlsAdPlayer] Ad container hidden after completion (waiting for next ad)");
1305
1300
  }
1306
1301
  }, 50);
1307
1302
  }
@@ -3157,7 +3152,7 @@ var StormcloudVideoPlayer = class {
3157
3152
  continue;
3158
3153
  }
3159
3154
  if (this.config.debugAdTiming) {
3160
- console.log(`[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch ad (${this.successfulAdRequests.length + this.adRequestQueue.length + 1} total)...`);
3155
+ 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)...`);
3161
3156
  }
3162
3157
  try {
3163
3158
  const response = await fetch(newAdUrl, { mode: "cors" });
@@ -3173,7 +3168,8 @@ var StormcloudVideoPlayer = class {
3173
3168
  console.log("[CONTINUOUS-FETCH] \u26A0\uFE0F VAST response has no media files, skipping");
3174
3169
  }
3175
3170
  this.failedVastUrls.add(newAdUrl);
3176
- await new Promise((resolve) => setTimeout(resolve, 1e3));
3171
+ const retryDelay = this.adRequestQueue.length > 0 ? 1e3 : 500;
3172
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
3177
3173
  continue;
3178
3174
  }
3179
3175
  if (this.config.debugAdTiming) {
@@ -3181,17 +3177,19 @@ var StormcloudVideoPlayer = class {
3181
3177
  }
3182
3178
  this.adRequestQueue.push(newAdUrl);
3183
3179
  this.totalAdsInBreak++;
3184
- await new Promise((resolve) => setTimeout(resolve, 500));
3180
+ const successDelay = this.adRequestQueue.length <= 1 ? 300 : 500;
3181
+ await new Promise((resolve) => setTimeout(resolve, successDelay));
3185
3182
  } catch (error) {
3186
3183
  if (this.config.debugAdTiming) {
3187
3184
  console.log("[CONTINUOUS-FETCH] \u274C Ad fetch failed:", error.message);
3188
3185
  }
3189
3186
  this.failedVastUrls.add(newAdUrl);
3190
- await new Promise((resolve) => setTimeout(resolve, 2e3));
3187
+ const retryDelay = this.adRequestQueue.length > 0 ? 2e3 : 1e3;
3188
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
3191
3189
  }
3192
3190
  }
3193
3191
  if (this.config.debugAdTiming) {
3194
- console.log("[CONTINUOUS-FETCH] \u{1F6D1} Continuous fetch loop ended");
3192
+ console.log(`[CONTINUOUS-FETCH] \u{1F6D1} Continuous fetch loop ended (fetched ${this.successfulAdRequests.length} ads, ${this.adRequestQueue.length} in queue)`);
3195
3193
  }
3196
3194
  }
3197
3195
  stopContinuousFetching() {
@@ -3229,20 +3227,27 @@ var StormcloudVideoPlayer = class {
3229
3227
  return;
3230
3228
  }
3231
3229
  }
3232
- const maxRetries = 5;
3233
- if (this.continuousFetchingActive && retryCount < maxRetries && remaining > 2e3) {
3230
+ const hasPlayedAtLeastOneAd = this.successfulAdRequests.length > 0;
3231
+ const maxRetries = hasPlayedAtLeastOneAd ? 10 : 5;
3232
+ const retryDelayMs = hasPlayedAtLeastOneAd ? 500 : 1e3;
3233
+ const minRemainingForRetry = 1e3;
3234
+ if (this.continuousFetchingActive && retryCount < maxRetries && remaining > minRemainingForRetry) {
3234
3235
  if (this.config.debugAdTiming) {
3235
- console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting... (retry ${retryCount + 1}/${maxRetries})`);
3236
+ console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting ${retryDelayMs}ms... (retry ${retryCount + 1}/${maxRetries}, remaining: ${remaining}ms)`);
3236
3237
  }
3237
- await new Promise((resolve) => setTimeout(resolve, 1e3));
3238
+ await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
3238
3239
  await this.tryNextAvailableAd(retryCount + 1);
3239
3240
  return;
3240
3241
  }
3241
- if (!this.isShowingPlaceholder && remaining > 1e3) {
3242
+ const minTimeForPlaceholder = 3e3;
3243
+ if (!this.isShowingPlaceholder && remaining >= minTimeForPlaceholder && this.continuousFetchingActive) {
3244
+ if (this.config.debugAdTiming) {
3245
+ console.log(`[CONTINUOUS-FETCH] \u2B1B Last resort: showing placeholder (${remaining}ms remaining)`);
3246
+ }
3242
3247
  this.showPlaceholderAndWaitForAds();
3243
3248
  } else {
3244
3249
  if (this.config.debugAdTiming) {
3245
- console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available, ending ad break");
3250
+ console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available or insufficient time remaining (${remaining}ms), ending ad break`);
3246
3251
  }
3247
3252
  this.handleAdPodComplete();
3248
3253
  }
@@ -3250,26 +3255,36 @@ var StormcloudVideoPlayer = class {
3250
3255
  async showPlaceholderAndWaitForAds() {
3251
3256
  const remaining = this.getRemainingAdMs();
3252
3257
  const waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
3253
- if (waitTime < 1e3) {
3258
+ if (waitTime < 3e3) {
3259
+ if (this.config.debugAdTiming) {
3260
+ console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F Insufficient time for placeholder (${waitTime}ms), ending ad break`);
3261
+ }
3254
3262
  this.handleAdPodComplete();
3255
3263
  return;
3256
3264
  }
3257
3265
  if (this.config.debugAdTiming) {
3258
- console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for ${waitTime}ms while waiting for ads`);
3266
+ console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for up to ${waitTime}ms while waiting for ads (last resort)`);
3259
3267
  }
3260
3268
  this.isShowingPlaceholder = true;
3261
3269
  this.placeholderStartTimeMs = Date.now();
3262
3270
  this.ima.showPlaceholder();
3263
- const checkInterval = 500;
3271
+ const checkInterval = 300;
3264
3272
  const maxChecks = Math.floor(waitTime / checkInterval);
3265
3273
  for (let i = 0; i < maxChecks; i++) {
3266
3274
  await new Promise((resolve) => setTimeout(resolve, checkInterval));
3267
3275
  if (!this.inAdBreak) {
3276
+ if (this.config.debugAdTiming) {
3277
+ console.log("[CONTINUOUS-FETCH] \u2139\uFE0F Ad break ended during placeholder wait");
3278
+ }
3279
+ this.isShowingPlaceholder = false;
3280
+ this.placeholderStartTimeMs = null;
3281
+ this.ima.hidePlaceholder();
3268
3282
  return;
3269
3283
  }
3270
3284
  if (this.adRequestQueue.length > 0) {
3285
+ const elapsedInPlaceholder = Date.now() - (this.placeholderStartTimeMs || Date.now());
3271
3286
  if (this.config.debugAdTiming) {
3272
- console.log("[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder");
3287
+ console.log(`[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder (after ${elapsedInPlaceholder}ms)`);
3273
3288
  }
3274
3289
  this.isShowingPlaceholder = false;
3275
3290
  this.placeholderStartTimeMs = null;
@@ -3288,8 +3303,9 @@ var StormcloudVideoPlayer = class {
3288
3303
  return;
3289
3304
  }
3290
3305
  }
3306
+ const totalPlaceholderTime = Date.now() - (this.placeholderStartTimeMs || Date.now());
3291
3307
  if (this.config.debugAdTiming) {
3292
- console.log("[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached, no ads fetched");
3308
+ console.log(`[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached after ${totalPlaceholderTime}ms, no ads fetched`);
3293
3309
  }
3294
3310
  this.isShowingPlaceholder = false;
3295
3311
  this.placeholderStartTimeMs = null;