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.
@@ -366,11 +366,12 @@ function createImaController(video, options) {
366
366
  container.style.top = "0";
367
367
  container.style.right = "0";
368
368
  container.style.bottom = "0";
369
- container.style.display = "flex";
369
+ container.style.display = "none";
370
370
  container.style.alignItems = "center";
371
371
  container.style.justifyContent = "center";
372
372
  container.style.pointerEvents = "none";
373
- container.style.zIndex = "2";
373
+ container.style.zIndex = "10";
374
+ container.style.backgroundColor = "#000";
374
375
  (_a = video.parentElement) == null ? void 0 : _a.appendChild(container);
375
376
  adContainerEl = container;
376
377
  adDisplayContainer = new google.ima.AdDisplayContainer(
@@ -440,7 +441,8 @@ function createImaController(video, options) {
440
441
  container.style.alignItems = "center";
441
442
  container.style.justifyContent = "center";
442
443
  container.style.pointerEvents = "none";
443
- container.style.zIndex = "2";
444
+ container.style.zIndex = "10";
445
+ container.style.backgroundColor = "#000";
444
446
  if (!video.parentElement) {
445
447
  throw new Error("Video element has no parent for ad container");
446
448
  }
@@ -538,7 +540,9 @@ function createImaController(video, options) {
538
540
  adsManager.addEventListener(
539
541
  AdEvent.CONTENT_PAUSE_REQUESTED,
540
542
  () => {
541
- console.log("[IMA] Content pause requested");
543
+ console.log(
544
+ "[IMA] Content pause requested - FORCE MUTING main video"
545
+ );
542
546
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
543
547
  video.pause();
544
548
  console.log("[IMA] Video paused (VOD mode)");
@@ -548,14 +552,19 @@ function createImaController(video, options) {
548
552
  );
549
553
  }
550
554
  video.muted = true;
555
+ video.volume = 0;
551
556
  adPlaying = true;
552
557
  setAdPlayingFlag(true);
553
558
  emit("content_pause");
554
559
  }
555
560
  );
556
561
  adsManager.addEventListener(AdEvent.STARTED, () => {
557
- console.log("[IMA] Ad started playing");
562
+ console.log(
563
+ "[IMA] Ad started playing - FORCE MUTING main video"
564
+ );
558
565
  setAdPlayingFlag(true);
566
+ video.muted = true;
567
+ video.volume = 0;
559
568
  if (adContainerEl) {
560
569
  adContainerEl.style.pointerEvents = "auto";
561
570
  adContainerEl.style.display = "flex";
@@ -571,63 +580,12 @@ function createImaController(video, options) {
571
580
  adPlaying = false;
572
581
  setAdPlayingFlag(false);
573
582
  emit("content_resume");
574
- setTimeout(() => {
575
- var _a;
576
- const stillInAdPod = video.dataset.stormcloudAdPlaying === "true";
577
- if (stillInAdPod) {
578
- console.log(
579
- "[IMA] Next ad started - keeping content muted/paused and ad container visible"
580
- );
581
- if (adContainerEl) {
582
- adContainerEl.style.display = "flex";
583
- adContainerEl.style.pointerEvents = "auto";
584
- }
585
- return;
586
- }
587
- console.log("[IMA] No next ad - resuming content");
588
- video.muted = originalMutedState;
589
- if (adContainerEl) {
590
- adContainerEl.style.pointerEvents = "none";
591
- adContainerEl.style.display = "none";
592
- console.log(
593
- "[IMA] Ad container hidden - pointer events disabled"
594
- );
595
- }
596
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
597
- (_a = video.play()) == null ? void 0 : _a.catch(() => {
598
- });
599
- console.log("[IMA] Video resumed (VOD mode)");
600
- } else {
601
- console.log(
602
- "[IMA] Video unmuted (Live mode - was never paused)"
603
- );
604
- }
605
- }, 100);
606
583
  }
607
584
  );
608
585
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
609
- console.log("[IMA] All ads completed");
586
+ console.log("[IMA] All ads completed - notifying parent");
610
587
  adPlaying = false;
611
- video.muted = originalMutedState;
612
588
  setAdPlayingFlag(false);
613
- if (adContainerEl) {
614
- adContainerEl.style.pointerEvents = "none";
615
- adContainerEl.style.display = "none";
616
- console.log(
617
- "[IMA] Ad container hidden after all ads completed"
618
- );
619
- }
620
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
621
- video.play().catch(() => {
622
- });
623
- console.log(
624
- "[IMA] Video resumed after all ads completed (VOD mode)"
625
- );
626
- } else {
627
- console.log(
628
- "[IMA] Video unmuted after all ads completed (Live mode)"
629
- );
630
- }
631
589
  emit("all_ads_completed");
632
590
  });
633
591
  console.log("[IMA] Ads manager event listeners attached");
@@ -750,8 +708,8 @@ function createImaController(video, options) {
750
708
  },
751
709
  async stop() {
752
710
  var _a;
711
+ console.log("[IMA] Stopping ad playback");
753
712
  adPlaying = false;
754
- video.muted = originalMutedState;
755
713
  setAdPlayingFlag(false);
756
714
  if (adContainerEl) {
757
715
  adContainerEl.style.pointerEvents = "none";
@@ -763,13 +721,6 @@ function createImaController(video, options) {
763
721
  } catch {
764
722
  }
765
723
  destroyAdsManager();
766
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
767
- video.play().catch(() => {
768
- });
769
- console.log("[IMA] Video resumed after stop (VOD mode)");
770
- } else {
771
- console.log("[IMA] Video unmuted after stop (Live mode)");
772
- }
773
724
  },
774
725
  destroy() {
775
726
  var _a;
@@ -1178,37 +1129,6 @@ function createHlsAdPlayer(contentVideo, options) {
1178
1129
  adPlaying = false;
1179
1130
  setAdPlayingFlag(false);
1180
1131
  emit("content_resume");
1181
- emit("all_ads_completed");
1182
- setTimeout(() => {
1183
- const stillInAdPod = contentVideo.dataset.stormcloudAdPlaying === "true";
1184
- if (stillInAdPod) {
1185
- console.log(
1186
- "[HlsAdPlayer] Next ad started - keeping content muted/paused and ad container visible"
1187
- );
1188
- if (adContainerEl) {
1189
- adContainerEl.style.display = "flex";
1190
- adContainerEl.style.pointerEvents = "auto";
1191
- }
1192
- return;
1193
- }
1194
- console.log("[HlsAdPlayer] No next ad - resuming content");
1195
- const previousMutedState = contentVideo.muted;
1196
- contentVideo.muted = originalMutedState;
1197
- console.log(
1198
- `[HlsAdPlayer] Restored mute state: ${previousMutedState} -> ${originalMutedState}`
1199
- );
1200
- if (adContainerEl) {
1201
- adContainerEl.style.display = "none";
1202
- adContainerEl.style.pointerEvents = "none";
1203
- }
1204
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1205
- contentVideo.play().catch(() => {
1206
- });
1207
- console.log("[HlsAdPlayer] Content resumed (VOD mode)");
1208
- } else {
1209
- console.log("[HlsAdPlayer] Content unmuted (Live mode)");
1210
- }
1211
- }, 100);
1212
1132
  }
1213
1133
  function handleAdError() {
1214
1134
  console.log("[HlsAdPlayer] Handling ad error");
@@ -1246,7 +1166,7 @@ function createHlsAdPlayer(contentVideo, options) {
1246
1166
  container.style.alignItems = "center";
1247
1167
  container.style.justifyContent = "center";
1248
1168
  container.style.pointerEvents = "none";
1249
- container.style.zIndex = "2";
1169
+ container.style.zIndex = "10";
1250
1170
  container.style.backgroundColor = "#000";
1251
1171
  (_a = contentVideo.parentElement) == null ? void 0 : _a.appendChild(container);
1252
1172
  adContainerEl = container;
@@ -1320,7 +1240,9 @@ function createHlsAdPlayer(contentVideo, options) {
1320
1240
  } else {
1321
1241
  console.log("[HlsAdPlayer] Content continues (Live mode)");
1322
1242
  }
1243
+ console.log("[HlsAdPlayer] FORCE MUTING main video");
1323
1244
  contentVideo.muted = true;
1245
+ contentVideo.volume = 0;
1324
1246
  adPlaying = true;
1325
1247
  setAdPlayingFlag(true);
1326
1248
  if (adVideoElement) {
@@ -1384,7 +1306,6 @@ function createHlsAdPlayer(contentVideo, options) {
1384
1306
  console.log("[HlsAdPlayer] Stopping ad");
1385
1307
  adPlaying = false;
1386
1308
  setAdPlayingFlag(false);
1387
- contentVideo.muted = originalMutedState;
1388
1309
  if (adContainerEl) {
1389
1310
  adContainerEl.style.display = "none";
1390
1311
  adContainerEl.style.pointerEvents = "none";
@@ -1397,10 +1318,6 @@ function createHlsAdPlayer(contentVideo, options) {
1397
1318
  adVideoElement.pause();
1398
1319
  adVideoElement.src = "";
1399
1320
  }
1400
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1401
- contentVideo.play().catch(() => {
1402
- });
1403
- }
1404
1321
  currentAd = void 0;
1405
1322
  },
1406
1323
  destroy() {
@@ -1946,7 +1863,6 @@ var StormcloudVideoPlayer = class {
1946
1863
  this.bufferedSegmentsCount = 0;
1947
1864
  this.shouldAutoplayAfterBuffering = false;
1948
1865
  this.hasInitialBufferCompleted = false;
1949
- this.isTransitioningBetweenAds = false;
1950
1866
  initializePolyfills();
1951
1867
  const browserOverrides = getBrowserConfigOverrides();
1952
1868
  this.config = { ...config, ...browserOverrides };
@@ -2210,9 +2126,12 @@ var StormcloudVideoPlayer = class {
2210
2126
  this.ima.on("all_ads_completed", () => {
2211
2127
  if (this.config.debugAdTiming) {
2212
2128
  console.log(
2213
- "[StormcloudVideoPlayer] IMA all_ads_completed event received"
2129
+ "[StormcloudVideoPlayer] IMA all_ads_completed event received - ending ad break"
2214
2130
  );
2215
2131
  }
2132
+ if (this.inAdBreak) {
2133
+ this.handleAdPodComplete();
2134
+ }
2216
2135
  });
2217
2136
  this.ima.on("ad_error", () => {
2218
2137
  if (this.config.debugAdTiming) {
@@ -2251,57 +2170,43 @@ var StormcloudVideoPlayer = class {
2251
2170
  "[StormcloudVideoPlayer] IMA content_resume event received",
2252
2171
  {
2253
2172
  inAdBreak: this.inAdBreak,
2254
- isTransitioningBetweenAds: this.isTransitioningBetweenAds,
2255
2173
  pendingAds: this.adPodQueue.length
2256
2174
  }
2257
2175
  );
2258
2176
  }
2259
2177
  this.clearAdFailsafeTimer();
2260
- if (this.isTransitioningBetweenAds) {
2261
- if (this.config.debugAdTiming) {
2262
- console.log(
2263
- "[StormcloudVideoPlayer] Transitioning between ads - keeping content muted/paused"
2264
- );
2265
- }
2266
- return;
2267
- }
2268
2178
  if (!this.inAdBreak) {
2269
2179
  if (this.config.debugAdTiming) {
2270
2180
  console.log(
2271
- "[StormcloudVideoPlayer] Not in ad break, allowing normal content resume"
2181
+ "[StormcloudVideoPlayer] Not in ad break - this shouldn't happen during pod"
2272
2182
  );
2273
2183
  }
2274
2184
  return;
2275
2185
  }
2276
2186
  const remaining = this.getRemainingAdMs();
2277
2187
  if (remaining > 500 && this.adPodQueue.length > 0) {
2278
- this.isTransitioningBetweenAds = true;
2279
- this.video.muted = true;
2280
- if (!this.shouldContinueLiveStreamDuringAds()) {
2281
- this.video.pause();
2282
- }
2283
2188
  const next = this.adPodQueue.shift();
2284
2189
  this.currentAdIndex++;
2285
2190
  if (this.config.debugAdTiming) {
2286
2191
  console.log(
2287
- `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - keeping content muted/paused`
2192
+ `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - main video stays muted, ad layer stays visible`
2288
2193
  );
2289
2194
  }
2290
2195
  this.playSingleAd(next).catch(() => {
2291
- }).finally(() => {
2292
- this.isTransitioningBetweenAds = false;
2196
+ if (this.config.debugAdTiming) {
2197
+ console.error(
2198
+ "[StormcloudVideoPlayer] Failed to play next ad in pod"
2199
+ );
2200
+ }
2201
+ this.handleAdPodComplete();
2293
2202
  });
2294
2203
  } else {
2295
2204
  if (this.config.debugAdTiming) {
2296
- console.log("[StormcloudVideoPlayer] Ad pod completed");
2205
+ console.log(
2206
+ "[StormcloudVideoPlayer] No more ads in pod - completing ad break"
2207
+ );
2297
2208
  }
2298
- this.inAdBreak = false;
2299
- this.expectedAdBreakDurationMs = void 0;
2300
- this.currentAdBreakStartWallClockMs = void 0;
2301
- this.currentAdIndex = 0;
2302
- this.totalAdsInBreak = 0;
2303
- this.showAds = false;
2304
- this.clearAdStopTimer();
2209
+ this.handleAdPodComplete();
2305
2210
  }
2306
2211
  });
2307
2212
  this.video.addEventListener("timeupdate", () => {
@@ -3019,23 +2924,11 @@ var StormcloudVideoPlayer = class {
3019
2924
  maxExtensionMs
3020
2925
  });
3021
2926
  }
3022
- this.inAdBreak = false;
3023
- this.expectedAdBreakDurationMs = void 0;
3024
- this.currentAdBreakStartWallClockMs = void 0;
3025
- this.showAds = false;
3026
- this.adPodQueue = [];
3027
- this.currentAdIndex = 0;
3028
- this.totalAdsInBreak = 0;
3029
- this.clearAdFailsafeTimer();
3030
2927
  if (adPlaying) {
3031
2928
  this.ima.stop().catch(() => {
3032
2929
  });
3033
- return;
3034
- }
3035
- const originalMutedState = this.ima.getOriginalMutedState();
3036
- if (this.video.muted !== originalMutedState) {
3037
- this.video.muted = originalMutedState;
3038
2930
  }
2931
+ this.handleAdPodComplete();
3039
2932
  }
3040
2933
  scheduleAdStartIn(delayMs) {
3041
2934
  this.clearAdStartTimer();
@@ -3122,17 +3015,11 @@ var StormcloudVideoPlayer = class {
3122
3015
  this.handleAdFailure();
3123
3016
  }
3124
3017
  }
3125
- handleAdFailure() {
3018
+ handleAdPodComplete() {
3126
3019
  var _a;
3127
3020
  if (this.config.debugAdTiming) {
3128
3021
  console.log(
3129
- "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3130
- {
3131
- inAdBreak: this.inAdBreak,
3132
- showAds: this.showAds,
3133
- videoPaused: this.video.paused,
3134
- adPlaying: this.ima.isAdPlaying()
3135
- }
3022
+ "[StormcloudVideoPlayer] Handling ad pod completion - resuming content and hiding ad layer"
3136
3023
  );
3137
3024
  }
3138
3025
  this.inAdBreak = false;
@@ -3145,34 +3032,44 @@ var StormcloudVideoPlayer = class {
3145
3032
  this.showAds = false;
3146
3033
  this.currentAdIndex = 0;
3147
3034
  this.totalAdsInBreak = 0;
3148
- const currentMutedState = this.video.muted;
3035
+ this.ima.stop().catch(() => {
3036
+ });
3149
3037
  const originalMutedState = this.ima.getOriginalMutedState();
3150
3038
  this.video.muted = originalMutedState;
3039
+ this.video.volume = originalMutedState ? 0 : 1;
3151
3040
  if (this.config.debugAdTiming) {
3152
3041
  console.log(
3153
- `[StormcloudVideoPlayer] Restored mute state: ${currentMutedState} -> ${originalMutedState}`
3042
+ `[StormcloudVideoPlayer] Restored main video - muted: ${originalMutedState}, volume: ${this.video.volume}`
3154
3043
  );
3155
3044
  }
3156
- if (this.video.paused) {
3045
+ if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
3157
3046
  if (this.config.debugAdTiming) {
3158
3047
  console.log("[StormcloudVideoPlayer] Resuming paused video");
3159
3048
  }
3160
3049
  (_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
3161
3050
  if (this.config.debugAdTiming) {
3162
3051
  console.error(
3163
- "[StormcloudVideoPlayer] Failed to resume video after ad failure:",
3052
+ "[StormcloudVideoPlayer] Failed to resume video:",
3164
3053
  error
3165
3054
  );
3166
3055
  }
3167
3056
  });
3168
- } else {
3169
- if (this.config.debugAdTiming) {
3170
- console.log(
3171
- "[StormcloudVideoPlayer] Video is already playing, no resume needed"
3172
- );
3173
- }
3174
3057
  }
3175
3058
  }
3059
+ handleAdFailure() {
3060
+ if (this.config.debugAdTiming) {
3061
+ console.log(
3062
+ "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3063
+ {
3064
+ inAdBreak: this.inAdBreak,
3065
+ showAds: this.showAds,
3066
+ videoPaused: this.video.paused,
3067
+ adPlaying: this.ima.isAdPlaying()
3068
+ }
3069
+ );
3070
+ }
3071
+ this.handleAdPodComplete();
3072
+ }
3176
3073
  startAdFailsafeTimer() {
3177
3074
  var _a;
3178
3075
  this.clearAdFailsafeTimer();