stormcloud-video-player 0.8.7 → 0.8.9

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
@@ -217,6 +217,7 @@ declare class StormcloudVideoPlayer {
217
217
  private preloadPoolActive;
218
218
  private preloadPoolLoopRunning;
219
219
  private adDetectSentForCurrentBreak;
220
+ private adBreakEpoch;
220
221
  private palNonce;
221
222
  private palPlaybackStarted;
222
223
  private readonly streamCorrelator;
@@ -343,6 +344,7 @@ declare class StormcloudVideoPlayer {
343
344
  setMuted(muted: boolean): void;
344
345
  setVolume(volume: number): void;
345
346
  getVolume(): number;
347
+ private getAdAudioVolume;
346
348
  isFullscreen(): boolean;
347
349
  isLive(): boolean;
348
350
  get videoElement(): HTMLVideoElement;
package/lib/index.d.ts CHANGED
@@ -217,6 +217,7 @@ declare class StormcloudVideoPlayer {
217
217
  private preloadPoolActive;
218
218
  private preloadPoolLoopRunning;
219
219
  private adDetectSentForCurrentBreak;
220
+ private adBreakEpoch;
220
221
  private palNonce;
221
222
  private palPlaybackStarted;
222
223
  private readonly streamCorrelator;
@@ -343,6 +344,7 @@ declare class StormcloudVideoPlayer {
343
344
  setMuted(muted: boolean): void;
344
345
  setVolume(volume: number): void;
345
346
  getVolume(): number;
347
+ private getAdAudioVolume;
346
348
  isFullscreen(): boolean;
347
349
  isLive(): boolean;
348
350
  get videoElement(): HTMLVideoElement;
package/lib/index.js CHANGED
@@ -836,7 +836,6 @@ function createHlsAdPlayer(contentVideo, options) {
836
836
  adPlaying = false;
837
837
  setAdPlayingFlag(false);
838
838
  contentVideo.muted = true;
839
- contentVideo.volume = 0;
840
839
  if (adContainerEl) {
841
840
  adContainerEl.style.display = "none";
842
841
  adContainerEl.style.pointerEvents = "none";
@@ -856,7 +855,6 @@ function createHlsAdPlayer(contentVideo, options) {
856
855
  adPlaying = false;
857
856
  setAdPlayingFlag(false);
858
857
  contentVideo.muted = true;
859
- contentVideo.volume = 0;
860
858
  if (adContainerEl) {
861
859
  adContainerEl.style.display = "none";
862
860
  adContainerEl.style.pointerEvents = "none";
@@ -961,7 +959,7 @@ function createHlsAdPlayer(contentVideo, options) {
961
959
  },
962
960
  play: function play() {
963
961
  return _async_to_generator(function() {
964
- var contentVolume, adVolume, mediaFile, isHlsAd;
962
+ var contentVolume, mediaFile, isHlsAd;
965
963
  return _ts_generator(this, function(_state) {
966
964
  if (!currentAd) {
967
965
  console.warn("[HlsAdPlayer] Cannot play: No ad loaded (no ads available)");
@@ -995,13 +993,11 @@ function createHlsAdPlayer(contentVideo, options) {
995
993
  }
996
994
  console.log("[HlsAdPlayer] FORCE MUTING main video");
997
995
  contentVideo.muted = true;
998
- contentVideo.volume = 0;
999
996
  adPlaying = true;
1000
997
  setAdPlayingFlag(true);
1001
998
  if (adVideoElement) {
1002
- adVolume = originalMutedState ? 0 : originalVolume;
1003
- adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
1004
- adVideoElement.muted = false;
999
+ adVideoElement.volume = Math.max(0, Math.min(1, originalVolume));
1000
+ adVideoElement.muted = originalMutedState;
1005
1001
  console.log("[HlsAdPlayer] Set ad video volume to ".concat(adVideoElement.volume, ", muted: ").concat(adVideoElement.muted, ", originalMutedState: ").concat(originalMutedState, ", contentVolume: ").concat(contentVolume));
1006
1002
  }
1007
1003
  if (adContainerEl) {
@@ -1109,8 +1105,8 @@ function createHlsAdPlayer(contentVideo, options) {
1109
1105
  setAdPlayingFlag(false);
1110
1106
  previousMutedState = contentVideo.muted;
1111
1107
  contentVideo.muted = originalMutedState;
1112
- contentVideo.volume = originalMutedState ? 0 : originalVolume;
1113
- console.log("[HlsAdPlayer] Restored mute state on stop: ".concat(previousMutedState, " -> ").concat(originalMutedState));
1108
+ contentVideo.volume = Math.max(0, Math.min(1, originalVolume));
1109
+ console.log("[HlsAdPlayer] Restored mute state on stop: ".concat(previousMutedState, " -> ").concat(originalMutedState, ", volume: ").concat(contentVideo.volume));
1114
1110
  if (adContainerEl) {
1115
1111
  adContainerEl.style.display = "none";
1116
1112
  adContainerEl.style.pointerEvents = "none";
@@ -1165,7 +1161,7 @@ function createHlsAdPlayer(contentVideo, options) {
1165
1161
  adPlaying = false;
1166
1162
  setAdPlayingFlag(false);
1167
1163
  contentVideo.muted = originalMutedState;
1168
- contentVideo.volume = originalMutedState ? 0 : originalVolume;
1164
+ contentVideo.volume = Math.max(0, Math.min(1, originalVolume));
1169
1165
  if (adHls) {
1170
1166
  adHls.destroy();
1171
1167
  adHls = void 0;
@@ -1221,7 +1217,9 @@ function createHlsAdPlayer(contentVideo, options) {
1221
1217
  },
1222
1218
  setAdVolume: function setAdVolume(volume) {
1223
1219
  if (adVideoElement && adPlaying) {
1224
- adVideoElement.volume = Math.max(0, Math.min(1, volume));
1220
+ var clamped = Math.max(0, Math.min(1, volume));
1221
+ adVideoElement.volume = clamped;
1222
+ adVideoElement.muted = clamped === 0;
1225
1223
  }
1226
1224
  },
1227
1225
  getAdVolume: function getAdVolume() {
@@ -2724,6 +2722,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2724
2722
  this.preloadPoolActive = false;
2725
2723
  this.preloadPoolLoopRunning = false;
2726
2724
  this.adDetectSentForCurrentBreak = false;
2725
+ this.adBreakEpoch = 0;
2727
2726
  this.palPlaybackStarted = false;
2728
2727
  this.streamCorrelator = generateCorrelator();
2729
2728
  this.consentSignals = {};
@@ -3266,10 +3265,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3266
3265
  console.log("[StormcloudVideoPlayer] Starting ad break timer on content_pause (first ad starting)");
3267
3266
  }
3268
3267
  }
3269
- var currentMuted = _this.video.muted;
3270
- var currentVolume = _this.video.volume;
3271
- var adVolume = currentMuted ? 0 : currentVolume;
3272
- _this.adPlayer.setAdVolume(adVolume);
3268
+ _this.adPlayer.setAdVolume(_this.getAdAudioVolume());
3273
3269
  if (_this.isShowingPlaceholder) {
3274
3270
  if (_this.config.debugAdTiming) {
3275
3271
  console.log("[StormcloudVideoPlayer] Hiding placeholder - new ads starting");
@@ -3286,7 +3282,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3286
3282
  }).catch(function() {});
3287
3283
  if (!_this.video.muted) {
3288
3284
  _this.video.muted = true;
3289
- _this.video.volume = 0;
3290
3285
  if (_this.config.debugAdTiming) {
3291
3286
  console.log("[StormcloudVideoPlayer] Muted video on content_resume (ad ended, gap between ads)");
3292
3287
  }
@@ -3334,7 +3329,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3334
3329
  try {
3335
3330
  this.adPlayer.destroy();
3336
3331
  this.video.muted = true;
3337
- this.video.volume = 0;
3338
3332
  } catch (error) {
3339
3333
  if (this.config.debugAdTiming) {
3340
3334
  console.warn("[StormcloudVideoPlayer] Error destroying old AdController:", error);
@@ -3393,7 +3387,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3393
3387
  }
3394
3388
  if (!this.video.muted) {
3395
3389
  this.video.muted = true;
3396
- this.video.volume = 0;
3397
3390
  if (this.config.debugAdTiming) {
3398
3391
  console.log("[StormcloudVideoPlayer] Muted video when showing placeholder");
3399
3392
  }
@@ -4015,7 +4008,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4015
4008
  if (marker.type === "end") {
4016
4009
  if (!this.video.muted) {
4017
4010
  this.video.muted = true;
4018
- this.video.volume = 0;
4019
4011
  if (this.config.debugAdTiming) {
4020
4012
  console.log("[StormcloudVideoPlayer] Muted video on SCTE end marker");
4021
4013
  }
@@ -4053,13 +4045,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4053
4045
  {
4054
4046
  key: "startScte35AdBreak",
4055
4047
  value: function startScte35AdBreak(marker, cueKey, durationMs) {
4056
- if (!this.video.muted) {
4057
- this.video.muted = true;
4058
- this.video.volume = 0;
4059
- if (this.config.debugAdTiming) {
4060
- console.log("[StormcloudVideoPlayer] Muted video on SCTE start marker");
4061
- }
4062
- }
4063
4048
  this.inAdBreak = true;
4064
4049
  this.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.pendingScte35CueKey;
4065
4050
  this.scheduledScte35BreakKey = void 0;
@@ -5285,7 +5270,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5285
5270
  key: "preloadAdIntoPool",
5286
5271
  value: function preloadAdIntoPool(vastUrl) {
5287
5272
  return _async_to_generator(function() {
5288
- var _this, loadPromise;
5273
+ var _this, epoch, loadPromise;
5289
5274
  return _ts_generator(this, function(_state) {
5290
5275
  _this = this;
5291
5276
  if (this.isGamInCooldown()) {
@@ -5311,6 +5296,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5311
5296
  if (this.config.debugAdTiming) {
5312
5297
  console.log("[PRELOAD-POOL] \uD83D\uDCE5 Preloading ad into pool: ".concat(vastUrl));
5313
5298
  }
5299
+ epoch = this.adBreakEpoch;
5314
5300
  loadPromise = function() {
5315
5301
  return _async_to_generator(function() {
5316
5302
  var _this, hasAdError, adErrorPayload, errorListenerCleanup, continueLiveStreamDuringAds, preloadAd, errorListener, isNoFill, poolEntry, lateErrorListener, error;
@@ -5388,6 +5374,20 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5388
5374
  2
5389
5375
  ];
5390
5376
  }
5377
+ if (!this.preloadPoolActive || epoch !== this.adBreakEpoch) {
5378
+ if (this.config.debugAdTiming) {
5379
+ console.log("[PRELOAD-POOL] \uD83D\uDEAB Discarding preloaded ad - break ended during fetch");
5380
+ }
5381
+ if (errorListenerCleanup) {
5382
+ errorListenerCleanup();
5383
+ }
5384
+ try {
5385
+ preloadAd.destroy();
5386
+ } catch (unused) {}
5387
+ return [
5388
+ 2
5389
+ ];
5390
+ }
5391
5391
  poolEntry = {
5392
5392
  vastUrl: vastUrl,
5393
5393
  adController: preloadAd,
@@ -5459,7 +5459,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5459
5459
  key: "preloadPoolLoop",
5460
5460
  value: function preloadPoolLoop(baseVastUrl) {
5461
5461
  return _async_to_generator(function() {
5462
- var remaining, newUrls, newUrl;
5462
+ var epoch, remaining, newUrls, newUrl;
5463
5463
  return _ts_generator(this, function(_state) {
5464
5464
  switch(_state.label){
5465
5465
  case 0:
@@ -5469,12 +5469,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5469
5469
  ];
5470
5470
  }
5471
5471
  this.preloadPoolLoopRunning = true;
5472
+ epoch = this.adBreakEpoch;
5472
5473
  if (this.config.debugAdTiming) {
5473
5474
  console.log("[PRELOAD-POOL] \uD83D\uDD04 Starting continuous preload loop");
5474
5475
  }
5475
5476
  _state.label = 1;
5476
5477
  case 1:
5477
- if (!this.preloadPoolActive) return [
5478
+ if (!(this.preloadPoolActive && epoch === this.adBreakEpoch)) return [
5478
5479
  3,
5479
5480
  10
5480
5481
  ];
@@ -5519,7 +5520,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5519
5520
  3,
5520
5521
  8
5521
5522
  ];
5522
- if (!this.preloadPoolActive || this.isGamInCooldown()) {
5523
+ if (!this.preloadPoolActive || epoch !== this.adBreakEpoch || this.isGamInCooldown()) {
5523
5524
  return [
5524
5525
  3,
5525
5526
  8
@@ -5646,7 +5647,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5646
5647
  key: "handleAdStart",
5647
5648
  value: function handleAdStart(_marker) {
5648
5649
  return _async_to_generator(function() {
5649
- var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, firstAdUrl, usePreloadedAd, preloadedController, preloaded, firstAdUrlArray, adVolume, adVolume1, error, fallbackPreloaded, adVolume2, fallbackError;
5650
+ var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, firstAdUrl, usePreloadedAd, preloadedController, preloaded, firstAdUrlArray, preservedMuted, preservedVolume, adVolume, adVolume1, error, fallbackPreloaded, preservedMuted1, preservedVolume1, adVolume2, fallbackError;
5650
5651
  return _ts_generator(this, function(_state) {
5651
5652
  switch(_state.label){
5652
5653
  case 0:
@@ -5686,7 +5687,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5686
5687
  this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
5687
5688
  if (!this.video.muted) {
5688
5689
  this.video.muted = true;
5689
- this.video.volume = 0;
5690
5690
  if (this.config.debugAdTiming) {
5691
5691
  console.log("[StormcloudVideoPlayer] Muted video in handleAdStart");
5692
5692
  }
@@ -5756,10 +5756,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5756
5756
  3,
5757
5757
  3
5758
5758
  ];
5759
+ preservedMuted = this.adPlayer.getOriginalMutedState();
5760
+ preservedVolume = this.adPlayer.getOriginalVolume();
5759
5761
  this.adPlayer.destroy();
5760
5762
  this.video.muted = true;
5761
- this.video.volume = 0;
5762
5763
  this.adPlayer = preloadedController;
5764
+ this.adPlayer.updateOriginalMutedState(preservedMuted, preservedVolume);
5763
5765
  this.attachImaEventListeners();
5764
5766
  if (this.config.debugAdTiming) {
5765
5767
  console.log("[CONTINUOUS-FETCH] \u2705 Using preloaded ad, resuming and starting playback immediately (no request delay!)");
@@ -5857,11 +5859,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5857
5859
  ,
5858
5860
  12
5859
5861
  ]);
5862
+ preservedMuted1 = this.adPlayer.getOriginalMutedState();
5863
+ preservedVolume1 = this.adPlayer.getOriginalVolume();
5860
5864
  this.adPlayer.destroy();
5861
5865
  this.video.muted = true;
5862
- this.video.volume = 0;
5863
5866
  this.adPlayer = fallbackPreloaded.adController;
5864
5867
  this.attachImaEventListeners();
5868
+ this.adPlayer.updateOriginalMutedState(preservedMuted1, preservedVolume1);
5865
5869
  this.adPlayer.resume();
5866
5870
  this.consecutiveFailures = 0;
5867
5871
  this.currentAdIndex++;
@@ -5949,7 +5953,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5949
5953
  key: "continuousFetchLoop",
5950
5954
  value: function continuousFetchLoop(baseVastUrl) {
5951
5955
  return _async_to_generator(function() {
5952
- var _this, _loop, _ret;
5956
+ var _this, _loop, epoch, _ret;
5953
5957
  return _ts_generator(this, function(_state) {
5954
5958
  switch(_state.label){
5955
5959
  case 0:
@@ -6059,9 +6063,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6059
6063
  }
6060
6064
  });
6061
6065
  };
6066
+ epoch = this.adBreakEpoch;
6062
6067
  _state.label = 1;
6063
6068
  case 1:
6064
- if (!(this.continuousFetchingActive && this.inAdBreak)) return [
6069
+ if (!(this.continuousFetchingActive && this.inAdBreak && epoch === this.adBreakEpoch)) return [
6065
6070
  3,
6066
6071
  3
6067
6072
  ];
@@ -6110,10 +6115,16 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6110
6115
  key: "tryNextAvailableAdWithRateLimit",
6111
6116
  value: function tryNextAvailableAdWithRateLimit() {
6112
6117
  return _async_to_generator(function() {
6113
- var backoffMultiplier, backoffDelay, effectiveMinInterval, timeSinceLastRequest, waitTime;
6118
+ var epoch, backoffMultiplier, backoffDelay, effectiveMinInterval, timeSinceLastRequest, waitTime;
6114
6119
  return _ts_generator(this, function(_state) {
6115
6120
  switch(_state.label){
6116
6121
  case 0:
6122
+ if (!this.inAdBreak) {
6123
+ return [
6124
+ 2
6125
+ ];
6126
+ }
6127
+ epoch = this.adBreakEpoch;
6117
6128
  if (this.consecutiveFailures >= this.maxConsecutiveFailures) {
6118
6129
  if (this.config.debugAdTiming) {
6119
6130
  console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Too many consecutive failures (".concat(this.consecutiveFailures, "), ending ad break gracefully"));
@@ -6145,6 +6156,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6145
6156
  _state.sent();
6146
6157
  _state.label = 2;
6147
6158
  case 2:
6159
+ if (!this.inAdBreak || epoch !== this.adBreakEpoch) {
6160
+ return [
6161
+ 2
6162
+ ];
6163
+ }
6148
6164
  return [
6149
6165
  2,
6150
6166
  this.tryNextAvailableAd(0)
@@ -6159,10 +6175,15 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6159
6175
  value: function tryNextAvailableAd() {
6160
6176
  var retryCount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
6161
6177
  return _async_to_generator(function() {
6162
- var remaining, preloaded, currentMuted, currentVolume, adVolume, error, nextAdUrl, currentMuted1, currentVolume1, error1, errorMessage, maxRetries;
6178
+ var remaining, preloaded, preservedMuted, preservedVolume, error, nextAdUrl, error1, errorMessage, maxRetries;
6163
6179
  return _ts_generator(this, function(_state) {
6164
6180
  switch(_state.label){
6165
6181
  case 0:
6182
+ if (!this.inAdBreak) {
6183
+ return [
6184
+ 2
6185
+ ];
6186
+ }
6166
6187
  remaining = this.getRemainingAdMs();
6167
6188
  if (remaining <= 500) {
6168
6189
  if (this.config.debugAdTiming) {
@@ -6213,11 +6234,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6213
6234
  ,
6214
6235
  4
6215
6236
  ]);
6237
+ preservedMuted = this.adPlayer.getOriginalMutedState();
6238
+ preservedVolume = this.adPlayer.getOriginalVolume();
6216
6239
  this.adPlayer.destroy();
6217
6240
  this.video.muted = true;
6218
- this.video.volume = 0;
6219
6241
  this.adPlayer = preloaded.adController;
6220
6242
  this.attachImaEventListeners();
6243
+ this.adPlayer.updateOriginalMutedState(preservedMuted, preservedVolume);
6221
6244
  this.adPlayer.resume();
6222
6245
  this.currentAdIndex++;
6223
6246
  this.totalAdRequestsInBreak++;
@@ -6231,10 +6254,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6231
6254
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6232
6255
  this.scheduleAdStopCountdown(this.getRemainingAdMs());
6233
6256
  }
6234
- currentMuted = this.video.muted;
6235
- currentVolume = this.video.volume;
6236
- adVolume = currentMuted ? 0 : currentVolume;
6237
- this.adPlayer.setAdVolume(adVolume);
6257
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
6238
6258
  this.consecutiveFailures = 0;
6239
6259
  return [
6240
6260
  2
@@ -6281,9 +6301,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6281
6301
  if (this.config.debugAdTiming) {
6282
6302
  console.log("[CONTINUOUS-FETCH] \uD83C\uDFAC Requesting next ad via HLS ad player (".concat(this.currentAdIndex + 1, "/").concat(this.totalAdsInBreak, ", ").concat(this.adRequestQueue.length, " remaining in queue)"));
6283
6303
  }
6284
- currentMuted1 = this.video.muted;
6285
- currentVolume1 = this.video.volume;
6286
- this.adPlayer.updateOriginalMutedState(currentMuted1, currentVolume1);
6287
6304
  this.currentAdIndex++;
6288
6305
  this.totalAdRequestsInBreak++;
6289
6306
  this.lastAdRequestTime = Date.now();
@@ -6376,7 +6393,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6376
6393
  key: "showPlaceholderAndWaitForAds",
6377
6394
  value: function showPlaceholderAndWaitForAds() {
6378
6395
  return _async_to_generator(function() {
6379
- var remaining, waitTime, checkInterval, maxChecks, i, nextAdUrl, currentMuted, currentVolume, error, errorMessage;
6396
+ var remaining, waitTime, checkInterval, maxChecks, i, nextAdUrl, error, errorMessage;
6380
6397
  return _ts_generator(this, function(_state) {
6381
6398
  switch(_state.label){
6382
6399
  case 0:
@@ -6472,9 +6489,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6472
6489
  }
6473
6490
  this.isShowingPlaceholder = false;
6474
6491
  this.adPlayer.hidePlaceholder();
6475
- currentMuted = this.video.muted;
6476
- currentVolume = this.video.volume;
6477
- this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
6478
6492
  this.currentAdIndex++;
6479
6493
  this.totalAdRequestsInBreak++;
6480
6494
  this.lastAdRequestTime = Date.now();
@@ -6924,7 +6938,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6924
6938
  key: "playSingleAd",
6925
6939
  value: function playSingleAd(vastTagUrl) {
6926
6940
  return _async_to_generator(function() {
6927
- var requestToken, currentMuted, currentVolume, adVolume, playError, preloadedFallback, currentMuted1, currentVolume1, adVolume1, fallbackError, error, errorMessage, preloadedFallback1, currentMuted2, currentVolume2, adVolume2, fallbackError1;
6941
+ var requestToken, playError, preloadedFallback, preservedMuted, preservedVolume, fallbackError, error, errorMessage, preloadedFallback1, preservedMuted1, preservedVolume1, fallbackError1;
6928
6942
  return _ts_generator(this, function(_state) {
6929
6943
  switch(_state.label){
6930
6944
  case 0:
@@ -7011,10 +7025,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7011
7025
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7012
7026
  this.scheduleAdStopCountdown(this.getRemainingAdMs());
7013
7027
  }
7014
- currentMuted = this.video.muted;
7015
- currentVolume = this.video.volume;
7016
- adVolume = currentMuted ? 0 : currentVolume;
7017
- this.adPlayer.setAdVolume(adVolume);
7028
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
7018
7029
  this.consecutiveFailures = 0;
7019
7030
  this.temporaryFailureUrls.delete(vastTagUrl);
7020
7031
  return [
@@ -7043,11 +7054,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7043
7054
  10
7044
7055
  ]);
7045
7056
  this.clearAdFailsafeTimer();
7057
+ preservedMuted = this.adPlayer.getOriginalMutedState();
7058
+ preservedVolume = this.adPlayer.getOriginalVolume();
7046
7059
  this.adPlayer.destroy();
7047
7060
  this.video.muted = true;
7048
- this.video.volume = 0;
7049
7061
  this.adPlayer = preloadedFallback.adController;
7050
7062
  this.attachImaEventListeners();
7063
+ this.adPlayer.updateOriginalMutedState(preservedMuted, preservedVolume);
7051
7064
  this.adPlayer.resume();
7052
7065
  this.consecutiveFailures = 0;
7053
7066
  this.currentAdIndex++;
@@ -7061,10 +7074,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7061
7074
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7062
7075
  this.scheduleAdStopCountdown(this.getRemainingAdMs());
7063
7076
  }
7064
- currentMuted1 = this.video.muted;
7065
- currentVolume1 = this.video.volume;
7066
- adVolume1 = currentMuted1 ? 0 : currentVolume1;
7067
- this.adPlayer.setAdVolume(adVolume1);
7077
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
7068
7078
  return [
7069
7079
  2
7070
7080
  ];
@@ -7123,11 +7133,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7123
7133
  ]);
7124
7134
  this.clearAdRequestWatchdog();
7125
7135
  this.clearAdFailsafeTimer();
7136
+ preservedMuted1 = this.adPlayer.getOriginalMutedState();
7137
+ preservedVolume1 = this.adPlayer.getOriginalVolume();
7126
7138
  this.adPlayer.destroy();
7127
7139
  this.video.muted = true;
7128
- this.video.volume = 0;
7129
7140
  this.adPlayer = preloadedFallback1.adController;
7130
7141
  this.attachImaEventListeners();
7142
+ this.adPlayer.updateOriginalMutedState(preservedMuted1, preservedVolume1);
7131
7143
  this.adPlayer.resume();
7132
7144
  this.consecutiveFailures = 0;
7133
7145
  this.currentAdIndex++;
@@ -7138,10 +7150,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7138
7150
  ];
7139
7151
  case 14:
7140
7152
  _state.sent();
7141
- currentMuted2 = this.video.muted;
7142
- currentVolume2 = this.video.volume;
7143
- adVolume2 = currentMuted2 ? 0 : currentVolume2;
7144
- this.adPlayer.setAdVolume(adVolume2);
7153
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
7145
7154
  return [
7146
7155
  2
7147
7156
  ];
@@ -7187,6 +7196,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7187
7196
  if (this.config.debugAdTiming) {
7188
7197
  console.log("[StormcloudVideoPlayer] \uD83C\uDFC1 Ad pod complete - cleaning up");
7189
7198
  }
7199
+ this.adBreakEpoch++;
7190
7200
  this.clearAdRequestWatchdog();
7191
7201
  this.clearAdFailsafeTimer();
7192
7202
  this.activeAdRequestToken = null;
@@ -7443,10 +7453,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7443
7453
  key: "toggleMute",
7444
7454
  value: function toggleMute() {
7445
7455
  if (this.adPlayer.isAdPlaying()) {
7446
- var currentPerceptualState = this.isMuted();
7447
- var newMutedState = !currentPerceptualState;
7456
+ var newMutedState = !this.adPlayer.getOriginalMutedState();
7457
+ var restoreVolume = this.adPlayer.getOriginalVolume() || 1;
7448
7458
  this.adPlayer.updateOriginalMutedState(newMutedState, this.video.volume);
7449
- this.adPlayer.setAdVolume(newMutedState ? 0 : 1);
7459
+ this.adPlayer.setAdVolume(newMutedState ? 0 : restoreVolume);
7450
7460
  if (this.config.debugAdTiming) {
7451
7461
  console.log("[StormcloudVideoPlayer] Mute toggle during ad - immediately applied:", newMutedState);
7452
7462
  }
@@ -7501,10 +7511,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7501
7511
  key: "isMuted",
7502
7512
  value: function isMuted() {
7503
7513
  if (this.adPlayer.isAdPlaying()) {
7504
- if (this.config.debugAdTiming) {
7505
- console.log("[StormcloudVideoPlayer] isMuted() override during ad playback -> false");
7506
- }
7507
- return false;
7514
+ return this.adPlayer.getOriginalMutedState();
7508
7515
  }
7509
7516
  return this.video.muted;
7510
7517
  }
@@ -7571,6 +7578,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7571
7578
  return this.video.volume;
7572
7579
  }
7573
7580
  },
7581
+ {
7582
+ key: "getAdAudioVolume",
7583
+ value: function getAdAudioVolume() {
7584
+ return this.adPlayer.getOriginalMutedState() ? 0 : this.adPlayer.getOriginalVolume();
7585
+ }
7586
+ },
7574
7587
  {
7575
7588
  key: "isFullscreen",
7576
7589
  value: function isFullscreen() {