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.
@@ -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
  }
@@ -496,7 +498,9 @@ function createImaController(video, options) {
496
498
  adsManager.addEventListener(
497
499
  AdEvent.CONTENT_PAUSE_REQUESTED,
498
500
  () => {
499
- console.log("[IMA] Content pause requested");
501
+ console.log(
502
+ "[IMA] Content pause requested - FORCE MUTING main video"
503
+ );
500
504
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
501
505
  video.pause();
502
506
  console.log("[IMA] Video paused (VOD mode)");
@@ -506,14 +510,19 @@ function createImaController(video, options) {
506
510
  );
507
511
  }
508
512
  video.muted = true;
513
+ video.volume = 0;
509
514
  adPlaying = true;
510
515
  setAdPlayingFlag(true);
511
516
  emit("content_pause");
512
517
  }
513
518
  );
514
519
  adsManager.addEventListener(AdEvent.STARTED, () => {
515
- console.log("[IMA] Ad started playing");
520
+ console.log(
521
+ "[IMA] Ad started playing - FORCE MUTING main video"
522
+ );
516
523
  setAdPlayingFlag(true);
524
+ video.muted = true;
525
+ video.volume = 0;
517
526
  if (adContainerEl) {
518
527
  adContainerEl.style.pointerEvents = "auto";
519
528
  adContainerEl.style.display = "flex";
@@ -529,63 +538,12 @@ function createImaController(video, options) {
529
538
  adPlaying = false;
530
539
  setAdPlayingFlag(false);
531
540
  emit("content_resume");
532
- setTimeout(() => {
533
- var _a;
534
- const stillInAdPod = video.dataset.stormcloudAdPlaying === "true";
535
- if (stillInAdPod) {
536
- console.log(
537
- "[IMA] Next ad started - keeping content muted/paused and ad container visible"
538
- );
539
- if (adContainerEl) {
540
- adContainerEl.style.display = "flex";
541
- adContainerEl.style.pointerEvents = "auto";
542
- }
543
- return;
544
- }
545
- console.log("[IMA] No next ad - resuming content");
546
- video.muted = originalMutedState;
547
- if (adContainerEl) {
548
- adContainerEl.style.pointerEvents = "none";
549
- adContainerEl.style.display = "none";
550
- console.log(
551
- "[IMA] Ad container hidden - pointer events disabled"
552
- );
553
- }
554
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
555
- (_a = video.play()) == null ? void 0 : _a.catch(() => {
556
- });
557
- console.log("[IMA] Video resumed (VOD mode)");
558
- } else {
559
- console.log(
560
- "[IMA] Video unmuted (Live mode - was never paused)"
561
- );
562
- }
563
- }, 100);
564
541
  }
565
542
  );
566
543
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
567
- console.log("[IMA] All ads completed");
544
+ console.log("[IMA] All ads completed - notifying parent");
568
545
  adPlaying = false;
569
- video.muted = originalMutedState;
570
546
  setAdPlayingFlag(false);
571
- if (adContainerEl) {
572
- adContainerEl.style.pointerEvents = "none";
573
- adContainerEl.style.display = "none";
574
- console.log(
575
- "[IMA] Ad container hidden after all ads completed"
576
- );
577
- }
578
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
579
- video.play().catch(() => {
580
- });
581
- console.log(
582
- "[IMA] Video resumed after all ads completed (VOD mode)"
583
- );
584
- } else {
585
- console.log(
586
- "[IMA] Video unmuted after all ads completed (Live mode)"
587
- );
588
- }
589
547
  emit("all_ads_completed");
590
548
  });
591
549
  console.log("[IMA] Ads manager event listeners attached");
@@ -708,8 +666,8 @@ function createImaController(video, options) {
708
666
  },
709
667
  async stop() {
710
668
  var _a;
669
+ console.log("[IMA] Stopping ad playback");
711
670
  adPlaying = false;
712
- video.muted = originalMutedState;
713
671
  setAdPlayingFlag(false);
714
672
  if (adContainerEl) {
715
673
  adContainerEl.style.pointerEvents = "none";
@@ -721,13 +679,6 @@ function createImaController(video, options) {
721
679
  } catch {
722
680
  }
723
681
  destroyAdsManager();
724
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
725
- video.play().catch(() => {
726
- });
727
- console.log("[IMA] Video resumed after stop (VOD mode)");
728
- } else {
729
- console.log("[IMA] Video unmuted after stop (Live mode)");
730
- }
731
682
  },
732
683
  destroy() {
733
684
  var _a;
@@ -1136,37 +1087,6 @@ function createHlsAdPlayer(contentVideo, options) {
1136
1087
  adPlaying = false;
1137
1088
  setAdPlayingFlag(false);
1138
1089
  emit("content_resume");
1139
- emit("all_ads_completed");
1140
- setTimeout(() => {
1141
- const stillInAdPod = contentVideo.dataset.stormcloudAdPlaying === "true";
1142
- if (stillInAdPod) {
1143
- console.log(
1144
- "[HlsAdPlayer] Next ad started - keeping content muted/paused and ad container visible"
1145
- );
1146
- if (adContainerEl) {
1147
- adContainerEl.style.display = "flex";
1148
- adContainerEl.style.pointerEvents = "auto";
1149
- }
1150
- return;
1151
- }
1152
- console.log("[HlsAdPlayer] No next ad - resuming content");
1153
- const previousMutedState = contentVideo.muted;
1154
- contentVideo.muted = originalMutedState;
1155
- console.log(
1156
- `[HlsAdPlayer] Restored mute state: ${previousMutedState} -> ${originalMutedState}`
1157
- );
1158
- if (adContainerEl) {
1159
- adContainerEl.style.display = "none";
1160
- adContainerEl.style.pointerEvents = "none";
1161
- }
1162
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1163
- contentVideo.play().catch(() => {
1164
- });
1165
- console.log("[HlsAdPlayer] Content resumed (VOD mode)");
1166
- } else {
1167
- console.log("[HlsAdPlayer] Content unmuted (Live mode)");
1168
- }
1169
- }, 100);
1170
1090
  }
1171
1091
  function handleAdError() {
1172
1092
  console.log("[HlsAdPlayer] Handling ad error");
@@ -1204,7 +1124,7 @@ function createHlsAdPlayer(contentVideo, options) {
1204
1124
  container.style.alignItems = "center";
1205
1125
  container.style.justifyContent = "center";
1206
1126
  container.style.pointerEvents = "none";
1207
- container.style.zIndex = "2";
1127
+ container.style.zIndex = "10";
1208
1128
  container.style.backgroundColor = "#000";
1209
1129
  (_a = contentVideo.parentElement) == null ? void 0 : _a.appendChild(container);
1210
1130
  adContainerEl = container;
@@ -1278,7 +1198,9 @@ function createHlsAdPlayer(contentVideo, options) {
1278
1198
  } else {
1279
1199
  console.log("[HlsAdPlayer] Content continues (Live mode)");
1280
1200
  }
1201
+ console.log("[HlsAdPlayer] FORCE MUTING main video");
1281
1202
  contentVideo.muted = true;
1203
+ contentVideo.volume = 0;
1282
1204
  adPlaying = true;
1283
1205
  setAdPlayingFlag(true);
1284
1206
  if (adVideoElement) {
@@ -1342,7 +1264,6 @@ function createHlsAdPlayer(contentVideo, options) {
1342
1264
  console.log("[HlsAdPlayer] Stopping ad");
1343
1265
  adPlaying = false;
1344
1266
  setAdPlayingFlag(false);
1345
- contentVideo.muted = originalMutedState;
1346
1267
  if (adContainerEl) {
1347
1268
  adContainerEl.style.display = "none";
1348
1269
  adContainerEl.style.pointerEvents = "none";
@@ -1355,10 +1276,6 @@ function createHlsAdPlayer(contentVideo, options) {
1355
1276
  adVideoElement.pause();
1356
1277
  adVideoElement.src = "";
1357
1278
  }
1358
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1359
- contentVideo.play().catch(() => {
1360
- });
1361
- }
1362
1279
  currentAd = void 0;
1363
1280
  },
1364
1281
  destroy() {
@@ -1904,7 +1821,6 @@ var StormcloudVideoPlayer = class {
1904
1821
  this.bufferedSegmentsCount = 0;
1905
1822
  this.shouldAutoplayAfterBuffering = false;
1906
1823
  this.hasInitialBufferCompleted = false;
1907
- this.isTransitioningBetweenAds = false;
1908
1824
  initializePolyfills();
1909
1825
  const browserOverrides = getBrowserConfigOverrides();
1910
1826
  this.config = { ...config, ...browserOverrides };
@@ -2168,9 +2084,12 @@ var StormcloudVideoPlayer = class {
2168
2084
  this.ima.on("all_ads_completed", () => {
2169
2085
  if (this.config.debugAdTiming) {
2170
2086
  console.log(
2171
- "[StormcloudVideoPlayer] IMA all_ads_completed event received"
2087
+ "[StormcloudVideoPlayer] IMA all_ads_completed event received - ending ad break"
2172
2088
  );
2173
2089
  }
2090
+ if (this.inAdBreak) {
2091
+ this.handleAdPodComplete();
2092
+ }
2174
2093
  });
2175
2094
  this.ima.on("ad_error", () => {
2176
2095
  if (this.config.debugAdTiming) {
@@ -2209,57 +2128,43 @@ var StormcloudVideoPlayer = class {
2209
2128
  "[StormcloudVideoPlayer] IMA content_resume event received",
2210
2129
  {
2211
2130
  inAdBreak: this.inAdBreak,
2212
- isTransitioningBetweenAds: this.isTransitioningBetweenAds,
2213
2131
  pendingAds: this.adPodQueue.length
2214
2132
  }
2215
2133
  );
2216
2134
  }
2217
2135
  this.clearAdFailsafeTimer();
2218
- if (this.isTransitioningBetweenAds) {
2219
- if (this.config.debugAdTiming) {
2220
- console.log(
2221
- "[StormcloudVideoPlayer] Transitioning between ads - keeping content muted/paused"
2222
- );
2223
- }
2224
- return;
2225
- }
2226
2136
  if (!this.inAdBreak) {
2227
2137
  if (this.config.debugAdTiming) {
2228
2138
  console.log(
2229
- "[StormcloudVideoPlayer] Not in ad break, allowing normal content resume"
2139
+ "[StormcloudVideoPlayer] Not in ad break - this shouldn't happen during pod"
2230
2140
  );
2231
2141
  }
2232
2142
  return;
2233
2143
  }
2234
2144
  const remaining = this.getRemainingAdMs();
2235
2145
  if (remaining > 500 && this.adPodQueue.length > 0) {
2236
- this.isTransitioningBetweenAds = true;
2237
- this.video.muted = true;
2238
- if (!this.shouldContinueLiveStreamDuringAds()) {
2239
- this.video.pause();
2240
- }
2241
2146
  const next = this.adPodQueue.shift();
2242
2147
  this.currentAdIndex++;
2243
2148
  if (this.config.debugAdTiming) {
2244
2149
  console.log(
2245
- `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - keeping content muted/paused`
2150
+ `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - main video stays muted, ad layer stays visible`
2246
2151
  );
2247
2152
  }
2248
2153
  this.playSingleAd(next).catch(() => {
2249
- }).finally(() => {
2250
- this.isTransitioningBetweenAds = false;
2154
+ if (this.config.debugAdTiming) {
2155
+ console.error(
2156
+ "[StormcloudVideoPlayer] Failed to play next ad in pod"
2157
+ );
2158
+ }
2159
+ this.handleAdPodComplete();
2251
2160
  });
2252
2161
  } else {
2253
2162
  if (this.config.debugAdTiming) {
2254
- console.log("[StormcloudVideoPlayer] Ad pod completed");
2163
+ console.log(
2164
+ "[StormcloudVideoPlayer] No more ads in pod - completing ad break"
2165
+ );
2255
2166
  }
2256
- this.inAdBreak = false;
2257
- this.expectedAdBreakDurationMs = void 0;
2258
- this.currentAdBreakStartWallClockMs = void 0;
2259
- this.currentAdIndex = 0;
2260
- this.totalAdsInBreak = 0;
2261
- this.showAds = false;
2262
- this.clearAdStopTimer();
2167
+ this.handleAdPodComplete();
2263
2168
  }
2264
2169
  });
2265
2170
  this.video.addEventListener("timeupdate", () => {
@@ -2977,23 +2882,11 @@ var StormcloudVideoPlayer = class {
2977
2882
  maxExtensionMs
2978
2883
  });
2979
2884
  }
2980
- this.inAdBreak = false;
2981
- this.expectedAdBreakDurationMs = void 0;
2982
- this.currentAdBreakStartWallClockMs = void 0;
2983
- this.showAds = false;
2984
- this.adPodQueue = [];
2985
- this.currentAdIndex = 0;
2986
- this.totalAdsInBreak = 0;
2987
- this.clearAdFailsafeTimer();
2988
2885
  if (adPlaying) {
2989
2886
  this.ima.stop().catch(() => {
2990
2887
  });
2991
- return;
2992
- }
2993
- const originalMutedState = this.ima.getOriginalMutedState();
2994
- if (this.video.muted !== originalMutedState) {
2995
- this.video.muted = originalMutedState;
2996
2888
  }
2889
+ this.handleAdPodComplete();
2997
2890
  }
2998
2891
  scheduleAdStartIn(delayMs) {
2999
2892
  this.clearAdStartTimer();
@@ -3080,17 +2973,11 @@ var StormcloudVideoPlayer = class {
3080
2973
  this.handleAdFailure();
3081
2974
  }
3082
2975
  }
3083
- handleAdFailure() {
2976
+ handleAdPodComplete() {
3084
2977
  var _a;
3085
2978
  if (this.config.debugAdTiming) {
3086
2979
  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
- }
2980
+ "[StormcloudVideoPlayer] Handling ad pod completion - resuming content and hiding ad layer"
3094
2981
  );
3095
2982
  }
3096
2983
  this.inAdBreak = false;
@@ -3103,34 +2990,44 @@ var StormcloudVideoPlayer = class {
3103
2990
  this.showAds = false;
3104
2991
  this.currentAdIndex = 0;
3105
2992
  this.totalAdsInBreak = 0;
3106
- const currentMutedState = this.video.muted;
2993
+ this.ima.stop().catch(() => {
2994
+ });
3107
2995
  const originalMutedState = this.ima.getOriginalMutedState();
3108
2996
  this.video.muted = originalMutedState;
2997
+ this.video.volume = originalMutedState ? 0 : 1;
3109
2998
  if (this.config.debugAdTiming) {
3110
2999
  console.log(
3111
- `[StormcloudVideoPlayer] Restored mute state: ${currentMutedState} -> ${originalMutedState}`
3000
+ `[StormcloudVideoPlayer] Restored main video - muted: ${originalMutedState}, volume: ${this.video.volume}`
3112
3001
  );
3113
3002
  }
3114
- if (this.video.paused) {
3003
+ if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
3115
3004
  if (this.config.debugAdTiming) {
3116
3005
  console.log("[StormcloudVideoPlayer] Resuming paused video");
3117
3006
  }
3118
3007
  (_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
3119
3008
  if (this.config.debugAdTiming) {
3120
3009
  console.error(
3121
- "[StormcloudVideoPlayer] Failed to resume video after ad failure:",
3010
+ "[StormcloudVideoPlayer] Failed to resume video:",
3122
3011
  error
3123
3012
  );
3124
3013
  }
3125
3014
  });
3126
- } else {
3127
- if (this.config.debugAdTiming) {
3128
- console.log(
3129
- "[StormcloudVideoPlayer] Video is already playing, no resume needed"
3130
- );
3131
- }
3132
3015
  }
3133
3016
  }
3017
+ handleAdFailure() {
3018
+ if (this.config.debugAdTiming) {
3019
+ console.log(
3020
+ "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3021
+ {
3022
+ inAdBreak: this.inAdBreak,
3023
+ showAds: this.showAds,
3024
+ videoPaused: this.video.paused,
3025
+ adPlaying: this.ima.isAdPlaying()
3026
+ }
3027
+ );
3028
+ }
3029
+ this.handleAdPodComplete();
3030
+ }
3134
3031
  startAdFailsafeTimer() {
3135
3032
  var _a;
3136
3033
  this.clearAdFailsafeTimer();