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.
package/lib/index.cjs CHANGED
@@ -1318,15 +1318,10 @@ function createHlsAdPlayer(contentVideo, options) {
1318
1318
  setAdPlayingFlag(false);
1319
1319
  emit("content_resume");
1320
1320
  setTimeout(() => {
1321
- const stillInPod = contentVideo.dataset.stormcloudAdPlaying === "true";
1322
- if (stillInPod) {
1323
- console.log(
1324
- "[HlsAdPlayer] Still in ad pod - keeping ad container visible (black screen)"
1325
- );
1326
- if (adContainerEl) {
1327
- adContainerEl.style.display = "flex";
1328
- adContainerEl.style.pointerEvents = "auto";
1329
- }
1321
+ if (!adPlaying && adContainerEl) {
1322
+ adContainerEl.style.display = "none";
1323
+ adContainerEl.style.pointerEvents = "none";
1324
+ console.log("[HlsAdPlayer] Ad container hidden after completion (waiting for next ad)");
1330
1325
  }
1331
1326
  }, 50);
1332
1327
  }
@@ -3182,7 +3177,7 @@ var StormcloudVideoPlayer = class {
3182
3177
  continue;
3183
3178
  }
3184
3179
  if (this.config.debugAdTiming) {
3185
- console.log(`[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch ad (${this.successfulAdRequests.length + this.adRequestQueue.length + 1} total)...`);
3180
+ 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)...`);
3186
3181
  }
3187
3182
  try {
3188
3183
  const response = await fetch(newAdUrl, { mode: "cors" });
@@ -3198,7 +3193,8 @@ var StormcloudVideoPlayer = class {
3198
3193
  console.log("[CONTINUOUS-FETCH] \u26A0\uFE0F VAST response has no media files, skipping");
3199
3194
  }
3200
3195
  this.failedVastUrls.add(newAdUrl);
3201
- await new Promise((resolve) => setTimeout(resolve, 1e3));
3196
+ const retryDelay = this.adRequestQueue.length > 0 ? 1e3 : 500;
3197
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
3202
3198
  continue;
3203
3199
  }
3204
3200
  if (this.config.debugAdTiming) {
@@ -3206,17 +3202,19 @@ var StormcloudVideoPlayer = class {
3206
3202
  }
3207
3203
  this.adRequestQueue.push(newAdUrl);
3208
3204
  this.totalAdsInBreak++;
3209
- await new Promise((resolve) => setTimeout(resolve, 500));
3205
+ const successDelay = this.adRequestQueue.length <= 1 ? 300 : 500;
3206
+ await new Promise((resolve) => setTimeout(resolve, successDelay));
3210
3207
  } catch (error) {
3211
3208
  if (this.config.debugAdTiming) {
3212
3209
  console.log("[CONTINUOUS-FETCH] \u274C Ad fetch failed:", error.message);
3213
3210
  }
3214
3211
  this.failedVastUrls.add(newAdUrl);
3215
- await new Promise((resolve) => setTimeout(resolve, 2e3));
3212
+ const retryDelay = this.adRequestQueue.length > 0 ? 2e3 : 1e3;
3213
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
3216
3214
  }
3217
3215
  }
3218
3216
  if (this.config.debugAdTiming) {
3219
- console.log("[CONTINUOUS-FETCH] \u{1F6D1} Continuous fetch loop ended");
3217
+ console.log(`[CONTINUOUS-FETCH] \u{1F6D1} Continuous fetch loop ended (fetched ${this.successfulAdRequests.length} ads, ${this.adRequestQueue.length} in queue)`);
3220
3218
  }
3221
3219
  }
3222
3220
  stopContinuousFetching() {
@@ -3254,20 +3252,27 @@ var StormcloudVideoPlayer = class {
3254
3252
  return;
3255
3253
  }
3256
3254
  }
3257
- const maxRetries = 5;
3258
- if (this.continuousFetchingActive && retryCount < maxRetries && remaining > 2e3) {
3255
+ const hasPlayedAtLeastOneAd = this.successfulAdRequests.length > 0;
3256
+ const maxRetries = hasPlayedAtLeastOneAd ? 10 : 5;
3257
+ const retryDelayMs = hasPlayedAtLeastOneAd ? 500 : 1e3;
3258
+ const minRemainingForRetry = 1e3;
3259
+ if (this.continuousFetchingActive && retryCount < maxRetries && remaining > minRemainingForRetry) {
3259
3260
  if (this.config.debugAdTiming) {
3260
- console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting... (retry ${retryCount + 1}/${maxRetries})`);
3261
+ console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting ${retryDelayMs}ms... (retry ${retryCount + 1}/${maxRetries}, remaining: ${remaining}ms)`);
3261
3262
  }
3262
- await new Promise((resolve) => setTimeout(resolve, 1e3));
3263
+ await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
3263
3264
  await this.tryNextAvailableAd(retryCount + 1);
3264
3265
  return;
3265
3266
  }
3266
- if (!this.isShowingPlaceholder && remaining > 1e3) {
3267
+ const minTimeForPlaceholder = 3e3;
3268
+ if (!this.isShowingPlaceholder && remaining >= minTimeForPlaceholder && this.continuousFetchingActive) {
3269
+ if (this.config.debugAdTiming) {
3270
+ console.log(`[CONTINUOUS-FETCH] \u2B1B Last resort: showing placeholder (${remaining}ms remaining)`);
3271
+ }
3267
3272
  this.showPlaceholderAndWaitForAds();
3268
3273
  } else {
3269
3274
  if (this.config.debugAdTiming) {
3270
- console.log("[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available, ending ad break");
3275
+ console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available or insufficient time remaining (${remaining}ms), ending ad break`);
3271
3276
  }
3272
3277
  this.handleAdPodComplete();
3273
3278
  }
@@ -3275,26 +3280,36 @@ var StormcloudVideoPlayer = class {
3275
3280
  async showPlaceholderAndWaitForAds() {
3276
3281
  const remaining = this.getRemainingAdMs();
3277
3282
  const waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
3278
- if (waitTime < 1e3) {
3283
+ if (waitTime < 3e3) {
3284
+ if (this.config.debugAdTiming) {
3285
+ console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F Insufficient time for placeholder (${waitTime}ms), ending ad break`);
3286
+ }
3279
3287
  this.handleAdPodComplete();
3280
3288
  return;
3281
3289
  }
3282
3290
  if (this.config.debugAdTiming) {
3283
- console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for ${waitTime}ms while waiting for ads`);
3291
+ console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for up to ${waitTime}ms while waiting for ads (last resort)`);
3284
3292
  }
3285
3293
  this.isShowingPlaceholder = true;
3286
3294
  this.placeholderStartTimeMs = Date.now();
3287
3295
  this.ima.showPlaceholder();
3288
- const checkInterval = 500;
3296
+ const checkInterval = 300;
3289
3297
  const maxChecks = Math.floor(waitTime / checkInterval);
3290
3298
  for (let i = 0; i < maxChecks; i++) {
3291
3299
  await new Promise((resolve) => setTimeout(resolve, checkInterval));
3292
3300
  if (!this.inAdBreak) {
3301
+ if (this.config.debugAdTiming) {
3302
+ console.log("[CONTINUOUS-FETCH] \u2139\uFE0F Ad break ended during placeholder wait");
3303
+ }
3304
+ this.isShowingPlaceholder = false;
3305
+ this.placeholderStartTimeMs = null;
3306
+ this.ima.hidePlaceholder();
3293
3307
  return;
3294
3308
  }
3295
3309
  if (this.adRequestQueue.length > 0) {
3310
+ const elapsedInPlaceholder = Date.now() - (this.placeholderStartTimeMs || Date.now());
3296
3311
  if (this.config.debugAdTiming) {
3297
- console.log("[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder");
3312
+ console.log(`[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder (after ${elapsedInPlaceholder}ms)`);
3298
3313
  }
3299
3314
  this.isShowingPlaceholder = false;
3300
3315
  this.placeholderStartTimeMs = null;
@@ -3313,8 +3328,9 @@ var StormcloudVideoPlayer = class {
3313
3328
  return;
3314
3329
  }
3315
3330
  }
3331
+ const totalPlaceholderTime = Date.now() - (this.placeholderStartTimeMs || Date.now());
3316
3332
  if (this.config.debugAdTiming) {
3317
- console.log("[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached, no ads fetched");
3333
+ console.log(`[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached after ${totalPlaceholderTime}ms, no ads fetched`);
3318
3334
  }
3319
3335
  this.isShowingPlaceholder = false;
3320
3336
  this.placeholderStartTimeMs = null;