stormcloud-video-player 0.2.20 → 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.
package/lib/index.d.cts CHANGED
@@ -122,7 +122,6 @@ declare class StormcloudVideoPlayer {
122
122
  private bufferedSegmentsCount;
123
123
  private shouldAutoplayAfterBuffering;
124
124
  private hasInitialBufferCompleted;
125
- private isTransitioningBetweenAds;
126
125
  constructor(config: StormcloudVideoPlayerConfig);
127
126
  private createAdPlayer;
128
127
  load(): Promise<void>;
@@ -159,6 +158,7 @@ declare class StormcloudVideoPlayer {
159
158
  private clearAdStartTimer;
160
159
  private updatePtsDrift;
161
160
  private playSingleAd;
161
+ private handleAdPodComplete;
162
162
  private handleAdFailure;
163
163
  private startAdFailsafeTimer;
164
164
  private clearAdFailsafeTimer;
package/lib/index.d.ts CHANGED
@@ -122,7 +122,6 @@ declare class StormcloudVideoPlayer {
122
122
  private bufferedSegmentsCount;
123
123
  private shouldAutoplayAfterBuffering;
124
124
  private hasInitialBufferCompleted;
125
- private isTransitioningBetweenAds;
126
125
  constructor(config: StormcloudVideoPlayerConfig);
127
126
  private createAdPlayer;
128
127
  load(): Promise<void>;
@@ -159,6 +158,7 @@ declare class StormcloudVideoPlayer {
159
158
  private clearAdStartTimer;
160
159
  private updatePtsDrift;
161
160
  private playSingleAd;
161
+ private handleAdPodComplete;
162
162
  private handleAdFailure;
163
163
  private startAdFailsafeTimer;
164
164
  private clearAdFailsafeTimer;
package/lib/index.js CHANGED
@@ -322,11 +322,12 @@ function createImaController(video, options) {
322
322
  container.style.top = "0";
323
323
  container.style.right = "0";
324
324
  container.style.bottom = "0";
325
- container.style.display = "flex";
325
+ container.style.display = "none";
326
326
  container.style.alignItems = "center";
327
327
  container.style.justifyContent = "center";
328
328
  container.style.pointerEvents = "none";
329
- container.style.zIndex = "2";
329
+ container.style.zIndex = "10";
330
+ container.style.backgroundColor = "#000";
330
331
  (_a = video.parentElement) == null ? void 0 : _a.appendChild(container);
331
332
  adContainerEl = container;
332
333
  adDisplayContainer = new google.ima.AdDisplayContainer(
@@ -396,7 +397,8 @@ function createImaController(video, options) {
396
397
  container.style.alignItems = "center";
397
398
  container.style.justifyContent = "center";
398
399
  container.style.pointerEvents = "none";
399
- container.style.zIndex = "2";
400
+ container.style.zIndex = "10";
401
+ container.style.backgroundColor = "#000";
400
402
  if (!video.parentElement) {
401
403
  throw new Error("Video element has no parent for ad container");
402
404
  }
@@ -527,63 +529,12 @@ function createImaController(video, options) {
527
529
  adPlaying = false;
528
530
  setAdPlayingFlag(false);
529
531
  emit("content_resume");
530
- setTimeout(() => {
531
- var _a;
532
- const stillInAdPod = video.dataset.stormcloudAdPlaying === "true";
533
- if (stillInAdPod) {
534
- console.log(
535
- "[IMA] Next ad started - keeping content muted/paused and ad container visible"
536
- );
537
- if (adContainerEl) {
538
- adContainerEl.style.display = "flex";
539
- adContainerEl.style.pointerEvents = "auto";
540
- }
541
- return;
542
- }
543
- console.log("[IMA] No next ad - resuming content");
544
- video.muted = originalMutedState;
545
- if (adContainerEl) {
546
- adContainerEl.style.pointerEvents = "none";
547
- adContainerEl.style.display = "none";
548
- console.log(
549
- "[IMA] Ad container hidden - pointer events disabled"
550
- );
551
- }
552
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
553
- (_a = video.play()) == null ? void 0 : _a.catch(() => {
554
- });
555
- console.log("[IMA] Video resumed (VOD mode)");
556
- } else {
557
- console.log(
558
- "[IMA] Video unmuted (Live mode - was never paused)"
559
- );
560
- }
561
- }, 100);
562
532
  }
563
533
  );
564
534
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
565
- console.log("[IMA] All ads completed");
535
+ console.log("[IMA] All ads completed - notifying parent");
566
536
  adPlaying = false;
567
- video.muted = originalMutedState;
568
537
  setAdPlayingFlag(false);
569
- if (adContainerEl) {
570
- adContainerEl.style.pointerEvents = "none";
571
- adContainerEl.style.display = "none";
572
- console.log(
573
- "[IMA] Ad container hidden after all ads completed"
574
- );
575
- }
576
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
577
- video.play().catch(() => {
578
- });
579
- console.log(
580
- "[IMA] Video resumed after all ads completed (VOD mode)"
581
- );
582
- } else {
583
- console.log(
584
- "[IMA] Video unmuted after all ads completed (Live mode)"
585
- );
586
- }
587
538
  emit("all_ads_completed");
588
539
  });
589
540
  console.log("[IMA] Ads manager event listeners attached");
@@ -706,8 +657,8 @@ function createImaController(video, options) {
706
657
  },
707
658
  async stop() {
708
659
  var _a;
660
+ console.log("[IMA] Stopping ad playback");
709
661
  adPlaying = false;
710
- video.muted = originalMutedState;
711
662
  setAdPlayingFlag(false);
712
663
  if (adContainerEl) {
713
664
  adContainerEl.style.pointerEvents = "none";
@@ -719,13 +670,6 @@ function createImaController(video, options) {
719
670
  } catch {
720
671
  }
721
672
  destroyAdsManager();
722
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
723
- video.play().catch(() => {
724
- });
725
- console.log("[IMA] Video resumed after stop (VOD mode)");
726
- } else {
727
- console.log("[IMA] Video unmuted after stop (Live mode)");
728
- }
729
673
  },
730
674
  destroy() {
731
675
  var _a;
@@ -1134,37 +1078,6 @@ function createHlsAdPlayer(contentVideo, options) {
1134
1078
  adPlaying = false;
1135
1079
  setAdPlayingFlag(false);
1136
1080
  emit("content_resume");
1137
- emit("all_ads_completed");
1138
- setTimeout(() => {
1139
- const stillInAdPod = contentVideo.dataset.stormcloudAdPlaying === "true";
1140
- if (stillInAdPod) {
1141
- console.log(
1142
- "[HlsAdPlayer] Next ad started - keeping content muted/paused and ad container visible"
1143
- );
1144
- if (adContainerEl) {
1145
- adContainerEl.style.display = "flex";
1146
- adContainerEl.style.pointerEvents = "auto";
1147
- }
1148
- return;
1149
- }
1150
- console.log("[HlsAdPlayer] No next ad - resuming content");
1151
- const previousMutedState = contentVideo.muted;
1152
- contentVideo.muted = originalMutedState;
1153
- console.log(
1154
- `[HlsAdPlayer] Restored mute state: ${previousMutedState} -> ${originalMutedState}`
1155
- );
1156
- if (adContainerEl) {
1157
- adContainerEl.style.display = "none";
1158
- adContainerEl.style.pointerEvents = "none";
1159
- }
1160
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1161
- contentVideo.play().catch(() => {
1162
- });
1163
- console.log("[HlsAdPlayer] Content resumed (VOD mode)");
1164
- } else {
1165
- console.log("[HlsAdPlayer] Content unmuted (Live mode)");
1166
- }
1167
- }, 100);
1168
1081
  }
1169
1082
  function handleAdError() {
1170
1083
  console.log("[HlsAdPlayer] Handling ad error");
@@ -1202,7 +1115,7 @@ function createHlsAdPlayer(contentVideo, options) {
1202
1115
  container.style.alignItems = "center";
1203
1116
  container.style.justifyContent = "center";
1204
1117
  container.style.pointerEvents = "none";
1205
- container.style.zIndex = "2";
1118
+ container.style.zIndex = "10";
1206
1119
  container.style.backgroundColor = "#000";
1207
1120
  (_a = contentVideo.parentElement) == null ? void 0 : _a.appendChild(container);
1208
1121
  adContainerEl = container;
@@ -1340,7 +1253,6 @@ function createHlsAdPlayer(contentVideo, options) {
1340
1253
  console.log("[HlsAdPlayer] Stopping ad");
1341
1254
  adPlaying = false;
1342
1255
  setAdPlayingFlag(false);
1343
- contentVideo.muted = originalMutedState;
1344
1256
  if (adContainerEl) {
1345
1257
  adContainerEl.style.display = "none";
1346
1258
  adContainerEl.style.pointerEvents = "none";
@@ -1353,10 +1265,6 @@ function createHlsAdPlayer(contentVideo, options) {
1353
1265
  adVideoElement.pause();
1354
1266
  adVideoElement.src = "";
1355
1267
  }
1356
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1357
- contentVideo.play().catch(() => {
1358
- });
1359
- }
1360
1268
  currentAd = void 0;
1361
1269
  },
1362
1270
  destroy() {
@@ -1902,7 +1810,6 @@ var StormcloudVideoPlayer = class {
1902
1810
  this.bufferedSegmentsCount = 0;
1903
1811
  this.shouldAutoplayAfterBuffering = false;
1904
1812
  this.hasInitialBufferCompleted = false;
1905
- this.isTransitioningBetweenAds = false;
1906
1813
  initializePolyfills();
1907
1814
  const browserOverrides = getBrowserConfigOverrides();
1908
1815
  this.config = { ...config, ...browserOverrides };
@@ -2166,9 +2073,12 @@ var StormcloudVideoPlayer = class {
2166
2073
  this.ima.on("all_ads_completed", () => {
2167
2074
  if (this.config.debugAdTiming) {
2168
2075
  console.log(
2169
- "[StormcloudVideoPlayer] IMA all_ads_completed event received"
2076
+ "[StormcloudVideoPlayer] IMA all_ads_completed event received - ending ad break"
2170
2077
  );
2171
2078
  }
2079
+ if (this.inAdBreak) {
2080
+ this.handleAdPodComplete();
2081
+ }
2172
2082
  });
2173
2083
  this.ima.on("ad_error", () => {
2174
2084
  if (this.config.debugAdTiming) {
@@ -2207,57 +2117,43 @@ var StormcloudVideoPlayer = class {
2207
2117
  "[StormcloudVideoPlayer] IMA content_resume event received",
2208
2118
  {
2209
2119
  inAdBreak: this.inAdBreak,
2210
- isTransitioningBetweenAds: this.isTransitioningBetweenAds,
2211
2120
  pendingAds: this.adPodQueue.length
2212
2121
  }
2213
2122
  );
2214
2123
  }
2215
2124
  this.clearAdFailsafeTimer();
2216
- if (this.isTransitioningBetweenAds) {
2217
- if (this.config.debugAdTiming) {
2218
- console.log(
2219
- "[StormcloudVideoPlayer] Transitioning between ads - keeping content muted/paused"
2220
- );
2221
- }
2222
- return;
2223
- }
2224
2125
  if (!this.inAdBreak) {
2225
2126
  if (this.config.debugAdTiming) {
2226
2127
  console.log(
2227
- "[StormcloudVideoPlayer] Not in ad break, allowing normal content resume"
2128
+ "[StormcloudVideoPlayer] Not in ad break - this shouldn't happen during pod"
2228
2129
  );
2229
2130
  }
2230
2131
  return;
2231
2132
  }
2232
2133
  const remaining = this.getRemainingAdMs();
2233
2134
  if (remaining > 500 && this.adPodQueue.length > 0) {
2234
- this.isTransitioningBetweenAds = true;
2235
- this.video.muted = true;
2236
- if (!this.shouldContinueLiveStreamDuringAds()) {
2237
- this.video.pause();
2238
- }
2239
2135
  const next = this.adPodQueue.shift();
2240
2136
  this.currentAdIndex++;
2241
2137
  if (this.config.debugAdTiming) {
2242
2138
  console.log(
2243
- `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - keeping content muted/paused`
2139
+ `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - main video stays muted, ad layer stays visible`
2244
2140
  );
2245
2141
  }
2246
2142
  this.playSingleAd(next).catch(() => {
2247
- }).finally(() => {
2248
- this.isTransitioningBetweenAds = false;
2143
+ if (this.config.debugAdTiming) {
2144
+ console.error(
2145
+ "[StormcloudVideoPlayer] Failed to play next ad in pod"
2146
+ );
2147
+ }
2148
+ this.handleAdPodComplete();
2249
2149
  });
2250
2150
  } else {
2251
2151
  if (this.config.debugAdTiming) {
2252
- console.log("[StormcloudVideoPlayer] Ad pod completed");
2152
+ console.log(
2153
+ "[StormcloudVideoPlayer] No more ads in pod - completing ad break"
2154
+ );
2253
2155
  }
2254
- this.inAdBreak = false;
2255
- this.expectedAdBreakDurationMs = void 0;
2256
- this.currentAdBreakStartWallClockMs = void 0;
2257
- this.currentAdIndex = 0;
2258
- this.totalAdsInBreak = 0;
2259
- this.showAds = false;
2260
- this.clearAdStopTimer();
2156
+ this.handleAdPodComplete();
2261
2157
  }
2262
2158
  });
2263
2159
  this.video.addEventListener("timeupdate", () => {
@@ -2975,23 +2871,11 @@ var StormcloudVideoPlayer = class {
2975
2871
  maxExtensionMs
2976
2872
  });
2977
2873
  }
2978
- this.inAdBreak = false;
2979
- this.expectedAdBreakDurationMs = void 0;
2980
- this.currentAdBreakStartWallClockMs = void 0;
2981
- this.showAds = false;
2982
- this.adPodQueue = [];
2983
- this.currentAdIndex = 0;
2984
- this.totalAdsInBreak = 0;
2985
- this.clearAdFailsafeTimer();
2986
2874
  if (adPlaying) {
2987
2875
  this.ima.stop().catch(() => {
2988
2876
  });
2989
- return;
2990
- }
2991
- const originalMutedState = this.ima.getOriginalMutedState();
2992
- if (this.video.muted !== originalMutedState) {
2993
- this.video.muted = originalMutedState;
2994
2877
  }
2878
+ this.handleAdPodComplete();
2995
2879
  }
2996
2880
  scheduleAdStartIn(delayMs) {
2997
2881
  this.clearAdStartTimer();
@@ -3078,17 +2962,11 @@ var StormcloudVideoPlayer = class {
3078
2962
  this.handleAdFailure();
3079
2963
  }
3080
2964
  }
3081
- handleAdFailure() {
2965
+ handleAdPodComplete() {
3082
2966
  var _a;
3083
2967
  if (this.config.debugAdTiming) {
3084
2968
  console.log(
3085
- "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3086
- {
3087
- inAdBreak: this.inAdBreak,
3088
- showAds: this.showAds,
3089
- videoPaused: this.video.paused,
3090
- adPlaying: this.ima.isAdPlaying()
3091
- }
2969
+ "[StormcloudVideoPlayer] Handling ad pod completion - resuming content"
3092
2970
  );
3093
2971
  }
3094
2972
  this.inAdBreak = false;
@@ -3101,34 +2979,41 @@ var StormcloudVideoPlayer = class {
3101
2979
  this.showAds = false;
3102
2980
  this.currentAdIndex = 0;
3103
2981
  this.totalAdsInBreak = 0;
3104
- const currentMutedState = this.video.muted;
3105
2982
  const originalMutedState = this.ima.getOriginalMutedState();
3106
2983
  this.video.muted = originalMutedState;
3107
2984
  if (this.config.debugAdTiming) {
3108
2985
  console.log(
3109
- `[StormcloudVideoPlayer] Restored mute state: ${currentMutedState} -> ${originalMutedState}`
2986
+ `[StormcloudVideoPlayer] Restored main video mute state to: ${originalMutedState}`
3110
2987
  );
3111
2988
  }
3112
- if (this.video.paused) {
2989
+ if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
3113
2990
  if (this.config.debugAdTiming) {
3114
2991
  console.log("[StormcloudVideoPlayer] Resuming paused video");
3115
2992
  }
3116
2993
  (_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
3117
2994
  if (this.config.debugAdTiming) {
3118
2995
  console.error(
3119
- "[StormcloudVideoPlayer] Failed to resume video after ad failure:",
2996
+ "[StormcloudVideoPlayer] Failed to resume video:",
3120
2997
  error
3121
2998
  );
3122
2999
  }
3123
3000
  });
3124
- } else {
3125
- if (this.config.debugAdTiming) {
3126
- console.log(
3127
- "[StormcloudVideoPlayer] Video is already playing, no resume needed"
3128
- );
3129
- }
3130
3001
  }
3131
3002
  }
3003
+ handleAdFailure() {
3004
+ if (this.config.debugAdTiming) {
3005
+ console.log(
3006
+ "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3007
+ {
3008
+ inAdBreak: this.inAdBreak,
3009
+ showAds: this.showAds,
3010
+ videoPaused: this.video.paused,
3011
+ adPlaying: this.ima.isAdPlaying()
3012
+ }
3013
+ );
3014
+ }
3015
+ this.handleAdPodComplete();
3016
+ }
3132
3017
  startAdFailsafeTimer() {
3133
3018
  var _a;
3134
3019
  this.clearAdFailsafeTimer();