stormcloud-video-player 0.8.7 → 0.8.8

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
@@ -343,6 +343,7 @@ declare class StormcloudVideoPlayer {
343
343
  setMuted(muted: boolean): void;
344
344
  setVolume(volume: number): void;
345
345
  getVolume(): number;
346
+ private getAdAudioVolume;
346
347
  isFullscreen(): boolean;
347
348
  isLive(): boolean;
348
349
  get videoElement(): HTMLVideoElement;
package/lib/index.d.ts CHANGED
@@ -343,6 +343,7 @@ declare class StormcloudVideoPlayer {
343
343
  setMuted(muted: boolean): void;
344
344
  setVolume(volume: number): void;
345
345
  getVolume(): number;
346
+ private getAdAudioVolume;
346
347
  isFullscreen(): boolean;
347
348
  isLive(): boolean;
348
349
  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() {
@@ -3266,10 +3264,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3266
3264
  console.log("[StormcloudVideoPlayer] Starting ad break timer on content_pause (first ad starting)");
3267
3265
  }
3268
3266
  }
3269
- var currentMuted = _this.video.muted;
3270
- var currentVolume = _this.video.volume;
3271
- var adVolume = currentMuted ? 0 : currentVolume;
3272
- _this.adPlayer.setAdVolume(adVolume);
3267
+ _this.adPlayer.setAdVolume(_this.getAdAudioVolume());
3273
3268
  if (_this.isShowingPlaceholder) {
3274
3269
  if (_this.config.debugAdTiming) {
3275
3270
  console.log("[StormcloudVideoPlayer] Hiding placeholder - new ads starting");
@@ -3286,7 +3281,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3286
3281
  }).catch(function() {});
3287
3282
  if (!_this.video.muted) {
3288
3283
  _this.video.muted = true;
3289
- _this.video.volume = 0;
3290
3284
  if (_this.config.debugAdTiming) {
3291
3285
  console.log("[StormcloudVideoPlayer] Muted video on content_resume (ad ended, gap between ads)");
3292
3286
  }
@@ -3334,7 +3328,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3334
3328
  try {
3335
3329
  this.adPlayer.destroy();
3336
3330
  this.video.muted = true;
3337
- this.video.volume = 0;
3338
3331
  } catch (error) {
3339
3332
  if (this.config.debugAdTiming) {
3340
3333
  console.warn("[StormcloudVideoPlayer] Error destroying old AdController:", error);
@@ -3393,7 +3386,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3393
3386
  }
3394
3387
  if (!this.video.muted) {
3395
3388
  this.video.muted = true;
3396
- this.video.volume = 0;
3397
3389
  if (this.config.debugAdTiming) {
3398
3390
  console.log("[StormcloudVideoPlayer] Muted video when showing placeholder");
3399
3391
  }
@@ -4015,7 +4007,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4015
4007
  if (marker.type === "end") {
4016
4008
  if (!this.video.muted) {
4017
4009
  this.video.muted = true;
4018
- this.video.volume = 0;
4019
4010
  if (this.config.debugAdTiming) {
4020
4011
  console.log("[StormcloudVideoPlayer] Muted video on SCTE end marker");
4021
4012
  }
@@ -4053,13 +4044,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4053
4044
  {
4054
4045
  key: "startScte35AdBreak",
4055
4046
  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
4047
  this.inAdBreak = true;
4064
4048
  this.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.pendingScte35CueKey;
4065
4049
  this.scheduledScte35BreakKey = void 0;
@@ -5646,7 +5630,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5646
5630
  key: "handleAdStart",
5647
5631
  value: function handleAdStart(_marker) {
5648
5632
  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;
5633
+ var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, firstAdUrl, usePreloadedAd, preloadedController, preloaded, firstAdUrlArray, preservedMuted, preservedVolume, adVolume, adVolume1, error, fallbackPreloaded, preservedMuted1, preservedVolume1, adVolume2, fallbackError;
5650
5634
  return _ts_generator(this, function(_state) {
5651
5635
  switch(_state.label){
5652
5636
  case 0:
@@ -5686,7 +5670,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5686
5670
  this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
5687
5671
  if (!this.video.muted) {
5688
5672
  this.video.muted = true;
5689
- this.video.volume = 0;
5690
5673
  if (this.config.debugAdTiming) {
5691
5674
  console.log("[StormcloudVideoPlayer] Muted video in handleAdStart");
5692
5675
  }
@@ -5756,10 +5739,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5756
5739
  3,
5757
5740
  3
5758
5741
  ];
5742
+ preservedMuted = this.adPlayer.getOriginalMutedState();
5743
+ preservedVolume = this.adPlayer.getOriginalVolume();
5759
5744
  this.adPlayer.destroy();
5760
5745
  this.video.muted = true;
5761
- this.video.volume = 0;
5762
5746
  this.adPlayer = preloadedController;
5747
+ this.adPlayer.updateOriginalMutedState(preservedMuted, preservedVolume);
5763
5748
  this.attachImaEventListeners();
5764
5749
  if (this.config.debugAdTiming) {
5765
5750
  console.log("[CONTINUOUS-FETCH] \u2705 Using preloaded ad, resuming and starting playback immediately (no request delay!)");
@@ -5857,11 +5842,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5857
5842
  ,
5858
5843
  12
5859
5844
  ]);
5845
+ preservedMuted1 = this.adPlayer.getOriginalMutedState();
5846
+ preservedVolume1 = this.adPlayer.getOriginalVolume();
5860
5847
  this.adPlayer.destroy();
5861
5848
  this.video.muted = true;
5862
- this.video.volume = 0;
5863
5849
  this.adPlayer = fallbackPreloaded.adController;
5864
5850
  this.attachImaEventListeners();
5851
+ this.adPlayer.updateOriginalMutedState(preservedMuted1, preservedVolume1);
5865
5852
  this.adPlayer.resume();
5866
5853
  this.consecutiveFailures = 0;
5867
5854
  this.currentAdIndex++;
@@ -6159,7 +6146,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6159
6146
  value: function tryNextAvailableAd() {
6160
6147
  var retryCount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
6161
6148
  return _async_to_generator(function() {
6162
- var remaining, preloaded, currentMuted, currentVolume, adVolume, error, nextAdUrl, currentMuted1, currentVolume1, error1, errorMessage, maxRetries;
6149
+ var remaining, preloaded, preservedMuted, preservedVolume, error, nextAdUrl, error1, errorMessage, maxRetries;
6163
6150
  return _ts_generator(this, function(_state) {
6164
6151
  switch(_state.label){
6165
6152
  case 0:
@@ -6213,11 +6200,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6213
6200
  ,
6214
6201
  4
6215
6202
  ]);
6203
+ preservedMuted = this.adPlayer.getOriginalMutedState();
6204
+ preservedVolume = this.adPlayer.getOriginalVolume();
6216
6205
  this.adPlayer.destroy();
6217
6206
  this.video.muted = true;
6218
- this.video.volume = 0;
6219
6207
  this.adPlayer = preloaded.adController;
6220
6208
  this.attachImaEventListeners();
6209
+ this.adPlayer.updateOriginalMutedState(preservedMuted, preservedVolume);
6221
6210
  this.adPlayer.resume();
6222
6211
  this.currentAdIndex++;
6223
6212
  this.totalAdRequestsInBreak++;
@@ -6231,10 +6220,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6231
6220
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6232
6221
  this.scheduleAdStopCountdown(this.getRemainingAdMs());
6233
6222
  }
6234
- currentMuted = this.video.muted;
6235
- currentVolume = this.video.volume;
6236
- adVolume = currentMuted ? 0 : currentVolume;
6237
- this.adPlayer.setAdVolume(adVolume);
6223
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
6238
6224
  this.consecutiveFailures = 0;
6239
6225
  return [
6240
6226
  2
@@ -6281,9 +6267,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6281
6267
  if (this.config.debugAdTiming) {
6282
6268
  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
6269
  }
6284
- currentMuted1 = this.video.muted;
6285
- currentVolume1 = this.video.volume;
6286
- this.adPlayer.updateOriginalMutedState(currentMuted1, currentVolume1);
6287
6270
  this.currentAdIndex++;
6288
6271
  this.totalAdRequestsInBreak++;
6289
6272
  this.lastAdRequestTime = Date.now();
@@ -6376,7 +6359,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6376
6359
  key: "showPlaceholderAndWaitForAds",
6377
6360
  value: function showPlaceholderAndWaitForAds() {
6378
6361
  return _async_to_generator(function() {
6379
- var remaining, waitTime, checkInterval, maxChecks, i, nextAdUrl, currentMuted, currentVolume, error, errorMessage;
6362
+ var remaining, waitTime, checkInterval, maxChecks, i, nextAdUrl, error, errorMessage;
6380
6363
  return _ts_generator(this, function(_state) {
6381
6364
  switch(_state.label){
6382
6365
  case 0:
@@ -6472,9 +6455,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6472
6455
  }
6473
6456
  this.isShowingPlaceholder = false;
6474
6457
  this.adPlayer.hidePlaceholder();
6475
- currentMuted = this.video.muted;
6476
- currentVolume = this.video.volume;
6477
- this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
6478
6458
  this.currentAdIndex++;
6479
6459
  this.totalAdRequestsInBreak++;
6480
6460
  this.lastAdRequestTime = Date.now();
@@ -6924,7 +6904,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6924
6904
  key: "playSingleAd",
6925
6905
  value: function playSingleAd(vastTagUrl) {
6926
6906
  return _async_to_generator(function() {
6927
- var requestToken, currentMuted, currentVolume, adVolume, playError, preloadedFallback, currentMuted1, currentVolume1, adVolume1, fallbackError, error, errorMessage, preloadedFallback1, currentMuted2, currentVolume2, adVolume2, fallbackError1;
6907
+ var requestToken, playError, preloadedFallback, preservedMuted, preservedVolume, fallbackError, error, errorMessage, preloadedFallback1, preservedMuted1, preservedVolume1, fallbackError1;
6928
6908
  return _ts_generator(this, function(_state) {
6929
6909
  switch(_state.label){
6930
6910
  case 0:
@@ -7011,10 +6991,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7011
6991
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7012
6992
  this.scheduleAdStopCountdown(this.getRemainingAdMs());
7013
6993
  }
7014
- currentMuted = this.video.muted;
7015
- currentVolume = this.video.volume;
7016
- adVolume = currentMuted ? 0 : currentVolume;
7017
- this.adPlayer.setAdVolume(adVolume);
6994
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
7018
6995
  this.consecutiveFailures = 0;
7019
6996
  this.temporaryFailureUrls.delete(vastTagUrl);
7020
6997
  return [
@@ -7043,11 +7020,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7043
7020
  10
7044
7021
  ]);
7045
7022
  this.clearAdFailsafeTimer();
7023
+ preservedMuted = this.adPlayer.getOriginalMutedState();
7024
+ preservedVolume = this.adPlayer.getOriginalVolume();
7046
7025
  this.adPlayer.destroy();
7047
7026
  this.video.muted = true;
7048
- this.video.volume = 0;
7049
7027
  this.adPlayer = preloadedFallback.adController;
7050
7028
  this.attachImaEventListeners();
7029
+ this.adPlayer.updateOriginalMutedState(preservedMuted, preservedVolume);
7051
7030
  this.adPlayer.resume();
7052
7031
  this.consecutiveFailures = 0;
7053
7032
  this.currentAdIndex++;
@@ -7061,10 +7040,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7061
7040
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7062
7041
  this.scheduleAdStopCountdown(this.getRemainingAdMs());
7063
7042
  }
7064
- currentMuted1 = this.video.muted;
7065
- currentVolume1 = this.video.volume;
7066
- adVolume1 = currentMuted1 ? 0 : currentVolume1;
7067
- this.adPlayer.setAdVolume(adVolume1);
7043
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
7068
7044
  return [
7069
7045
  2
7070
7046
  ];
@@ -7123,11 +7099,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7123
7099
  ]);
7124
7100
  this.clearAdRequestWatchdog();
7125
7101
  this.clearAdFailsafeTimer();
7102
+ preservedMuted1 = this.adPlayer.getOriginalMutedState();
7103
+ preservedVolume1 = this.adPlayer.getOriginalVolume();
7126
7104
  this.adPlayer.destroy();
7127
7105
  this.video.muted = true;
7128
- this.video.volume = 0;
7129
7106
  this.adPlayer = preloadedFallback1.adController;
7130
7107
  this.attachImaEventListeners();
7108
+ this.adPlayer.updateOriginalMutedState(preservedMuted1, preservedVolume1);
7131
7109
  this.adPlayer.resume();
7132
7110
  this.consecutiveFailures = 0;
7133
7111
  this.currentAdIndex++;
@@ -7138,10 +7116,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7138
7116
  ];
7139
7117
  case 14:
7140
7118
  _state.sent();
7141
- currentMuted2 = this.video.muted;
7142
- currentVolume2 = this.video.volume;
7143
- adVolume2 = currentMuted2 ? 0 : currentVolume2;
7144
- this.adPlayer.setAdVolume(adVolume2);
7119
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
7145
7120
  return [
7146
7121
  2
7147
7122
  ];
@@ -7443,10 +7418,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7443
7418
  key: "toggleMute",
7444
7419
  value: function toggleMute() {
7445
7420
  if (this.adPlayer.isAdPlaying()) {
7446
- var currentPerceptualState = this.isMuted();
7447
- var newMutedState = !currentPerceptualState;
7421
+ var newMutedState = !this.adPlayer.getOriginalMutedState();
7422
+ var restoreVolume = this.adPlayer.getOriginalVolume() || 1;
7448
7423
  this.adPlayer.updateOriginalMutedState(newMutedState, this.video.volume);
7449
- this.adPlayer.setAdVolume(newMutedState ? 0 : 1);
7424
+ this.adPlayer.setAdVolume(newMutedState ? 0 : restoreVolume);
7450
7425
  if (this.config.debugAdTiming) {
7451
7426
  console.log("[StormcloudVideoPlayer] Mute toggle during ad - immediately applied:", newMutedState);
7452
7427
  }
@@ -7501,10 +7476,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7501
7476
  key: "isMuted",
7502
7477
  value: function isMuted() {
7503
7478
  if (this.adPlayer.isAdPlaying()) {
7504
- if (this.config.debugAdTiming) {
7505
- console.log("[StormcloudVideoPlayer] isMuted() override during ad playback -> false");
7506
- }
7507
- return false;
7479
+ return this.adPlayer.getOriginalMutedState();
7508
7480
  }
7509
7481
  return this.video.muted;
7510
7482
  }
@@ -7571,6 +7543,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7571
7543
  return this.video.volume;
7572
7544
  }
7573
7545
  },
7546
+ {
7547
+ key: "getAdAudioVolume",
7548
+ value: function getAdAudioVolume() {
7549
+ return this.adPlayer.getOriginalMutedState() ? 0 : this.adPlayer.getOriginalVolume();
7550
+ }
7551
+ },
7574
7552
  {
7575
7553
  key: "isFullscreen",
7576
7554
  value: function isFullscreen() {