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.
@@ -26,7 +26,6 @@ declare class StormcloudVideoPlayer {
26
26
  private bufferedSegmentsCount;
27
27
  private shouldAutoplayAfterBuffering;
28
28
  private hasInitialBufferCompleted;
29
- private isTransitioningBetweenAds;
30
29
  constructor(config: StormcloudVideoPlayerConfig);
31
30
  private createAdPlayer;
32
31
  load(): Promise<void>;
@@ -63,6 +62,7 @@ declare class StormcloudVideoPlayer {
63
62
  private clearAdStartTimer;
64
63
  private updatePtsDrift;
65
64
  private playSingleAd;
65
+ private handleAdPodComplete;
66
66
  private handleAdFailure;
67
67
  private startAdFailsafeTimer;
68
68
  private clearAdFailsafeTimer;
@@ -327,11 +327,12 @@ function createImaController(video, options) {
327
327
  container.style.top = "0";
328
328
  container.style.right = "0";
329
329
  container.style.bottom = "0";
330
- container.style.display = "flex";
330
+ container.style.display = "none";
331
331
  container.style.alignItems = "center";
332
332
  container.style.justifyContent = "center";
333
333
  container.style.pointerEvents = "none";
334
- container.style.zIndex = "2";
334
+ container.style.zIndex = "10";
335
+ container.style.backgroundColor = "#000";
335
336
  (_a = video.parentElement) == null ? void 0 : _a.appendChild(container);
336
337
  adContainerEl = container;
337
338
  adDisplayContainer = new google.ima.AdDisplayContainer(
@@ -401,7 +402,8 @@ function createImaController(video, options) {
401
402
  container.style.alignItems = "center";
402
403
  container.style.justifyContent = "center";
403
404
  container.style.pointerEvents = "none";
404
- container.style.zIndex = "2";
405
+ container.style.zIndex = "10";
406
+ container.style.backgroundColor = "#000";
405
407
  if (!video.parentElement) {
406
408
  throw new Error("Video element has no parent for ad container");
407
409
  }
@@ -499,7 +501,9 @@ function createImaController(video, options) {
499
501
  adsManager.addEventListener(
500
502
  AdEvent.CONTENT_PAUSE_REQUESTED,
501
503
  () => {
502
- console.log("[IMA] Content pause requested");
504
+ console.log(
505
+ "[IMA] Content pause requested - FORCE MUTING main video"
506
+ );
503
507
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
504
508
  video.pause();
505
509
  console.log("[IMA] Video paused (VOD mode)");
@@ -509,14 +513,19 @@ function createImaController(video, options) {
509
513
  );
510
514
  }
511
515
  video.muted = true;
516
+ video.volume = 0;
512
517
  adPlaying = true;
513
518
  setAdPlayingFlag(true);
514
519
  emit("content_pause");
515
520
  }
516
521
  );
517
522
  adsManager.addEventListener(AdEvent.STARTED, () => {
518
- console.log("[IMA] Ad started playing");
523
+ console.log(
524
+ "[IMA] Ad started playing - FORCE MUTING main video"
525
+ );
519
526
  setAdPlayingFlag(true);
527
+ video.muted = true;
528
+ video.volume = 0;
520
529
  if (adContainerEl) {
521
530
  adContainerEl.style.pointerEvents = "auto";
522
531
  adContainerEl.style.display = "flex";
@@ -532,63 +541,12 @@ function createImaController(video, options) {
532
541
  adPlaying = false;
533
542
  setAdPlayingFlag(false);
534
543
  emit("content_resume");
535
- setTimeout(() => {
536
- var _a;
537
- const stillInAdPod = video.dataset.stormcloudAdPlaying === "true";
538
- if (stillInAdPod) {
539
- console.log(
540
- "[IMA] Next ad started - keeping content muted/paused and ad container visible"
541
- );
542
- if (adContainerEl) {
543
- adContainerEl.style.display = "flex";
544
- adContainerEl.style.pointerEvents = "auto";
545
- }
546
- return;
547
- }
548
- console.log("[IMA] No next ad - resuming content");
549
- video.muted = originalMutedState;
550
- if (adContainerEl) {
551
- adContainerEl.style.pointerEvents = "none";
552
- adContainerEl.style.display = "none";
553
- console.log(
554
- "[IMA] Ad container hidden - pointer events disabled"
555
- );
556
- }
557
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
558
- (_a = video.play()) == null ? void 0 : _a.catch(() => {
559
- });
560
- console.log("[IMA] Video resumed (VOD mode)");
561
- } else {
562
- console.log(
563
- "[IMA] Video unmuted (Live mode - was never paused)"
564
- );
565
- }
566
- }, 100);
567
544
  }
568
545
  );
569
546
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
570
- console.log("[IMA] All ads completed");
547
+ console.log("[IMA] All ads completed - notifying parent");
571
548
  adPlaying = false;
572
- video.muted = originalMutedState;
573
549
  setAdPlayingFlag(false);
574
- if (adContainerEl) {
575
- adContainerEl.style.pointerEvents = "none";
576
- adContainerEl.style.display = "none";
577
- console.log(
578
- "[IMA] Ad container hidden after all ads completed"
579
- );
580
- }
581
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
582
- video.play().catch(() => {
583
- });
584
- console.log(
585
- "[IMA] Video resumed after all ads completed (VOD mode)"
586
- );
587
- } else {
588
- console.log(
589
- "[IMA] Video unmuted after all ads completed (Live mode)"
590
- );
591
- }
592
550
  emit("all_ads_completed");
593
551
  });
594
552
  console.log("[IMA] Ads manager event listeners attached");
@@ -711,8 +669,8 @@ function createImaController(video, options) {
711
669
  },
712
670
  async stop() {
713
671
  var _a;
672
+ console.log("[IMA] Stopping ad playback");
714
673
  adPlaying = false;
715
- video.muted = originalMutedState;
716
674
  setAdPlayingFlag(false);
717
675
  if (adContainerEl) {
718
676
  adContainerEl.style.pointerEvents = "none";
@@ -724,13 +682,6 @@ function createImaController(video, options) {
724
682
  } catch {
725
683
  }
726
684
  destroyAdsManager();
727
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
728
- video.play().catch(() => {
729
- });
730
- console.log("[IMA] Video resumed after stop (VOD mode)");
731
- } else {
732
- console.log("[IMA] Video unmuted after stop (Live mode)");
733
- }
734
685
  },
735
686
  destroy() {
736
687
  var _a;
@@ -1139,37 +1090,6 @@ function createHlsAdPlayer(contentVideo, options) {
1139
1090
  adPlaying = false;
1140
1091
  setAdPlayingFlag(false);
1141
1092
  emit("content_resume");
1142
- emit("all_ads_completed");
1143
- setTimeout(() => {
1144
- const stillInAdPod = contentVideo.dataset.stormcloudAdPlaying === "true";
1145
- if (stillInAdPod) {
1146
- console.log(
1147
- "[HlsAdPlayer] Next ad started - keeping content muted/paused and ad container visible"
1148
- );
1149
- if (adContainerEl) {
1150
- adContainerEl.style.display = "flex";
1151
- adContainerEl.style.pointerEvents = "auto";
1152
- }
1153
- return;
1154
- }
1155
- console.log("[HlsAdPlayer] No next ad - resuming content");
1156
- const previousMutedState = contentVideo.muted;
1157
- contentVideo.muted = originalMutedState;
1158
- console.log(
1159
- `[HlsAdPlayer] Restored mute state: ${previousMutedState} -> ${originalMutedState}`
1160
- );
1161
- if (adContainerEl) {
1162
- adContainerEl.style.display = "none";
1163
- adContainerEl.style.pointerEvents = "none";
1164
- }
1165
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1166
- contentVideo.play().catch(() => {
1167
- });
1168
- console.log("[HlsAdPlayer] Content resumed (VOD mode)");
1169
- } else {
1170
- console.log("[HlsAdPlayer] Content unmuted (Live mode)");
1171
- }
1172
- }, 100);
1173
1093
  }
1174
1094
  function handleAdError() {
1175
1095
  console.log("[HlsAdPlayer] Handling ad error");
@@ -1207,7 +1127,7 @@ function createHlsAdPlayer(contentVideo, options) {
1207
1127
  container.style.alignItems = "center";
1208
1128
  container.style.justifyContent = "center";
1209
1129
  container.style.pointerEvents = "none";
1210
- container.style.zIndex = "2";
1130
+ container.style.zIndex = "10";
1211
1131
  container.style.backgroundColor = "#000";
1212
1132
  (_a = contentVideo.parentElement) == null ? void 0 : _a.appendChild(container);
1213
1133
  adContainerEl = container;
@@ -1281,7 +1201,9 @@ function createHlsAdPlayer(contentVideo, options) {
1281
1201
  } else {
1282
1202
  console.log("[HlsAdPlayer] Content continues (Live mode)");
1283
1203
  }
1204
+ console.log("[HlsAdPlayer] FORCE MUTING main video");
1284
1205
  contentVideo.muted = true;
1206
+ contentVideo.volume = 0;
1285
1207
  adPlaying = true;
1286
1208
  setAdPlayingFlag(true);
1287
1209
  if (adVideoElement) {
@@ -1345,7 +1267,6 @@ function createHlsAdPlayer(contentVideo, options) {
1345
1267
  console.log("[HlsAdPlayer] Stopping ad");
1346
1268
  adPlaying = false;
1347
1269
  setAdPlayingFlag(false);
1348
- contentVideo.muted = originalMutedState;
1349
1270
  if (adContainerEl) {
1350
1271
  adContainerEl.style.display = "none";
1351
1272
  adContainerEl.style.pointerEvents = "none";
@@ -1358,10 +1279,6 @@ function createHlsAdPlayer(contentVideo, options) {
1358
1279
  adVideoElement.pause();
1359
1280
  adVideoElement.src = "";
1360
1281
  }
1361
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1362
- contentVideo.play().catch(() => {
1363
- });
1364
- }
1365
1282
  currentAd = void 0;
1366
1283
  },
1367
1284
  destroy() {
@@ -1907,7 +1824,6 @@ var StormcloudVideoPlayer = class {
1907
1824
  this.bufferedSegmentsCount = 0;
1908
1825
  this.shouldAutoplayAfterBuffering = false;
1909
1826
  this.hasInitialBufferCompleted = false;
1910
- this.isTransitioningBetweenAds = false;
1911
1827
  initializePolyfills();
1912
1828
  const browserOverrides = getBrowserConfigOverrides();
1913
1829
  this.config = { ...config, ...browserOverrides };
@@ -2171,9 +2087,12 @@ var StormcloudVideoPlayer = class {
2171
2087
  this.ima.on("all_ads_completed", () => {
2172
2088
  if (this.config.debugAdTiming) {
2173
2089
  console.log(
2174
- "[StormcloudVideoPlayer] IMA all_ads_completed event received"
2090
+ "[StormcloudVideoPlayer] IMA all_ads_completed event received - ending ad break"
2175
2091
  );
2176
2092
  }
2093
+ if (this.inAdBreak) {
2094
+ this.handleAdPodComplete();
2095
+ }
2177
2096
  });
2178
2097
  this.ima.on("ad_error", () => {
2179
2098
  if (this.config.debugAdTiming) {
@@ -2212,57 +2131,43 @@ var StormcloudVideoPlayer = class {
2212
2131
  "[StormcloudVideoPlayer] IMA content_resume event received",
2213
2132
  {
2214
2133
  inAdBreak: this.inAdBreak,
2215
- isTransitioningBetweenAds: this.isTransitioningBetweenAds,
2216
2134
  pendingAds: this.adPodQueue.length
2217
2135
  }
2218
2136
  );
2219
2137
  }
2220
2138
  this.clearAdFailsafeTimer();
2221
- if (this.isTransitioningBetweenAds) {
2222
- if (this.config.debugAdTiming) {
2223
- console.log(
2224
- "[StormcloudVideoPlayer] Transitioning between ads - keeping content muted/paused"
2225
- );
2226
- }
2227
- return;
2228
- }
2229
2139
  if (!this.inAdBreak) {
2230
2140
  if (this.config.debugAdTiming) {
2231
2141
  console.log(
2232
- "[StormcloudVideoPlayer] Not in ad break, allowing normal content resume"
2142
+ "[StormcloudVideoPlayer] Not in ad break - this shouldn't happen during pod"
2233
2143
  );
2234
2144
  }
2235
2145
  return;
2236
2146
  }
2237
2147
  const remaining = this.getRemainingAdMs();
2238
2148
  if (remaining > 500 && this.adPodQueue.length > 0) {
2239
- this.isTransitioningBetweenAds = true;
2240
- this.video.muted = true;
2241
- if (!this.shouldContinueLiveStreamDuringAds()) {
2242
- this.video.pause();
2243
- }
2244
2149
  const next = this.adPodQueue.shift();
2245
2150
  this.currentAdIndex++;
2246
2151
  if (this.config.debugAdTiming) {
2247
2152
  console.log(
2248
- `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - keeping content muted/paused`
2153
+ `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - main video stays muted, ad layer stays visible`
2249
2154
  );
2250
2155
  }
2251
2156
  this.playSingleAd(next).catch(() => {
2252
- }).finally(() => {
2253
- this.isTransitioningBetweenAds = false;
2157
+ if (this.config.debugAdTiming) {
2158
+ console.error(
2159
+ "[StormcloudVideoPlayer] Failed to play next ad in pod"
2160
+ );
2161
+ }
2162
+ this.handleAdPodComplete();
2254
2163
  });
2255
2164
  } else {
2256
2165
  if (this.config.debugAdTiming) {
2257
- console.log("[StormcloudVideoPlayer] Ad pod completed");
2166
+ console.log(
2167
+ "[StormcloudVideoPlayer] No more ads in pod - completing ad break"
2168
+ );
2258
2169
  }
2259
- this.inAdBreak = false;
2260
- this.expectedAdBreakDurationMs = void 0;
2261
- this.currentAdBreakStartWallClockMs = void 0;
2262
- this.currentAdIndex = 0;
2263
- this.totalAdsInBreak = 0;
2264
- this.showAds = false;
2265
- this.clearAdStopTimer();
2170
+ this.handleAdPodComplete();
2266
2171
  }
2267
2172
  });
2268
2173
  this.video.addEventListener("timeupdate", () => {
@@ -2980,23 +2885,11 @@ var StormcloudVideoPlayer = class {
2980
2885
  maxExtensionMs
2981
2886
  });
2982
2887
  }
2983
- this.inAdBreak = false;
2984
- this.expectedAdBreakDurationMs = void 0;
2985
- this.currentAdBreakStartWallClockMs = void 0;
2986
- this.showAds = false;
2987
- this.adPodQueue = [];
2988
- this.currentAdIndex = 0;
2989
- this.totalAdsInBreak = 0;
2990
- this.clearAdFailsafeTimer();
2991
2888
  if (adPlaying) {
2992
2889
  this.ima.stop().catch(() => {
2993
2890
  });
2994
- return;
2995
- }
2996
- const originalMutedState = this.ima.getOriginalMutedState();
2997
- if (this.video.muted !== originalMutedState) {
2998
- this.video.muted = originalMutedState;
2999
2891
  }
2892
+ this.handleAdPodComplete();
3000
2893
  }
3001
2894
  scheduleAdStartIn(delayMs) {
3002
2895
  this.clearAdStartTimer();
@@ -3083,17 +2976,11 @@ var StormcloudVideoPlayer = class {
3083
2976
  this.handleAdFailure();
3084
2977
  }
3085
2978
  }
3086
- handleAdFailure() {
2979
+ handleAdPodComplete() {
3087
2980
  var _a;
3088
2981
  if (this.config.debugAdTiming) {
3089
2982
  console.log(
3090
- "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3091
- {
3092
- inAdBreak: this.inAdBreak,
3093
- showAds: this.showAds,
3094
- videoPaused: this.video.paused,
3095
- adPlaying: this.ima.isAdPlaying()
3096
- }
2983
+ "[StormcloudVideoPlayer] Handling ad pod completion - resuming content and hiding ad layer"
3097
2984
  );
3098
2985
  }
3099
2986
  this.inAdBreak = false;
@@ -3106,34 +2993,44 @@ var StormcloudVideoPlayer = class {
3106
2993
  this.showAds = false;
3107
2994
  this.currentAdIndex = 0;
3108
2995
  this.totalAdsInBreak = 0;
3109
- const currentMutedState = this.video.muted;
2996
+ this.ima.stop().catch(() => {
2997
+ });
3110
2998
  const originalMutedState = this.ima.getOriginalMutedState();
3111
2999
  this.video.muted = originalMutedState;
3000
+ this.video.volume = originalMutedState ? 0 : 1;
3112
3001
  if (this.config.debugAdTiming) {
3113
3002
  console.log(
3114
- `[StormcloudVideoPlayer] Restored mute state: ${currentMutedState} -> ${originalMutedState}`
3003
+ `[StormcloudVideoPlayer] Restored main video - muted: ${originalMutedState}, volume: ${this.video.volume}`
3115
3004
  );
3116
3005
  }
3117
- if (this.video.paused) {
3006
+ if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
3118
3007
  if (this.config.debugAdTiming) {
3119
3008
  console.log("[StormcloudVideoPlayer] Resuming paused video");
3120
3009
  }
3121
3010
  (_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
3122
3011
  if (this.config.debugAdTiming) {
3123
3012
  console.error(
3124
- "[StormcloudVideoPlayer] Failed to resume video after ad failure:",
3013
+ "[StormcloudVideoPlayer] Failed to resume video:",
3125
3014
  error
3126
3015
  );
3127
3016
  }
3128
3017
  });
3129
- } else {
3130
- if (this.config.debugAdTiming) {
3131
- console.log(
3132
- "[StormcloudVideoPlayer] Video is already playing, no resume needed"
3133
- );
3134
- }
3135
3018
  }
3136
3019
  }
3020
+ handleAdFailure() {
3021
+ if (this.config.debugAdTiming) {
3022
+ console.log(
3023
+ "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3024
+ {
3025
+ inAdBreak: this.inAdBreak,
3026
+ showAds: this.showAds,
3027
+ videoPaused: this.video.paused,
3028
+ adPlaying: this.ima.isAdPlaying()
3029
+ }
3030
+ );
3031
+ }
3032
+ this.handleAdPodComplete();
3033
+ }
3137
3034
  startAdFailsafeTimer() {
3138
3035
  var _a;
3139
3036
  this.clearAdFailsafeTimer();