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.
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
  }
@@ -494,7 +496,9 @@ function createImaController(video, options) {
494
496
  adsManager.addEventListener(
495
497
  AdEvent.CONTENT_PAUSE_REQUESTED,
496
498
  () => {
497
- console.log("[IMA] Content pause requested");
499
+ console.log(
500
+ "[IMA] Content pause requested - FORCE MUTING main video"
501
+ );
498
502
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
499
503
  video.pause();
500
504
  console.log("[IMA] Video paused (VOD mode)");
@@ -504,14 +508,19 @@ function createImaController(video, options) {
504
508
  );
505
509
  }
506
510
  video.muted = true;
511
+ video.volume = 0;
507
512
  adPlaying = true;
508
513
  setAdPlayingFlag(true);
509
514
  emit("content_pause");
510
515
  }
511
516
  );
512
517
  adsManager.addEventListener(AdEvent.STARTED, () => {
513
- console.log("[IMA] Ad started playing");
518
+ console.log(
519
+ "[IMA] Ad started playing - FORCE MUTING main video"
520
+ );
514
521
  setAdPlayingFlag(true);
522
+ video.muted = true;
523
+ video.volume = 0;
515
524
  if (adContainerEl) {
516
525
  adContainerEl.style.pointerEvents = "auto";
517
526
  adContainerEl.style.display = "flex";
@@ -527,63 +536,12 @@ function createImaController(video, options) {
527
536
  adPlaying = false;
528
537
  setAdPlayingFlag(false);
529
538
  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
539
  }
563
540
  );
564
541
  adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, () => {
565
- console.log("[IMA] All ads completed");
542
+ console.log("[IMA] All ads completed - notifying parent");
566
543
  adPlaying = false;
567
- video.muted = originalMutedState;
568
544
  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
545
  emit("all_ads_completed");
588
546
  });
589
547
  console.log("[IMA] Ads manager event listeners attached");
@@ -706,8 +664,8 @@ function createImaController(video, options) {
706
664
  },
707
665
  async stop() {
708
666
  var _a;
667
+ console.log("[IMA] Stopping ad playback");
709
668
  adPlaying = false;
710
- video.muted = originalMutedState;
711
669
  setAdPlayingFlag(false);
712
670
  if (adContainerEl) {
713
671
  adContainerEl.style.pointerEvents = "none";
@@ -719,13 +677,6 @@ function createImaController(video, options) {
719
677
  } catch {
720
678
  }
721
679
  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
680
  },
730
681
  destroy() {
731
682
  var _a;
@@ -1134,37 +1085,6 @@ function createHlsAdPlayer(contentVideo, options) {
1134
1085
  adPlaying = false;
1135
1086
  setAdPlayingFlag(false);
1136
1087
  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
1088
  }
1169
1089
  function handleAdError() {
1170
1090
  console.log("[HlsAdPlayer] Handling ad error");
@@ -1202,7 +1122,7 @@ function createHlsAdPlayer(contentVideo, options) {
1202
1122
  container.style.alignItems = "center";
1203
1123
  container.style.justifyContent = "center";
1204
1124
  container.style.pointerEvents = "none";
1205
- container.style.zIndex = "2";
1125
+ container.style.zIndex = "10";
1206
1126
  container.style.backgroundColor = "#000";
1207
1127
  (_a = contentVideo.parentElement) == null ? void 0 : _a.appendChild(container);
1208
1128
  adContainerEl = container;
@@ -1276,7 +1196,9 @@ function createHlsAdPlayer(contentVideo, options) {
1276
1196
  } else {
1277
1197
  console.log("[HlsAdPlayer] Content continues (Live mode)");
1278
1198
  }
1199
+ console.log("[HlsAdPlayer] FORCE MUTING main video");
1279
1200
  contentVideo.muted = true;
1201
+ contentVideo.volume = 0;
1280
1202
  adPlaying = true;
1281
1203
  setAdPlayingFlag(true);
1282
1204
  if (adVideoElement) {
@@ -1340,7 +1262,6 @@ function createHlsAdPlayer(contentVideo, options) {
1340
1262
  console.log("[HlsAdPlayer] Stopping ad");
1341
1263
  adPlaying = false;
1342
1264
  setAdPlayingFlag(false);
1343
- contentVideo.muted = originalMutedState;
1344
1265
  if (adContainerEl) {
1345
1266
  adContainerEl.style.display = "none";
1346
1267
  adContainerEl.style.pointerEvents = "none";
@@ -1353,10 +1274,6 @@ function createHlsAdPlayer(contentVideo, options) {
1353
1274
  adVideoElement.pause();
1354
1275
  adVideoElement.src = "";
1355
1276
  }
1356
- if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1357
- contentVideo.play().catch(() => {
1358
- });
1359
- }
1360
1277
  currentAd = void 0;
1361
1278
  },
1362
1279
  destroy() {
@@ -1902,7 +1819,6 @@ var StormcloudVideoPlayer = class {
1902
1819
  this.bufferedSegmentsCount = 0;
1903
1820
  this.shouldAutoplayAfterBuffering = false;
1904
1821
  this.hasInitialBufferCompleted = false;
1905
- this.isTransitioningBetweenAds = false;
1906
1822
  initializePolyfills();
1907
1823
  const browserOverrides = getBrowserConfigOverrides();
1908
1824
  this.config = { ...config, ...browserOverrides };
@@ -2166,9 +2082,12 @@ var StormcloudVideoPlayer = class {
2166
2082
  this.ima.on("all_ads_completed", () => {
2167
2083
  if (this.config.debugAdTiming) {
2168
2084
  console.log(
2169
- "[StormcloudVideoPlayer] IMA all_ads_completed event received"
2085
+ "[StormcloudVideoPlayer] IMA all_ads_completed event received - ending ad break"
2170
2086
  );
2171
2087
  }
2088
+ if (this.inAdBreak) {
2089
+ this.handleAdPodComplete();
2090
+ }
2172
2091
  });
2173
2092
  this.ima.on("ad_error", () => {
2174
2093
  if (this.config.debugAdTiming) {
@@ -2207,57 +2126,43 @@ var StormcloudVideoPlayer = class {
2207
2126
  "[StormcloudVideoPlayer] IMA content_resume event received",
2208
2127
  {
2209
2128
  inAdBreak: this.inAdBreak,
2210
- isTransitioningBetweenAds: this.isTransitioningBetweenAds,
2211
2129
  pendingAds: this.adPodQueue.length
2212
2130
  }
2213
2131
  );
2214
2132
  }
2215
2133
  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
2134
  if (!this.inAdBreak) {
2225
2135
  if (this.config.debugAdTiming) {
2226
2136
  console.log(
2227
- "[StormcloudVideoPlayer] Not in ad break, allowing normal content resume"
2137
+ "[StormcloudVideoPlayer] Not in ad break - this shouldn't happen during pod"
2228
2138
  );
2229
2139
  }
2230
2140
  return;
2231
2141
  }
2232
2142
  const remaining = this.getRemainingAdMs();
2233
2143
  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
2144
  const next = this.adPodQueue.shift();
2240
2145
  this.currentAdIndex++;
2241
2146
  if (this.config.debugAdTiming) {
2242
2147
  console.log(
2243
- `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - keeping content muted/paused`
2148
+ `[StormcloudVideoPlayer] Playing next ad in pod (${this.currentAdIndex}/${this.totalAdsInBreak}) - main video stays muted, ad layer stays visible`
2244
2149
  );
2245
2150
  }
2246
2151
  this.playSingleAd(next).catch(() => {
2247
- }).finally(() => {
2248
- this.isTransitioningBetweenAds = false;
2152
+ if (this.config.debugAdTiming) {
2153
+ console.error(
2154
+ "[StormcloudVideoPlayer] Failed to play next ad in pod"
2155
+ );
2156
+ }
2157
+ this.handleAdPodComplete();
2249
2158
  });
2250
2159
  } else {
2251
2160
  if (this.config.debugAdTiming) {
2252
- console.log("[StormcloudVideoPlayer] Ad pod completed");
2161
+ console.log(
2162
+ "[StormcloudVideoPlayer] No more ads in pod - completing ad break"
2163
+ );
2253
2164
  }
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();
2165
+ this.handleAdPodComplete();
2261
2166
  }
2262
2167
  });
2263
2168
  this.video.addEventListener("timeupdate", () => {
@@ -2975,23 +2880,11 @@ var StormcloudVideoPlayer = class {
2975
2880
  maxExtensionMs
2976
2881
  });
2977
2882
  }
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
2883
  if (adPlaying) {
2987
2884
  this.ima.stop().catch(() => {
2988
2885
  });
2989
- return;
2990
- }
2991
- const originalMutedState = this.ima.getOriginalMutedState();
2992
- if (this.video.muted !== originalMutedState) {
2993
- this.video.muted = originalMutedState;
2994
2886
  }
2887
+ this.handleAdPodComplete();
2995
2888
  }
2996
2889
  scheduleAdStartIn(delayMs) {
2997
2890
  this.clearAdStartTimer();
@@ -3078,17 +2971,11 @@ var StormcloudVideoPlayer = class {
3078
2971
  this.handleAdFailure();
3079
2972
  }
3080
2973
  }
3081
- handleAdFailure() {
2974
+ handleAdPodComplete() {
3082
2975
  var _a;
3083
2976
  if (this.config.debugAdTiming) {
3084
2977
  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
- }
2978
+ "[StormcloudVideoPlayer] Handling ad pod completion - resuming content and hiding ad layer"
3092
2979
  );
3093
2980
  }
3094
2981
  this.inAdBreak = false;
@@ -3101,34 +2988,44 @@ var StormcloudVideoPlayer = class {
3101
2988
  this.showAds = false;
3102
2989
  this.currentAdIndex = 0;
3103
2990
  this.totalAdsInBreak = 0;
3104
- const currentMutedState = this.video.muted;
2991
+ this.ima.stop().catch(() => {
2992
+ });
3105
2993
  const originalMutedState = this.ima.getOriginalMutedState();
3106
2994
  this.video.muted = originalMutedState;
2995
+ this.video.volume = originalMutedState ? 0 : 1;
3107
2996
  if (this.config.debugAdTiming) {
3108
2997
  console.log(
3109
- `[StormcloudVideoPlayer] Restored mute state: ${currentMutedState} -> ${originalMutedState}`
2998
+ `[StormcloudVideoPlayer] Restored main video - muted: ${originalMutedState}, volume: ${this.video.volume}`
3110
2999
  );
3111
3000
  }
3112
- if (this.video.paused) {
3001
+ if (!this.shouldContinueLiveStreamDuringAds() && this.video.paused) {
3113
3002
  if (this.config.debugAdTiming) {
3114
3003
  console.log("[StormcloudVideoPlayer] Resuming paused video");
3115
3004
  }
3116
3005
  (_a = this.video.play()) == null ? void 0 : _a.catch((error) => {
3117
3006
  if (this.config.debugAdTiming) {
3118
3007
  console.error(
3119
- "[StormcloudVideoPlayer] Failed to resume video after ad failure:",
3008
+ "[StormcloudVideoPlayer] Failed to resume video:",
3120
3009
  error
3121
3010
  );
3122
3011
  }
3123
3012
  });
3124
- } else {
3125
- if (this.config.debugAdTiming) {
3126
- console.log(
3127
- "[StormcloudVideoPlayer] Video is already playing, no resume needed"
3128
- );
3129
- }
3130
3013
  }
3131
3014
  }
3015
+ handleAdFailure() {
3016
+ if (this.config.debugAdTiming) {
3017
+ console.log(
3018
+ "[StormcloudVideoPlayer] Handling ad failure - resuming content",
3019
+ {
3020
+ inAdBreak: this.inAdBreak,
3021
+ showAds: this.showAds,
3022
+ videoPaused: this.video.paused,
3023
+ adPlaying: this.ima.isAdPlaying()
3024
+ }
3025
+ );
3026
+ }
3027
+ this.handleAdPodComplete();
3028
+ }
3132
3029
  startAdFailsafeTimer() {
3133
3030
  var _a;
3134
3031
  this.clearAdFailsafeTimer();