stormcloud-video-player 0.2.25 → 0.2.26

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
@@ -266,6 +266,7 @@ function supportsFeature(feature) {
266
266
  function createImaController(video, options) {
267
267
  let adPlaying = false;
268
268
  let originalMutedState = false;
269
+ let originalVolume = typeof video.volume === "number" && !Number.isNaN(video.volume) ? Math.max(0, Math.min(1, video.volume)) : 1;
269
270
  const listeners = /* @__PURE__ */ new Map();
270
271
  const preloadedVast = /* @__PURE__ */ new Map();
271
272
  const preloadingVast = /* @__PURE__ */ new Map();
@@ -374,6 +375,22 @@ function createImaController(video, options) {
374
375
  adsRequest.linearAdSlotHeight = videoHeight;
375
376
  adsRequest.nonLinearAdSlotWidth = videoWidth;
376
377
  adsRequest.nonLinearAdSlotHeight = videoHeight;
378
+ if (typeof adsRequest.setAdWillAutoPlay === "function") {
379
+ try {
380
+ const willAutoPlay = !video.paused || video.autoplay;
381
+ adsRequest.setAdWillAutoPlay(willAutoPlay);
382
+ } catch (error) {
383
+ console.warn("[IMA] Failed to call setAdWillAutoPlay:", error);
384
+ }
385
+ }
386
+ if (typeof adsRequest.setAdWillPlayMuted === "function") {
387
+ try {
388
+ const willPlayMuted = video.muted || video.volume === 0;
389
+ adsRequest.setAdWillPlayMuted(willPlayMuted);
390
+ } catch (error) {
391
+ console.warn("[IMA] Failed to call setAdWillPlayMuted:", error);
392
+ }
393
+ }
377
394
  adsRequest.vastLoadTimeout = 5e3;
378
395
  console.log(`[IMA] Ads request dimensions: ${videoWidth}x${videoHeight}`);
379
396
  adsLoader.requestAds(adsRequest);
@@ -779,7 +796,7 @@ function createImaController(video, options) {
779
796
  console.log(`[IMA] Initializing ads manager (${width}x${height})`);
780
797
  adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
781
798
  adPlaying = true;
782
- const adVolume = originalMutedState ? 0 : video.volume;
799
+ const adVolume = originalMutedState ? 0 : originalVolume;
783
800
  try {
784
801
  adsManager.setVolume(adVolume);
785
802
  console.log(`[IMA] Set ad volume to ${adVolume}`);
@@ -821,6 +838,7 @@ function createImaController(video, options) {
821
838
  destroyAdsManager();
822
839
  adPlaying = false;
823
840
  video.muted = originalMutedState;
841
+ video.volume = originalVolume;
824
842
  setAdPlayingFlag(false);
825
843
  if (adContainerEl) {
826
844
  adContainerEl.style.pointerEvents = "none";
@@ -865,15 +883,20 @@ function createImaController(video, options) {
865
883
  var _a;
866
884
  (_a = listeners.get(event)) == null ? void 0 : _a.delete(listener);
867
885
  },
868
- updateOriginalMutedState(muted) {
886
+ updateOriginalMutedState(muted, volume) {
887
+ const nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
869
888
  console.log(
870
- `[IMA] updateOriginalMutedState called: ${originalMutedState} -> ${muted}`
889
+ `[IMA] updateOriginalMutedState called: { muted: ${originalMutedState} -> ${muted}, volume: ${originalVolume} -> ${nextVolume} }`
871
890
  );
872
891
  originalMutedState = muted;
892
+ originalVolume = nextVolume;
873
893
  },
874
894
  getOriginalMutedState() {
875
895
  return originalMutedState;
876
896
  },
897
+ getOriginalVolume() {
898
+ return originalVolume;
899
+ },
877
900
  setAdVolume(volume) {
878
901
  if (adsManager && adPlaying) {
879
902
  try {
@@ -915,6 +938,7 @@ var import_hls = __toESM(require("hls.js"), 1);
915
938
  function createHlsAdPlayer(contentVideo, options) {
916
939
  let adPlaying = false;
917
940
  let originalMutedState = false;
941
+ let originalVolume = Math.max(0, Math.min(1, contentVideo.volume || 1));
918
942
  const listeners = /* @__PURE__ */ new Map();
919
943
  const licenseKey = options == null ? void 0 : options.licenseKey;
920
944
  const mainHlsInstance = options == null ? void 0 : options.mainHlsInstance;
@@ -1272,6 +1296,7 @@ function createHlsAdPlayer(contentVideo, options) {
1272
1296
  setAdPlayingFlag(false);
1273
1297
  const previousMutedState = contentVideo.muted;
1274
1298
  contentVideo.muted = originalMutedState;
1299
+ contentVideo.volume = originalMutedState ? 0 : originalVolume;
1275
1300
  console.log(
1276
1301
  `[HlsAdPlayer] Restored mute state: ${previousMutedState} -> ${originalMutedState}`
1277
1302
  );
@@ -1401,6 +1426,10 @@ function createHlsAdPlayer(contentVideo, options) {
1401
1426
  complete: false
1402
1427
  };
1403
1428
  const contentVolume = contentVideo.volume;
1429
+ originalVolume = Math.max(
1430
+ 0,
1431
+ Math.min(1, contentVolume || originalVolume)
1432
+ );
1404
1433
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1405
1434
  contentVideo.pause();
1406
1435
  console.log("[HlsAdPlayer] Content paused (VOD mode)");
@@ -1413,7 +1442,7 @@ function createHlsAdPlayer(contentVideo, options) {
1413
1442
  adPlaying = true;
1414
1443
  setAdPlayingFlag(true);
1415
1444
  if (adVideoElement) {
1416
- const adVolume = originalMutedState ? 0 : contentVolume;
1445
+ const adVolume = originalMutedState ? 0 : originalVolume;
1417
1446
  adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
1418
1447
  adVideoElement.muted = false;
1419
1448
  console.log(
@@ -1492,6 +1521,7 @@ function createHlsAdPlayer(contentVideo, options) {
1492
1521
  adPlaying = false;
1493
1522
  setAdPlayingFlag(false);
1494
1523
  contentVideo.muted = originalMutedState;
1524
+ contentVideo.volume = originalMutedState ? 0 : originalVolume;
1495
1525
  if (adHls) {
1496
1526
  adHls.destroy();
1497
1527
  adHls = void 0;
@@ -1533,15 +1563,20 @@ function createHlsAdPlayer(contentVideo, options) {
1533
1563
  var _a;
1534
1564
  (_a = listeners.get(event)) == null ? void 0 : _a.delete(listener);
1535
1565
  },
1536
- updateOriginalMutedState(muted) {
1566
+ updateOriginalMutedState(muted, volume) {
1567
+ const nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
1537
1568
  console.log(
1538
- `[HlsAdPlayer] updateOriginalMutedState called: ${originalMutedState} -> ${muted}`
1569
+ `[HlsAdPlayer] updateOriginalMutedState called: { muted: ${originalMutedState} -> ${muted}, volume: ${originalVolume} -> ${nextVolume} }`
1539
1570
  );
1540
1571
  originalMutedState = muted;
1572
+ originalVolume = nextVolume;
1541
1573
  },
1542
1574
  getOriginalMutedState() {
1543
1575
  return originalMutedState;
1544
1576
  },
1577
+ getOriginalVolume() {
1578
+ return originalVolume;
1579
+ },
1545
1580
  setAdVolume(volume) {
1546
1581
  if (adVideoElement && adPlaying) {
1547
1582
  adVideoElement.volume = Math.max(0, Math.min(1, volume));
@@ -2322,7 +2357,7 @@ var StormcloudVideoPlayer = class {
2322
2357
  this.video.autoplay = !!this.config.autoplay;
2323
2358
  this.video.muted = !!this.config.muted;
2324
2359
  this.ima.initialize();
2325
- this.ima.updateOriginalMutedState(this.video.muted);
2360
+ this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
2326
2361
  this.ima.on("all_ads_completed", () => {
2327
2362
  if (this.config.debugAdTiming) {
2328
2363
  console.log(
@@ -3211,7 +3246,7 @@ var StormcloudVideoPlayer = class {
3211
3246
  }
3212
3247
  );
3213
3248
  }
3214
- this.ima.updateOriginalMutedState(this.video.muted);
3249
+ this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3215
3250
  } else if (this.config.debugAdTiming) {
3216
3251
  console.log(
3217
3252
  `[StormcloudVideoPlayer] Keeping existing original mute state (currently showing ads)`
@@ -3273,8 +3308,9 @@ var StormcloudVideoPlayer = class {
3273
3308
  this.ima.stop().catch(() => {
3274
3309
  });
3275
3310
  const originalMutedState = this.ima.getOriginalMutedState();
3311
+ const originalVolume = typeof this.ima.getOriginalVolume === "function" ? this.ima.getOriginalVolume() : this.video.volume;
3276
3312
  this.video.muted = originalMutedState;
3277
- this.video.volume = originalMutedState ? 0 : 1;
3313
+ this.video.volume = originalVolume;
3278
3314
  if (this.config.debugAdTiming) {
3279
3315
  console.log(
3280
3316
  `[StormcloudVideoPlayer] Restored main video - muted: ${originalMutedState}, volume: ${this.video.volume}`
@@ -3425,7 +3461,7 @@ var StormcloudVideoPlayer = class {
3425
3461
  if (this.ima.isAdPlaying()) {
3426
3462
  const currentPerceptualState = this.isMuted();
3427
3463
  const newMutedState = !currentPerceptualState;
3428
- this.ima.updateOriginalMutedState(newMutedState);
3464
+ this.ima.updateOriginalMutedState(newMutedState, this.video.volume);
3429
3465
  this.ima.setAdVolume(newMutedState ? 0 : 1);
3430
3466
  if (this.config.debugAdTiming) {
3431
3467
  console.log(
@@ -3435,7 +3471,7 @@ var StormcloudVideoPlayer = class {
3435
3471
  }
3436
3472
  } else {
3437
3473
  this.video.muted = !this.video.muted;
3438
- this.ima.updateOriginalMutedState(this.video.muted);
3474
+ this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3439
3475
  if (this.config.debugAdTiming) {
3440
3476
  console.log("[StormcloudVideoPlayer] Muted:", this.video.muted);
3441
3477
  }
@@ -3507,7 +3543,7 @@ var StormcloudVideoPlayer = class {
3507
3543
  }
3508
3544
  this.video.muted = muted;
3509
3545
  if (adPlaying) {
3510
- this.ima.updateOriginalMutedState(muted);
3546
+ this.ima.updateOriginalMutedState(muted, this.video.volume);
3511
3547
  this.ima.setAdVolume(muted ? 0 : 1);
3512
3548
  if (this.config.debugAdTiming) {
3513
3549
  console.log("[StormcloudVideoPlayer] setMuted applied during ad", {
@@ -3516,7 +3552,7 @@ var StormcloudVideoPlayer = class {
3516
3552
  }
3517
3553
  return;
3518
3554
  }
3519
- this.ima.updateOriginalMutedState(muted);
3555
+ this.ima.updateOriginalMutedState(muted, this.video.volume);
3520
3556
  if (this.config.debugAdTiming) {
3521
3557
  console.log("[StormcloudVideoPlayer] setMuted called:", muted);
3522
3558
  }