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.cjs CHANGED
@@ -1050,7 +1050,6 @@ function createHlsAdPlayer(contentVideo, options) {
1050
1050
  adPlaying = false;
1051
1051
  setAdPlayingFlag(false);
1052
1052
  contentVideo.muted = true;
1053
- contentVideo.volume = 0;
1054
1053
  if (adContainerEl) {
1055
1054
  adContainerEl.style.display = "none";
1056
1055
  adContainerEl.style.pointerEvents = "none";
@@ -1070,7 +1069,6 @@ function createHlsAdPlayer(contentVideo, options) {
1070
1069
  adPlaying = false;
1071
1070
  setAdPlayingFlag(false);
1072
1071
  contentVideo.muted = true;
1073
- contentVideo.volume = 0;
1074
1072
  if (adContainerEl) {
1075
1073
  adContainerEl.style.display = "none";
1076
1074
  adContainerEl.style.pointerEvents = "none";
@@ -1175,7 +1173,7 @@ function createHlsAdPlayer(contentVideo, options) {
1175
1173
  },
1176
1174
  play: function play() {
1177
1175
  return _async_to_generator(function() {
1178
- var contentVolume, adVolume, mediaFile, isHlsAd;
1176
+ var contentVolume, mediaFile, isHlsAd;
1179
1177
  return _ts_generator(this, function(_state) {
1180
1178
  if (!currentAd) {
1181
1179
  console.warn("[HlsAdPlayer] Cannot play: No ad loaded (no ads available)");
@@ -1209,13 +1207,11 @@ function createHlsAdPlayer(contentVideo, options) {
1209
1207
  }
1210
1208
  console.log("[HlsAdPlayer] FORCE MUTING main video");
1211
1209
  contentVideo.muted = true;
1212
- contentVideo.volume = 0;
1213
1210
  adPlaying = true;
1214
1211
  setAdPlayingFlag(true);
1215
1212
  if (adVideoElement) {
1216
- adVolume = originalMutedState ? 0 : originalVolume;
1217
- adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
1218
- adVideoElement.muted = false;
1213
+ adVideoElement.volume = Math.max(0, Math.min(1, originalVolume));
1214
+ adVideoElement.muted = originalMutedState;
1219
1215
  console.log("[HlsAdPlayer] Set ad video volume to ".concat(adVideoElement.volume, ", muted: ").concat(adVideoElement.muted, ", originalMutedState: ").concat(originalMutedState, ", contentVolume: ").concat(contentVolume));
1220
1216
  }
1221
1217
  if (adContainerEl) {
@@ -1323,8 +1319,8 @@ function createHlsAdPlayer(contentVideo, options) {
1323
1319
  setAdPlayingFlag(false);
1324
1320
  previousMutedState = contentVideo.muted;
1325
1321
  contentVideo.muted = originalMutedState;
1326
- contentVideo.volume = originalMutedState ? 0 : originalVolume;
1327
- console.log("[HlsAdPlayer] Restored mute state on stop: ".concat(previousMutedState, " -> ").concat(originalMutedState));
1322
+ contentVideo.volume = Math.max(0, Math.min(1, originalVolume));
1323
+ console.log("[HlsAdPlayer] Restored mute state on stop: ".concat(previousMutedState, " -> ").concat(originalMutedState, ", volume: ").concat(contentVideo.volume));
1328
1324
  if (adContainerEl) {
1329
1325
  adContainerEl.style.display = "none";
1330
1326
  adContainerEl.style.pointerEvents = "none";
@@ -1379,7 +1375,7 @@ function createHlsAdPlayer(contentVideo, options) {
1379
1375
  adPlaying = false;
1380
1376
  setAdPlayingFlag(false);
1381
1377
  contentVideo.muted = originalMutedState;
1382
- contentVideo.volume = originalMutedState ? 0 : originalVolume;
1378
+ contentVideo.volume = Math.max(0, Math.min(1, originalVolume));
1383
1379
  if (adHls) {
1384
1380
  adHls.destroy();
1385
1381
  adHls = void 0;
@@ -1435,7 +1431,9 @@ function createHlsAdPlayer(contentVideo, options) {
1435
1431
  },
1436
1432
  setAdVolume: function setAdVolume(volume) {
1437
1433
  if (adVideoElement && adPlaying) {
1438
- adVideoElement.volume = Math.max(0, Math.min(1, volume));
1434
+ var clamped = Math.max(0, Math.min(1, volume));
1435
+ adVideoElement.volume = clamped;
1436
+ adVideoElement.muted = clamped === 0;
1439
1437
  }
1440
1438
  },
1441
1439
  getAdVolume: function getAdVolume() {
@@ -3477,10 +3475,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3477
3475
  console.log("[StormcloudVideoPlayer] Starting ad break timer on content_pause (first ad starting)");
3478
3476
  }
3479
3477
  }
3480
- var currentMuted = _this.video.muted;
3481
- var currentVolume = _this.video.volume;
3482
- var adVolume = currentMuted ? 0 : currentVolume;
3483
- _this.adPlayer.setAdVolume(adVolume);
3478
+ _this.adPlayer.setAdVolume(_this.getAdAudioVolume());
3484
3479
  if (_this.isShowingPlaceholder) {
3485
3480
  if (_this.config.debugAdTiming) {
3486
3481
  console.log("[StormcloudVideoPlayer] Hiding placeholder - new ads starting");
@@ -3497,7 +3492,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3497
3492
  }).catch(function() {});
3498
3493
  if (!_this.video.muted) {
3499
3494
  _this.video.muted = true;
3500
- _this.video.volume = 0;
3501
3495
  if (_this.config.debugAdTiming) {
3502
3496
  console.log("[StormcloudVideoPlayer] Muted video on content_resume (ad ended, gap between ads)");
3503
3497
  }
@@ -3545,7 +3539,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3545
3539
  try {
3546
3540
  this.adPlayer.destroy();
3547
3541
  this.video.muted = true;
3548
- this.video.volume = 0;
3549
3542
  } catch (error) {
3550
3543
  if (this.config.debugAdTiming) {
3551
3544
  console.warn("[StormcloudVideoPlayer] Error destroying old AdController:", error);
@@ -3604,7 +3597,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3604
3597
  }
3605
3598
  if (!this.video.muted) {
3606
3599
  this.video.muted = true;
3607
- this.video.volume = 0;
3608
3600
  if (this.config.debugAdTiming) {
3609
3601
  console.log("[StormcloudVideoPlayer] Muted video when showing placeholder");
3610
3602
  }
@@ -4226,7 +4218,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4226
4218
  if (marker.type === "end") {
4227
4219
  if (!this.video.muted) {
4228
4220
  this.video.muted = true;
4229
- this.video.volume = 0;
4230
4221
  if (this.config.debugAdTiming) {
4231
4222
  console.log("[StormcloudVideoPlayer] Muted video on SCTE end marker");
4232
4223
  }
@@ -4264,13 +4255,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4264
4255
  {
4265
4256
  key: "startScte35AdBreak",
4266
4257
  value: function startScte35AdBreak(marker, cueKey, durationMs) {
4267
- if (!this.video.muted) {
4268
- this.video.muted = true;
4269
- this.video.volume = 0;
4270
- if (this.config.debugAdTiming) {
4271
- console.log("[StormcloudVideoPlayer] Muted video on SCTE start marker");
4272
- }
4273
- }
4274
4258
  this.inAdBreak = true;
4275
4259
  this.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.pendingScte35CueKey;
4276
4260
  this.scheduledScte35BreakKey = void 0;
@@ -5857,7 +5841,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5857
5841
  key: "handleAdStart",
5858
5842
  value: function handleAdStart(_marker) {
5859
5843
  return _async_to_generator(function() {
5860
- var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, firstAdUrl, usePreloadedAd, preloadedController, preloaded, firstAdUrlArray, adVolume, adVolume1, error, fallbackPreloaded, adVolume2, fallbackError;
5844
+ var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, firstAdUrl, usePreloadedAd, preloadedController, preloaded, firstAdUrlArray, preservedMuted, preservedVolume, adVolume, adVolume1, error, fallbackPreloaded, preservedMuted1, preservedVolume1, adVolume2, fallbackError;
5861
5845
  return _ts_generator(this, function(_state) {
5862
5846
  switch(_state.label){
5863
5847
  case 0:
@@ -5897,7 +5881,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5897
5881
  this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
5898
5882
  if (!this.video.muted) {
5899
5883
  this.video.muted = true;
5900
- this.video.volume = 0;
5901
5884
  if (this.config.debugAdTiming) {
5902
5885
  console.log("[StormcloudVideoPlayer] Muted video in handleAdStart");
5903
5886
  }
@@ -5967,10 +5950,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5967
5950
  3,
5968
5951
  3
5969
5952
  ];
5953
+ preservedMuted = this.adPlayer.getOriginalMutedState();
5954
+ preservedVolume = this.adPlayer.getOriginalVolume();
5970
5955
  this.adPlayer.destroy();
5971
5956
  this.video.muted = true;
5972
- this.video.volume = 0;
5973
5957
  this.adPlayer = preloadedController;
5958
+ this.adPlayer.updateOriginalMutedState(preservedMuted, preservedVolume);
5974
5959
  this.attachImaEventListeners();
5975
5960
  if (this.config.debugAdTiming) {
5976
5961
  console.log("[CONTINUOUS-FETCH] \u2705 Using preloaded ad, resuming and starting playback immediately (no request delay!)");
@@ -6068,11 +6053,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6068
6053
  ,
6069
6054
  12
6070
6055
  ]);
6056
+ preservedMuted1 = this.adPlayer.getOriginalMutedState();
6057
+ preservedVolume1 = this.adPlayer.getOriginalVolume();
6071
6058
  this.adPlayer.destroy();
6072
6059
  this.video.muted = true;
6073
- this.video.volume = 0;
6074
6060
  this.adPlayer = fallbackPreloaded.adController;
6075
6061
  this.attachImaEventListeners();
6062
+ this.adPlayer.updateOriginalMutedState(preservedMuted1, preservedVolume1);
6076
6063
  this.adPlayer.resume();
6077
6064
  this.consecutiveFailures = 0;
6078
6065
  this.currentAdIndex++;
@@ -6370,7 +6357,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6370
6357
  value: function tryNextAvailableAd() {
6371
6358
  var retryCount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
6372
6359
  return _async_to_generator(function() {
6373
- var remaining, preloaded, currentMuted, currentVolume, adVolume, error, nextAdUrl, currentMuted1, currentVolume1, error1, errorMessage, maxRetries;
6360
+ var remaining, preloaded, preservedMuted, preservedVolume, error, nextAdUrl, error1, errorMessage, maxRetries;
6374
6361
  return _ts_generator(this, function(_state) {
6375
6362
  switch(_state.label){
6376
6363
  case 0:
@@ -6424,11 +6411,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6424
6411
  ,
6425
6412
  4
6426
6413
  ]);
6414
+ preservedMuted = this.adPlayer.getOriginalMutedState();
6415
+ preservedVolume = this.adPlayer.getOriginalVolume();
6427
6416
  this.adPlayer.destroy();
6428
6417
  this.video.muted = true;
6429
- this.video.volume = 0;
6430
6418
  this.adPlayer = preloaded.adController;
6431
6419
  this.attachImaEventListeners();
6420
+ this.adPlayer.updateOriginalMutedState(preservedMuted, preservedVolume);
6432
6421
  this.adPlayer.resume();
6433
6422
  this.currentAdIndex++;
6434
6423
  this.totalAdRequestsInBreak++;
@@ -6442,10 +6431,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6442
6431
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6443
6432
  this.scheduleAdStopCountdown(this.getRemainingAdMs());
6444
6433
  }
6445
- currentMuted = this.video.muted;
6446
- currentVolume = this.video.volume;
6447
- adVolume = currentMuted ? 0 : currentVolume;
6448
- this.adPlayer.setAdVolume(adVolume);
6434
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
6449
6435
  this.consecutiveFailures = 0;
6450
6436
  return [
6451
6437
  2
@@ -6492,9 +6478,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6492
6478
  if (this.config.debugAdTiming) {
6493
6479
  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)"));
6494
6480
  }
6495
- currentMuted1 = this.video.muted;
6496
- currentVolume1 = this.video.volume;
6497
- this.adPlayer.updateOriginalMutedState(currentMuted1, currentVolume1);
6498
6481
  this.currentAdIndex++;
6499
6482
  this.totalAdRequestsInBreak++;
6500
6483
  this.lastAdRequestTime = Date.now();
@@ -6587,7 +6570,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6587
6570
  key: "showPlaceholderAndWaitForAds",
6588
6571
  value: function showPlaceholderAndWaitForAds() {
6589
6572
  return _async_to_generator(function() {
6590
- var remaining, waitTime, checkInterval, maxChecks, i, nextAdUrl, currentMuted, currentVolume, error, errorMessage;
6573
+ var remaining, waitTime, checkInterval, maxChecks, i, nextAdUrl, error, errorMessage;
6591
6574
  return _ts_generator(this, function(_state) {
6592
6575
  switch(_state.label){
6593
6576
  case 0:
@@ -6683,9 +6666,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6683
6666
  }
6684
6667
  this.isShowingPlaceholder = false;
6685
6668
  this.adPlayer.hidePlaceholder();
6686
- currentMuted = this.video.muted;
6687
- currentVolume = this.video.volume;
6688
- this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
6689
6669
  this.currentAdIndex++;
6690
6670
  this.totalAdRequestsInBreak++;
6691
6671
  this.lastAdRequestTime = Date.now();
@@ -7135,7 +7115,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7135
7115
  key: "playSingleAd",
7136
7116
  value: function playSingleAd(vastTagUrl) {
7137
7117
  return _async_to_generator(function() {
7138
- var requestToken, currentMuted, currentVolume, adVolume, playError, preloadedFallback, currentMuted1, currentVolume1, adVolume1, fallbackError, error, errorMessage, preloadedFallback1, currentMuted2, currentVolume2, adVolume2, fallbackError1;
7118
+ var requestToken, playError, preloadedFallback, preservedMuted, preservedVolume, fallbackError, error, errorMessage, preloadedFallback1, preservedMuted1, preservedVolume1, fallbackError1;
7139
7119
  return _ts_generator(this, function(_state) {
7140
7120
  switch(_state.label){
7141
7121
  case 0:
@@ -7222,10 +7202,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7222
7202
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7223
7203
  this.scheduleAdStopCountdown(this.getRemainingAdMs());
7224
7204
  }
7225
- currentMuted = this.video.muted;
7226
- currentVolume = this.video.volume;
7227
- adVolume = currentMuted ? 0 : currentVolume;
7228
- this.adPlayer.setAdVolume(adVolume);
7205
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
7229
7206
  this.consecutiveFailures = 0;
7230
7207
  this.temporaryFailureUrls.delete(vastTagUrl);
7231
7208
  return [
@@ -7254,11 +7231,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7254
7231
  10
7255
7232
  ]);
7256
7233
  this.clearAdFailsafeTimer();
7234
+ preservedMuted = this.adPlayer.getOriginalMutedState();
7235
+ preservedVolume = this.adPlayer.getOriginalVolume();
7257
7236
  this.adPlayer.destroy();
7258
7237
  this.video.muted = true;
7259
- this.video.volume = 0;
7260
7238
  this.adPlayer = preloadedFallback.adController;
7261
7239
  this.attachImaEventListeners();
7240
+ this.adPlayer.updateOriginalMutedState(preservedMuted, preservedVolume);
7262
7241
  this.adPlayer.resume();
7263
7242
  this.consecutiveFailures = 0;
7264
7243
  this.currentAdIndex++;
@@ -7272,10 +7251,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7272
7251
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7273
7252
  this.scheduleAdStopCountdown(this.getRemainingAdMs());
7274
7253
  }
7275
- currentMuted1 = this.video.muted;
7276
- currentVolume1 = this.video.volume;
7277
- adVolume1 = currentMuted1 ? 0 : currentVolume1;
7278
- this.adPlayer.setAdVolume(adVolume1);
7254
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
7279
7255
  return [
7280
7256
  2
7281
7257
  ];
@@ -7334,11 +7310,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7334
7310
  ]);
7335
7311
  this.clearAdRequestWatchdog();
7336
7312
  this.clearAdFailsafeTimer();
7313
+ preservedMuted1 = this.adPlayer.getOriginalMutedState();
7314
+ preservedVolume1 = this.adPlayer.getOriginalVolume();
7337
7315
  this.adPlayer.destroy();
7338
7316
  this.video.muted = true;
7339
- this.video.volume = 0;
7340
7317
  this.adPlayer = preloadedFallback1.adController;
7341
7318
  this.attachImaEventListeners();
7319
+ this.adPlayer.updateOriginalMutedState(preservedMuted1, preservedVolume1);
7342
7320
  this.adPlayer.resume();
7343
7321
  this.consecutiveFailures = 0;
7344
7322
  this.currentAdIndex++;
@@ -7349,10 +7327,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7349
7327
  ];
7350
7328
  case 14:
7351
7329
  _state.sent();
7352
- currentMuted2 = this.video.muted;
7353
- currentVolume2 = this.video.volume;
7354
- adVolume2 = currentMuted2 ? 0 : currentVolume2;
7355
- this.adPlayer.setAdVolume(adVolume2);
7330
+ this.adPlayer.setAdVolume(this.getAdAudioVolume());
7356
7331
  return [
7357
7332
  2
7358
7333
  ];
@@ -7654,10 +7629,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7654
7629
  key: "toggleMute",
7655
7630
  value: function toggleMute() {
7656
7631
  if (this.adPlayer.isAdPlaying()) {
7657
- var currentPerceptualState = this.isMuted();
7658
- var newMutedState = !currentPerceptualState;
7632
+ var newMutedState = !this.adPlayer.getOriginalMutedState();
7633
+ var restoreVolume = this.adPlayer.getOriginalVolume() || 1;
7659
7634
  this.adPlayer.updateOriginalMutedState(newMutedState, this.video.volume);
7660
- this.adPlayer.setAdVolume(newMutedState ? 0 : 1);
7635
+ this.adPlayer.setAdVolume(newMutedState ? 0 : restoreVolume);
7661
7636
  if (this.config.debugAdTiming) {
7662
7637
  console.log("[StormcloudVideoPlayer] Mute toggle during ad - immediately applied:", newMutedState);
7663
7638
  }
@@ -7712,10 +7687,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7712
7687
  key: "isMuted",
7713
7688
  value: function isMuted() {
7714
7689
  if (this.adPlayer.isAdPlaying()) {
7715
- if (this.config.debugAdTiming) {
7716
- console.log("[StormcloudVideoPlayer] isMuted() override during ad playback -> false");
7717
- }
7718
- return false;
7690
+ return this.adPlayer.getOriginalMutedState();
7719
7691
  }
7720
7692
  return this.video.muted;
7721
7693
  }
@@ -7782,6 +7754,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7782
7754
  return this.video.volume;
7783
7755
  }
7784
7756
  },
7757
+ {
7758
+ key: "getAdAudioVolume",
7759
+ value: function getAdAudioVolume() {
7760
+ return this.adPlayer.getOriginalMutedState() ? 0 : this.adPlayer.getOriginalVolume();
7761
+ }
7762
+ },
7785
7763
  {
7786
7764
  key: "isFullscreen",
7787
7765
  value: function isFullscreen() {