stormcloud-video-player 0.2.19 → 0.2.21

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.
@@ -324,11 +324,12 @@ function createImaController(video, options) {
324
324
  container.style.top = "0";
325
325
  container.style.right = "0";
326
326
  container.style.bottom = "0";
327
- container.style.display = "flex";
327
+ container.style.display = "none";
328
328
  container.style.alignItems = "center";
329
329
  container.style.justifyContent = "center";
330
330
  container.style.pointerEvents = "none";
331
- container.style.zIndex = "2";
331
+ container.style.zIndex = "10";
332
+ container.style.backgroundColor = "#000";
332
333
  (_a = video.parentElement) == null ? void 0 : _a.appendChild(container);
333
334
  adContainerEl = container;
334
335
  adDisplayContainer = new google.ima.AdDisplayContainer(
@@ -398,7 +399,8 @@ function createImaController(video, options) {
398
399
  container.style.alignItems = "center";
399
400
  container.style.justifyContent = "center";
400
401
  container.style.pointerEvents = "none";
401
- container.style.zIndex = "2";
402
+ container.style.zIndex = "10";
403
+ container.style.backgroundColor = "#000";
402
404
  if (!video.parentElement) {
403
405
  throw new Error("Video element has no parent for ad container");
404
406
  }
@@ -525,53 +527,16 @@ function createImaController(video, options) {
525
527
  adsManager.addEventListener(
526
528
  AdEvent.CONTENT_RESUME_REQUESTED,
527
529
  () => {
528
- var _a;
529
530
  console.log("[IMA] Content resume requested");
530
531
  adPlaying = false;
531
- video.muted = originalMutedState;
532
532
  setAdPlayingFlag(false);
533
- if (adContainerEl) {
534
- adContainerEl.style.pointerEvents = "none";
535
- adContainerEl.style.display = "none";
536
- console.log(
537
- "[IMA] Ad container hidden - pointer events disabled"
538
- );
539
- }
540
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
541
- (_a = video.play()) == null ? void 0 : _a.catch(() => {
542
- });
543
- console.log("[IMA] Video resumed (VOD mode)");
544
- } else {
545
- console.log(
546
- "[IMA] Video unmuted (Live mode - was never paused)"
547
- );
548
- }
549
533
  emit("content_resume");
550
534
  }
551
535
  );
552
536
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
553
- console.log("[IMA] All ads completed");
537
+ console.log("[IMA] All ads completed - notifying parent");
554
538
  adPlaying = false;
555
- video.muted = originalMutedState;
556
539
  setAdPlayingFlag(false);
557
- if (adContainerEl) {
558
- adContainerEl.style.pointerEvents = "none";
559
- adContainerEl.style.display = "none";
560
- console.log(
561
- "[IMA] Ad container hidden after all ads completed"
562
- );
563
- }
564
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
565
- video.play().catch(() => {
566
- });
567
- console.log(
568
- "[IMA] Video resumed after all ads completed (VOD mode)"
569
- );
570
- } else {
571
- console.log(
572
- "[IMA] Video unmuted after all ads completed (Live mode)"
573
- );
574
- }
575
540
  emit("all_ads_completed");
576
541
  });
577
542
  console.log("[IMA] Ads manager event listeners attached");
@@ -694,8 +659,8 @@ function createImaController(video, options) {
694
659
  },
695
660
  async stop() {
696
661
  var _a;
662
+ console.log("[IMA] Stopping ad playback");
697
663
  adPlaying = false;
698
- video.muted = originalMutedState;
699
664
  setAdPlayingFlag(false);
700
665
  if (adContainerEl) {
701
666
  adContainerEl.style.pointerEvents = "none";
@@ -707,13 +672,6 @@ function createImaController(video, options) {
707
672
  } catch {
708
673
  }
709
674
  destroyAdsManager();
710
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
711
- video.play().catch(() => {
712
- });
713
- console.log("[IMA] Video resumed after stop (VOD mode)");
714
- } else {
715
- console.log("[IMA] Video unmuted after stop (Live mode)");
716
- }
717
675
  },
718
676
  destroy() {
719
677
  var _a;
@@ -1121,24 +1079,7 @@ function createHlsAdPlayer(contentVideo, options) {
1121
1079
  console.log("[HlsAdPlayer] Handling ad completion");
1122
1080
  adPlaying = false;
1123
1081
  setAdPlayingFlag(false);
1124
- const previousMutedState = contentVideo.muted;
1125
- contentVideo.muted = originalMutedState;
1126
- console.log(
1127
- `[HlsAdPlayer] Restored mute state: ${previousMutedState} -> ${originalMutedState}`
1128
- );
1129
- if (adContainerEl) {
1130
- adContainerEl.style.display = "none";
1131
- adContainerEl.style.pointerEvents = "none";
1132
- }
1133
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1134
- contentVideo.play().catch(() => {
1135
- });
1136
- console.log("[HlsAdPlayer] Content resumed (VOD mode)");
1137
- } else {
1138
- console.log("[HlsAdPlayer] Content unmuted (Live mode)");
1139
- }
1140
1082
  emit("content_resume");
1141
- emit("all_ads_completed");
1142
1083
  }
1143
1084
  function handleAdError() {
1144
1085
  console.log("[HlsAdPlayer] Handling ad error");
@@ -1176,7 +1117,7 @@ function createHlsAdPlayer(contentVideo, options) {
1176
1117
  container.style.alignItems = "center";
1177
1118
  container.style.justifyContent = "center";
1178
1119
  container.style.pointerEvents = "none";
1179
- container.style.zIndex = "2";
1120
+ container.style.zIndex = "10";
1180
1121
  container.style.backgroundColor = "#000";
1181
1122
  (_a = contentVideo.parentElement) == null ? void 0 : _a.appendChild(container);
1182
1123
  adContainerEl = container;
@@ -1314,7 +1255,6 @@ function createHlsAdPlayer(contentVideo, options) {
1314
1255
  console.log("[HlsAdPlayer] Stopping ad");
1315
1256
  adPlaying = false;
1316
1257
  setAdPlayingFlag(false);
1317
- contentVideo.muted = originalMutedState;
1318
1258
  if (adContainerEl) {
1319
1259
  adContainerEl.style.display = "none";
1320
1260
  adContainerEl.style.pointerEvents = "none";
@@ -1327,10 +1267,6 @@ function createHlsAdPlayer(contentVideo, options) {
1327
1267
  adVideoElement.pause();
1328
1268
  adVideoElement.src = "";
1329
1269
  }
1330
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1331
- contentVideo.play().catch(() => {
1332
- });
1333
- }
1334
1270
  currentAd = void 0;
1335
1271
  },
1336
1272
  destroy() {
@@ -2139,9 +2075,12 @@ var StormcloudVideoPlayer = class {
2139
2075
  this.ima.on("all_ads_completed", () => {
2140
2076
  if (this.config.debugAdTiming) {
2141
2077
  console.log(
2142
- "[StormcloudVideoPlayer] IMA all_ads_completed event received"
2078
+ "[StormcloudVideoPlayer] IMA all_ads_completed event received - ending ad break"
2143
2079
  );
2144
2080
  }
2081
+ if (this.inAdBreak) {
2082
+ this.handleAdPodComplete();
2083
+ }
2145
2084
  });
2146
2085
  this.ima.on("ad_error", () => {
2147
2086
  if (this.config.debugAdTiming) {
@@ -2177,29 +2116,46 @@ var StormcloudVideoPlayer = class {
2177
2116
  this.ima.on("content_resume", () => {
2178
2117
  if (this.config.debugAdTiming) {
2179
2118
  console.log(
2180
- "[StormcloudVideoPlayer] IMA content_resume event received"
2119
+ "[StormcloudVideoPlayer] IMA content_resume event received",
2120
+ {
2121
+ inAdBreak: this.inAdBreak,
2122
+ pendingAds: this.adPodQueue.length
2123
+ }
2181
2124
  );
2182
2125
  }
2183
2126
  this.clearAdFailsafeTimer();
2184
- if (!this.inAdBreak) return;
2127
+ if (!this.inAdBreak) {
2128
+ if (this.config.debugAdTiming) {
2129
+ console.log(
2130
+ "[StormcloudVideoPlayer] Not in ad break - this shouldn't happen during pod"
2131
+ );
2132
+ }
2133
+ return;
2134
+ }
2185
2135
  const remaining = this.getRemainingAdMs();
2186
2136
  if (remaining > 500 && this.adPodQueue.length > 0) {
2187
2137
  const next = this.adPodQueue.shift();
2188
2138
  this.currentAdIndex++;
2189
2139
  if (this.config.debugAdTiming) {
2190
2140
  console.log(
2191
- `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak})`
2141
+ `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - main video stays muted, ad layer stays visible`
2192
2142
  );
2193
2143
  }
2194
2144
  this.playSingleAd(next).catch(() => {
2145
+ if (this.config.debugAdTiming) {
2146
+ console.error(
2147
+ "[StormcloudVideoPlayer] Failed to play next ad in pod"
2148
+ );
2149
+ }
2150
+ this.handleAdPodComplete();
2195
2151
  });
2196
2152
  } else {
2197
2153
  if (this.config.debugAdTiming) {
2198
- console.log("[StormcloudVideoPlayer] Ad pod completed");
2154
+ console.log(
2155
+ "[StormcloudVideoPlayer] No more ads in pod - completing ad break"
2156
+ );
2199
2157
  }
2200
- this.currentAdIndex = 0;
2201
- this.totalAdsInBreak = 0;
2202
- this.showAds = false;
2158
+ this.handleAdPodComplete();
2203
2159
  }
2204
2160
  });
2205
2161
  this.video.addEventListener("timeupdate", () => {
@@ -2917,23 +2873,11 @@ var StormcloudVideoPlayer = class {
2917
2873
  maxExtensionMs
2918
2874
  });
2919
2875
  }
2920
- this.inAdBreak = false;
2921
- this.expectedAdBreakDurationMs = void 0;
2922
- this.currentAdBreakStartWallClockMs = void 0;
2923
- this.showAds = false;
2924
- this.adPodQueue = [];
2925
- this.currentAdIndex = 0;
2926
- this.totalAdsInBreak = 0;
2927
- this.clearAdFailsafeTimer();
2928
2876
  if (adPlaying) {
2929
2877
  this.ima.stop().catch(() => {
2930
2878
  });
2931
- return;
2932
- }
2933
- const originalMutedState = this.ima.getOriginalMutedState();
2934
- if (this.video.muted !== originalMutedState) {
2935
- this.video.muted = originalMutedState;
2936
2879
  }
2880
+ this.handleAdPodComplete();
2937
2881
  }
2938
2882
  scheduleAdStartIn(delayMs) {
2939
2883
  this.clearAdStartTimer();
@@ -3020,17 +2964,11 @@ var StormcloudVideoPlayer = class {
3020
2964
  this.handleAdFailure();
3021
2965
  }
3022
2966
  }
3023
- handleAdFailure() {
2967
+ handleAdPodComplete() {
3024
2968
  var _a;
3025
2969
  if (this.config.debugAdTiming) {
3026
2970
  console.log(
3027
- "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3028
- {
3029
- inAdBreak: this.inAdBreak,
3030
- showAds: this.showAds,
3031
- videoPaused: this.video.paused,
3032
- adPlaying: this.ima.isAdPlaying()
3033
- }
2971
+ "[StormcloudVideoPlayer] Handling ad pod completion - resuming content"
3034
2972
  );
3035
2973
  }
3036
2974
  this.inAdBreak = false;
@@ -3043,34 +2981,41 @@ var StormcloudVideoPlayer = class {
3043
2981
  this.showAds = false;
3044
2982
  this.currentAdIndex = 0;
3045
2983
  this.totalAdsInBreak = 0;
3046
- const currentMutedState = this.video.muted;
3047
2984
  const originalMutedState = this.ima.getOriginalMutedState();
3048
2985
  this.video.muted = originalMutedState;
3049
2986
  if (this.config.debugAdTiming) {
3050
2987
  console.log(
3051
- `[StormcloudVideoPlayer] Restored mute state: ${currentMutedState} -> ${originalMutedState}`
2988
+ `[StormcloudVideoPlayer] Restored main video mute state to: ${originalMutedState}`
3052
2989
  );
3053
2990
  }
3054
- if (this.video.paused) {
2991
+ if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
3055
2992
  if (this.config.debugAdTiming) {
3056
2993
  console.log("[StormcloudVideoPlayer] Resuming paused video");
3057
2994
  }
3058
2995
  (_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
3059
2996
  if (this.config.debugAdTiming) {
3060
2997
  console.error(
3061
- "[StormcloudVideoPlayer] Failed to resume video after ad failure:",
2998
+ "[StormcloudVideoPlayer] Failed to resume video:",
3062
2999
  error
3063
3000
  );
3064
3001
  }
3065
3002
  });
3066
- } else {
3067
- if (this.config.debugAdTiming) {
3068
- console.log(
3069
- "[StormcloudVideoPlayer] Video is already playing, no resume needed"
3070
- );
3071
- }
3072
3003
  }
3073
3004
  }
3005
+ handleAdFailure() {
3006
+ if (this.config.debugAdTiming) {
3007
+ console.log(
3008
+ "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3009
+ {
3010
+ inAdBreak: this.inAdBreak,
3011
+ showAds: this.showAds,
3012
+ videoPaused: this.video.paused,
3013
+ adPlaying: this.ima.isAdPlaying()
3014
+ }
3015
+ );
3016
+ }
3017
+ this.handleAdPodComplete();
3018
+ }
3074
3019
  startAdFailsafeTimer() {
3075
3020
  var _a;
3076
3021
  this.clearAdFailsafeTimer();