stormcloud-video-player 0.2.20 → 0.2.22

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
@@ -391,11 +391,12 @@ function createImaController(video, options) {
391
391
  container.style.top = "0";
392
392
  container.style.right = "0";
393
393
  container.style.bottom = "0";
394
- container.style.display = "flex";
394
+ container.style.display = "none";
395
395
  container.style.alignItems = "center";
396
396
  container.style.justifyContent = "center";
397
397
  container.style.pointerEvents = "none";
398
- container.style.zIndex = "2";
398
+ container.style.zIndex = "10";
399
+ container.style.backgroundColor = "#000";
399
400
  (_a = video.parentElement) == null ? void 0 : _a.appendChild(container);
400
401
  adContainerEl = container;
401
402
  adDisplayContainer = new google.ima.AdDisplayContainer(
@@ -465,7 +466,8 @@ function createImaController(video, options) {
465
466
  container.style.alignItems = "center";
466
467
  container.style.justifyContent = "center";
467
468
  container.style.pointerEvents = "none";
468
- container.style.zIndex = "2";
469
+ container.style.zIndex = "10";
470
+ container.style.backgroundColor = "#000";
469
471
  if (!video.parentElement) {
470
472
  throw new Error("Video element has no parent for ad container");
471
473
  }
@@ -563,7 +565,9 @@ function createImaController(video, options) {
563
565
  adsManager.addEventListener(
564
566
  AdEvent.CONTENT_PAUSE_REQUESTED,
565
567
  () => {
566
- console.log("[IMA] Content pause requested");
568
+ console.log(
569
+ "[IMA] Content pause requested - FORCE MUTING main video"
570
+ );
567
571
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
568
572
  video.pause();
569
573
  console.log("[IMA] Video paused (VOD mode)");
@@ -573,14 +577,19 @@ function createImaController(video, options) {
573
577
  );
574
578
  }
575
579
  video.muted = true;
580
+ video.volume = 0;
576
581
  adPlaying = true;
577
582
  setAdPlayingFlag(true);
578
583
  emit("content_pause");
579
584
  }
580
585
  );
581
586
  adsManager.addEventListener(AdEvent.STARTED, () => {
582
- console.log("[IMA] Ad started playing");
587
+ console.log(
588
+ "[IMA] Ad started playing - FORCE MUTING main video"
589
+ );
583
590
  setAdPlayingFlag(true);
591
+ video.muted = true;
592
+ video.volume = 0;
584
593
  if (adContainerEl) {
585
594
  adContainerEl.style.pointerEvents = "auto";
586
595
  adContainerEl.style.display = "flex";
@@ -596,63 +605,12 @@ function createImaController(video, options) {
596
605
  adPlaying = false;
597
606
  setAdPlayingFlag(false);
598
607
  emit("content_resume");
599
- setTimeout(() => {
600
- var _a;
601
- const stillInAdPod = video.dataset.stormcloudAdPlaying === "true";
602
- if (stillInAdPod) {
603
- console.log(
604
- "[IMA] Next ad started - keeping content muted/paused and ad container visible"
605
- );
606
- if (adContainerEl) {
607
- adContainerEl.style.display = "flex";
608
- adContainerEl.style.pointerEvents = "auto";
609
- }
610
- return;
611
- }
612
- console.log("[IMA] No next ad - resuming content");
613
- video.muted = originalMutedState;
614
- if (adContainerEl) {
615
- adContainerEl.style.pointerEvents = "none";
616
- adContainerEl.style.display = "none";
617
- console.log(
618
- "[IMA] Ad container hidden - pointer events disabled"
619
- );
620
- }
621
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
622
- (_a = video.play()) == null ? void 0 : _a.catch(() => {
623
- });
624
- console.log("[IMA] Video resumed (VOD mode)");
625
- } else {
626
- console.log(
627
- "[IMA] Video unmuted (Live mode - was never paused)"
628
- );
629
- }
630
- }, 100);
631
608
  }
632
609
  );
633
610
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
634
- console.log("[IMA] All ads completed");
611
+ console.log("[IMA] All ads completed - notifying parent");
635
612
  adPlaying = false;
636
- video.muted = originalMutedState;
637
613
  setAdPlayingFlag(false);
638
- if (adContainerEl) {
639
- adContainerEl.style.pointerEvents = "none";
640
- adContainerEl.style.display = "none";
641
- console.log(
642
- "[IMA] Ad container hidden after all ads completed"
643
- );
644
- }
645
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
646
- video.play().catch(() => {
647
- });
648
- console.log(
649
- "[IMA] Video resumed after all ads completed (VOD mode)"
650
- );
651
- } else {
652
- console.log(
653
- "[IMA] Video unmuted after all ads completed (Live mode)"
654
- );
655
- }
656
614
  emit("all_ads_completed");
657
615
  });
658
616
  console.log("[IMA] Ads manager event listeners attached");
@@ -775,8 +733,8 @@ function createImaController(video, options) {
775
733
  },
776
734
  async stop() {
777
735
  var _a;
736
+ console.log("[IMA] Stopping ad playback");
778
737
  adPlaying = false;
779
- video.muted = originalMutedState;
780
738
  setAdPlayingFlag(false);
781
739
  if (adContainerEl) {
782
740
  adContainerEl.style.pointerEvents = "none";
@@ -788,13 +746,6 @@ function createImaController(video, options) {
788
746
  } catch {
789
747
  }
790
748
  destroyAdsManager();
791
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
792
- video.play().catch(() => {
793
- });
794
- console.log("[IMA] Video resumed after stop (VOD mode)");
795
- } else {
796
- console.log("[IMA] Video unmuted after stop (Live mode)");
797
- }
798
749
  },
799
750
  destroy() {
800
751
  var _a;
@@ -1203,37 +1154,6 @@ function createHlsAdPlayer(contentVideo, options) {
1203
1154
  adPlaying = false;
1204
1155
  setAdPlayingFlag(false);
1205
1156
  emit("content_resume");
1206
- emit("all_ads_completed");
1207
- setTimeout(() => {
1208
- const stillInAdPod = contentVideo.dataset.stormcloudAdPlaying === "true";
1209
- if (stillInAdPod) {
1210
- console.log(
1211
- "[HlsAdPlayer] Next ad started - keeping content muted/paused and ad container visible"
1212
- );
1213
- if (adContainerEl) {
1214
- adContainerEl.style.display = "flex";
1215
- adContainerEl.style.pointerEvents = "auto";
1216
- }
1217
- return;
1218
- }
1219
- console.log("[HlsAdPlayer] No next ad - resuming content");
1220
- const previousMutedState = contentVideo.muted;
1221
- contentVideo.muted = originalMutedState;
1222
- console.log(
1223
- `[HlsAdPlayer] Restored mute state: ${previousMutedState} -> ${originalMutedState}`
1224
- );
1225
- if (adContainerEl) {
1226
- adContainerEl.style.display = "none";
1227
- adContainerEl.style.pointerEvents = "none";
1228
- }
1229
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1230
- contentVideo.play().catch(() => {
1231
- });
1232
- console.log("[HlsAdPlayer] Content resumed (VOD mode)");
1233
- } else {
1234
- console.log("[HlsAdPlayer] Content unmuted (Live mode)");
1235
- }
1236
- }, 100);
1237
1157
  }
1238
1158
  function handleAdError() {
1239
1159
  console.log("[HlsAdPlayer] Handling ad error");
@@ -1271,7 +1191,7 @@ function createHlsAdPlayer(contentVideo, options) {
1271
1191
  container.style.alignItems = "center";
1272
1192
  container.style.justifyContent = "center";
1273
1193
  container.style.pointerEvents = "none";
1274
- container.style.zIndex = "2";
1194
+ container.style.zIndex = "10";
1275
1195
  container.style.backgroundColor = "#000";
1276
1196
  (_a = contentVideo.parentElement) == null ? void 0 : _a.appendChild(container);
1277
1197
  adContainerEl = container;
@@ -1345,7 +1265,9 @@ function createHlsAdPlayer(contentVideo, options) {
1345
1265
  } else {
1346
1266
  console.log("[HlsAdPlayer] Content continues (Live mode)");
1347
1267
  }
1268
+ console.log("[HlsAdPlayer] FORCE MUTING main video");
1348
1269
  contentVideo.muted = true;
1270
+ contentVideo.volume = 0;
1349
1271
  adPlaying = true;
1350
1272
  setAdPlayingFlag(true);
1351
1273
  if (adVideoElement) {
@@ -1409,7 +1331,6 @@ function createHlsAdPlayer(contentVideo, options) {
1409
1331
  console.log("[HlsAdPlayer] Stopping ad");
1410
1332
  adPlaying = false;
1411
1333
  setAdPlayingFlag(false);
1412
- contentVideo.muted = originalMutedState;
1413
1334
  if (adContainerEl) {
1414
1335
  adContainerEl.style.display = "none";
1415
1336
  adContainerEl.style.pointerEvents = "none";
@@ -1422,10 +1343,6 @@ function createHlsAdPlayer(contentVideo, options) {
1422
1343
  adVideoElement.pause();
1423
1344
  adVideoElement.src = "";
1424
1345
  }
1425
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1426
- contentVideo.play().catch(() => {
1427
- });
1428
- }
1429
1346
  currentAd = void 0;
1430
1347
  },
1431
1348
  destroy() {
@@ -1971,7 +1888,6 @@ var StormcloudVideoPlayer = class {
1971
1888
  this.bufferedSegmentsCount = 0;
1972
1889
  this.shouldAutoplayAfterBuffering = false;
1973
1890
  this.hasInitialBufferCompleted = false;
1974
- this.isTransitioningBetweenAds = false;
1975
1891
  initializePolyfills();
1976
1892
  const browserOverrides = getBrowserConfigOverrides();
1977
1893
  this.config = { ...config, ...browserOverrides };
@@ -2235,9 +2151,12 @@ var StormcloudVideoPlayer = class {
2235
2151
  this.ima.on("all_ads_completed", () => {
2236
2152
  if (this.config.debugAdTiming) {
2237
2153
  console.log(
2238
- "[StormcloudVideoPlayer] IMA all_ads_completed event received"
2154
+ "[StormcloudVideoPlayer] IMA all_ads_completed event received - ending ad break"
2239
2155
  );
2240
2156
  }
2157
+ if (this.inAdBreak) {
2158
+ this.handleAdPodComplete();
2159
+ }
2241
2160
  });
2242
2161
  this.ima.on("ad_error", () => {
2243
2162
  if (this.config.debugAdTiming) {
@@ -2276,57 +2195,43 @@ var StormcloudVideoPlayer = class {
2276
2195
  "[StormcloudVideoPlayer] IMA content_resume event received",
2277
2196
  {
2278
2197
  inAdBreak: this.inAdBreak,
2279
- isTransitioningBetweenAds: this.isTransitioningBetweenAds,
2280
2198
  pendingAds: this.adPodQueue.length
2281
2199
  }
2282
2200
  );
2283
2201
  }
2284
2202
  this.clearAdFailsafeTimer();
2285
- if (this.isTransitioningBetweenAds) {
2286
- if (this.config.debugAdTiming) {
2287
- console.log(
2288
- "[StormcloudVideoPlayer] Transitioning between ads - keeping content muted/paused"
2289
- );
2290
- }
2291
- return;
2292
- }
2293
2203
  if (!this.inAdBreak) {
2294
2204
  if (this.config.debugAdTiming) {
2295
2205
  console.log(
2296
- "[StormcloudVideoPlayer] Not in ad break, allowing normal content resume"
2206
+ "[StormcloudVideoPlayer] Not in ad break - this shouldn't happen during pod"
2297
2207
  );
2298
2208
  }
2299
2209
  return;
2300
2210
  }
2301
2211
  const remaining = this.getRemainingAdMs();
2302
2212
  if (remaining > 500 && this.adPodQueue.length > 0) {
2303
- this.isTransitioningBetweenAds = true;
2304
- this.video.muted = true;
2305
- if (!this.shouldContinueLiveStreamDuringAds()) {
2306
- this.video.pause();
2307
- }
2308
2213
  const next = this.adPodQueue.shift();
2309
2214
  this.currentAdIndex++;
2310
2215
  if (this.config.debugAdTiming) {
2311
2216
  console.log(
2312
- `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - keeping content muted/paused`
2217
+ `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - main video stays muted, ad layer stays visible`
2313
2218
  );
2314
2219
  }
2315
2220
  this.playSingleAd(next).catch(() => {
2316
- }).finally(() => {
2317
- this.isTransitioningBetweenAds = false;
2221
+ if (this.config.debugAdTiming) {
2222
+ console.error(
2223
+ "[StormcloudVideoPlayer] Failed to play next ad in pod"
2224
+ );
2225
+ }
2226
+ this.handleAdPodComplete();
2318
2227
  });
2319
2228
  } else {
2320
2229
  if (this.config.debugAdTiming) {
2321
- console.log("[StormcloudVideoPlayer] Ad pod completed");
2230
+ console.log(
2231
+ "[StormcloudVideoPlayer] No more ads in pod - completing ad break"
2232
+ );
2322
2233
  }
2323
- this.inAdBreak = false;
2324
- this.expectedAdBreakDurationMs = void 0;
2325
- this.currentAdBreakStartWallClockMs = void 0;
2326
- this.currentAdIndex = 0;
2327
- this.totalAdsInBreak = 0;
2328
- this.showAds = false;
2329
- this.clearAdStopTimer();
2234
+ this.handleAdPodComplete();
2330
2235
  }
2331
2236
  });
2332
2237
  this.video.addEventListener("timeupdate", () => {
@@ -3044,23 +2949,11 @@ var StormcloudVideoPlayer = class {
3044
2949
  maxExtensionMs
3045
2950
  });
3046
2951
  }
3047
- this.inAdBreak = false;
3048
- this.expectedAdBreakDurationMs = void 0;
3049
- this.currentAdBreakStartWallClockMs = void 0;
3050
- this.showAds = false;
3051
- this.adPodQueue = [];
3052
- this.currentAdIndex = 0;
3053
- this.totalAdsInBreak = 0;
3054
- this.clearAdFailsafeTimer();
3055
2952
  if (adPlaying) {
3056
2953
  this.ima.stop().catch(() => {
3057
2954
  });
3058
- return;
3059
- }
3060
- const originalMutedState = this.ima.getOriginalMutedState();
3061
- if (this.video.muted !== originalMutedState) {
3062
- this.video.muted = originalMutedState;
3063
2955
  }
2956
+ this.handleAdPodComplete();
3064
2957
  }
3065
2958
  scheduleAdStartIn(delayMs) {
3066
2959
  this.clearAdStartTimer();
@@ -3147,17 +3040,11 @@ var StormcloudVideoPlayer = class {
3147
3040
  this.handleAdFailure();
3148
3041
  }
3149
3042
  }
3150
- handleAdFailure() {
3043
+ handleAdPodComplete() {
3151
3044
  var _a;
3152
3045
  if (this.config.debugAdTiming) {
3153
3046
  console.log(
3154
- "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3155
- {
3156
- inAdBreak: this.inAdBreak,
3157
- showAds: this.showAds,
3158
- videoPaused: this.video.paused,
3159
- adPlaying: this.ima.isAdPlaying()
3160
- }
3047
+ "[StormcloudVideoPlayer] Handling ad pod completion - resuming content and hiding ad layer"
3161
3048
  );
3162
3049
  }
3163
3050
  this.inAdBreak = false;
@@ -3170,34 +3057,44 @@ var StormcloudVideoPlayer = class {
3170
3057
  this.showAds = false;
3171
3058
  this.currentAdIndex = 0;
3172
3059
  this.totalAdsInBreak = 0;
3173
- const currentMutedState = this.video.muted;
3060
+ this.ima.stop().catch(() => {
3061
+ });
3174
3062
  const originalMutedState = this.ima.getOriginalMutedState();
3175
3063
  this.video.muted = originalMutedState;
3064
+ this.video.volume = originalMutedState ? 0 : 1;
3176
3065
  if (this.config.debugAdTiming) {
3177
3066
  console.log(
3178
- `[StormcloudVideoPlayer] Restored mute state: ${currentMutedState} -> ${originalMutedState}`
3067
+ `[StormcloudVideoPlayer] Restored main video - muted: ${originalMutedState}, volume: ${this.video.volume}`
3179
3068
  );
3180
3069
  }
3181
- if (this.video.paused) {
3070
+ if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
3182
3071
  if (this.config.debugAdTiming) {
3183
3072
  console.log("[StormcloudVideoPlayer] Resuming paused video");
3184
3073
  }
3185
3074
  (_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
3186
3075
  if (this.config.debugAdTiming) {
3187
3076
  console.error(
3188
- "[StormcloudVideoPlayer] Failed to resume video after ad failure:",
3077
+ "[StormcloudVideoPlayer] Failed to resume video:",
3189
3078
  error
3190
3079
  );
3191
3080
  }
3192
3081
  });
3193
- } else {
3194
- if (this.config.debugAdTiming) {
3195
- console.log(
3196
- "[StormcloudVideoPlayer] Video is already playing, no resume needed"
3197
- );
3198
- }
3199
3082
  }
3200
3083
  }
3084
+ handleAdFailure() {
3085
+ if (this.config.debugAdTiming) {
3086
+ console.log(
3087
+ "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3088
+ {
3089
+ inAdBreak: this.inAdBreak,
3090
+ showAds: this.showAds,
3091
+ videoPaused: this.video.paused,
3092
+ adPlaying: this.ima.isAdPlaying()
3093
+ }
3094
+ );
3095
+ }
3096
+ this.handleAdPodComplete();
3097
+ }
3201
3098
  startAdFailsafeTimer() {
3202
3099
  var _a;
3203
3100
  this.clearAdFailsafeTimer();