stormcloud-video-player 0.2.25 → 0.2.27

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.
@@ -1,4 +1,4 @@
1
- import { S as StormcloudVideoPlayerConfig } from '../types-9_2sbHCg.cjs';
1
+ import { S as StormcloudVideoPlayerConfig } from '../types-t9jEJXZy.cjs';
2
2
 
3
3
  declare class StormcloudVideoPlayer {
4
4
  private readonly video;
@@ -80,6 +80,7 @@ declare class StormcloudVideoPlayer {
80
80
  toggleFullscreen(): Promise<void>;
81
81
  isMuted(): boolean;
82
82
  setMuted(muted: boolean): void;
83
+ setVolume(volume: number): void;
83
84
  isFullscreen(): boolean;
84
85
  isLive(): boolean;
85
86
  get videoElement(): HTMLVideoElement;
@@ -202,6 +202,7 @@ function getBrowserConfigOverrides() {
202
202
  function createImaController(video, options) {
203
203
  let adPlaying = false;
204
204
  let originalMutedState = false;
205
+ let originalVolume = typeof video.volume === "number" && !Number.isNaN(video.volume) ? Math.max(0, Math.min(1, video.volume)) : 1;
205
206
  const listeners = /* @__PURE__ */ new Map();
206
207
  const preloadedVast = /* @__PURE__ */ new Map();
207
208
  const preloadingVast = /* @__PURE__ */ new Map();
@@ -310,6 +311,22 @@ function createImaController(video, options) {
310
311
  adsRequest.linearAdSlotHeight = videoHeight;
311
312
  adsRequest.nonLinearAdSlotWidth = videoWidth;
312
313
  adsRequest.nonLinearAdSlotHeight = videoHeight;
314
+ if (typeof adsRequest.setAdWillAutoPlay === "function") {
315
+ try {
316
+ const willAutoPlay = !video.paused || video.autoplay;
317
+ adsRequest.setAdWillAutoPlay(willAutoPlay);
318
+ } catch (error) {
319
+ console.warn("[IMA] Failed to call setAdWillAutoPlay:", error);
320
+ }
321
+ }
322
+ if (typeof adsRequest.setAdWillPlayMuted === "function") {
323
+ try {
324
+ const willPlayMuted = video.muted || video.volume === 0;
325
+ adsRequest.setAdWillPlayMuted(willPlayMuted);
326
+ } catch (error) {
327
+ console.warn("[IMA] Failed to call setAdWillPlayMuted:", error);
328
+ }
329
+ }
313
330
  adsRequest.vastLoadTimeout = 5e3;
314
331
  console.log(`[IMA] Ads request dimensions: ${videoWidth}x${videoHeight}`);
315
332
  adsLoader.requestAds(adsRequest);
@@ -715,7 +732,7 @@ function createImaController(video, options) {
715
732
  console.log(`[IMA] Initializing ads manager (${width}x${height})`);
716
733
  adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
717
734
  adPlaying = true;
718
- const adVolume = originalMutedState ? 0 : video.volume;
735
+ const adVolume = originalMutedState ? 0 : originalVolume;
719
736
  try {
720
737
  adsManager.setVolume(adVolume);
721
738
  console.log(`[IMA] Set ad volume to ${adVolume}`);
@@ -757,6 +774,7 @@ function createImaController(video, options) {
757
774
  destroyAdsManager();
758
775
  adPlaying = false;
759
776
  video.muted = originalMutedState;
777
+ video.volume = originalVolume;
760
778
  setAdPlayingFlag(false);
761
779
  if (adContainerEl) {
762
780
  adContainerEl.style.pointerEvents = "none";
@@ -801,15 +819,20 @@ function createImaController(video, options) {
801
819
  var _a;
802
820
  (_a = listeners.get(event)) == null ? void 0 : _a.delete(listener);
803
821
  },
804
- updateOriginalMutedState(muted) {
822
+ updateOriginalMutedState(muted, volume) {
823
+ const nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
805
824
  console.log(
806
- `[IMA] updateOriginalMutedState called: ${originalMutedState} -> ${muted}`
825
+ `[IMA] updateOriginalMutedState called: { muted: ${originalMutedState} -> ${muted}, volume: ${originalVolume} -> ${nextVolume} }`
807
826
  );
808
827
  originalMutedState = muted;
828
+ originalVolume = nextVolume;
809
829
  },
810
830
  getOriginalMutedState() {
811
831
  return originalMutedState;
812
832
  },
833
+ getOriginalVolume() {
834
+ return originalVolume;
835
+ },
813
836
  setAdVolume(volume) {
814
837
  if (adsManager && adPlaying) {
815
838
  try {
@@ -851,6 +874,7 @@ var import_hls = __toESM(require("hls.js"), 1);
851
874
  function createHlsAdPlayer(contentVideo, options) {
852
875
  let adPlaying = false;
853
876
  let originalMutedState = false;
877
+ let originalVolume = Math.max(0, Math.min(1, contentVideo.volume || 1));
854
878
  const listeners = /* @__PURE__ */ new Map();
855
879
  const licenseKey = options == null ? void 0 : options.licenseKey;
856
880
  const mainHlsInstance = options == null ? void 0 : options.mainHlsInstance;
@@ -1208,6 +1232,7 @@ function createHlsAdPlayer(contentVideo, options) {
1208
1232
  setAdPlayingFlag(false);
1209
1233
  const previousMutedState = contentVideo.muted;
1210
1234
  contentVideo.muted = originalMutedState;
1235
+ contentVideo.volume = originalMutedState ? 0 : originalVolume;
1211
1236
  console.log(
1212
1237
  `[HlsAdPlayer] Restored mute state: ${previousMutedState} -> ${originalMutedState}`
1213
1238
  );
@@ -1337,6 +1362,10 @@ function createHlsAdPlayer(contentVideo, options) {
1337
1362
  complete: false
1338
1363
  };
1339
1364
  const contentVolume = contentVideo.volume;
1365
+ originalVolume = Math.max(
1366
+ 0,
1367
+ Math.min(1, contentVolume || originalVolume)
1368
+ );
1340
1369
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1341
1370
  contentVideo.pause();
1342
1371
  console.log("[HlsAdPlayer] Content paused (VOD mode)");
@@ -1349,7 +1378,7 @@ function createHlsAdPlayer(contentVideo, options) {
1349
1378
  adPlaying = true;
1350
1379
  setAdPlayingFlag(true);
1351
1380
  if (adVideoElement) {
1352
- const adVolume = originalMutedState ? 0 : contentVolume;
1381
+ const adVolume = originalMutedState ? 0 : originalVolume;
1353
1382
  adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
1354
1383
  adVideoElement.muted = false;
1355
1384
  console.log(
@@ -1428,6 +1457,7 @@ function createHlsAdPlayer(contentVideo, options) {
1428
1457
  adPlaying = false;
1429
1458
  setAdPlayingFlag(false);
1430
1459
  contentVideo.muted = originalMutedState;
1460
+ contentVideo.volume = originalMutedState ? 0 : originalVolume;
1431
1461
  if (adHls) {
1432
1462
  adHls.destroy();
1433
1463
  adHls = void 0;
@@ -1469,15 +1499,20 @@ function createHlsAdPlayer(contentVideo, options) {
1469
1499
  var _a;
1470
1500
  (_a = listeners.get(event)) == null ? void 0 : _a.delete(listener);
1471
1501
  },
1472
- updateOriginalMutedState(muted) {
1502
+ updateOriginalMutedState(muted, volume) {
1503
+ const nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
1473
1504
  console.log(
1474
- `[HlsAdPlayer] updateOriginalMutedState called: ${originalMutedState} -> ${muted}`
1505
+ `[HlsAdPlayer] updateOriginalMutedState called: { muted: ${originalMutedState} -> ${muted}, volume: ${originalVolume} -> ${nextVolume} }`
1475
1506
  );
1476
1507
  originalMutedState = muted;
1508
+ originalVolume = nextVolume;
1477
1509
  },
1478
1510
  getOriginalMutedState() {
1479
1511
  return originalMutedState;
1480
1512
  },
1513
+ getOriginalVolume() {
1514
+ return originalVolume;
1515
+ },
1481
1516
  setAdVolume(volume) {
1482
1517
  if (adVideoElement && adPlaying) {
1483
1518
  adVideoElement.volume = Math.max(0, Math.min(1, volume));
@@ -2258,7 +2293,7 @@ var StormcloudVideoPlayer = class {
2258
2293
  this.video.autoplay = !!this.config.autoplay;
2259
2294
  this.video.muted = !!this.config.muted;
2260
2295
  this.ima.initialize();
2261
- this.ima.updateOriginalMutedState(this.video.muted);
2296
+ this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
2262
2297
  this.ima.on("all_ads_completed", () => {
2263
2298
  if (this.config.debugAdTiming) {
2264
2299
  console.log(
@@ -3147,7 +3182,7 @@ var StormcloudVideoPlayer = class {
3147
3182
  }
3148
3183
  );
3149
3184
  }
3150
- this.ima.updateOriginalMutedState(this.video.muted);
3185
+ this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3151
3186
  } else if (this.config.debugAdTiming) {
3152
3187
  console.log(
3153
3188
  `[StormcloudVideoPlayer] Keeping existing original mute state (currently showing ads)`
@@ -3209,8 +3244,9 @@ var StormcloudVideoPlayer = class {
3209
3244
  this.ima.stop().catch(() => {
3210
3245
  });
3211
3246
  const originalMutedState = this.ima.getOriginalMutedState();
3247
+ const originalVolume = typeof this.ima.getOriginalVolume === "function" ? this.ima.getOriginalVolume() : this.video.volume;
3212
3248
  this.video.muted = originalMutedState;
3213
- this.video.volume = originalMutedState ? 0 : 1;
3249
+ this.video.volume = originalVolume;
3214
3250
  if (this.config.debugAdTiming) {
3215
3251
  console.log(
3216
3252
  `[StormcloudVideoPlayer] Restored main video - muted: ${originalMutedState}, volume: ${this.video.volume}`
@@ -3361,7 +3397,7 @@ var StormcloudVideoPlayer = class {
3361
3397
  if (this.ima.isAdPlaying()) {
3362
3398
  const currentPerceptualState = this.isMuted();
3363
3399
  const newMutedState = !currentPerceptualState;
3364
- this.ima.updateOriginalMutedState(newMutedState);
3400
+ this.ima.updateOriginalMutedState(newMutedState, this.video.volume);
3365
3401
  this.ima.setAdVolume(newMutedState ? 0 : 1);
3366
3402
  if (this.config.debugAdTiming) {
3367
3403
  console.log(
@@ -3371,7 +3407,7 @@ var StormcloudVideoPlayer = class {
3371
3407
  }
3372
3408
  } else {
3373
3409
  this.video.muted = !this.video.muted;
3374
- this.ima.updateOriginalMutedState(this.video.muted);
3410
+ this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3375
3411
  if (this.config.debugAdTiming) {
3376
3412
  console.log("[StormcloudVideoPlayer] Muted:", this.video.muted);
3377
3413
  }
@@ -3443,7 +3479,7 @@ var StormcloudVideoPlayer = class {
3443
3479
  }
3444
3480
  this.video.muted = muted;
3445
3481
  if (adPlaying) {
3446
- this.ima.updateOriginalMutedState(muted);
3482
+ this.ima.updateOriginalMutedState(muted, this.video.volume);
3447
3483
  this.ima.setAdVolume(muted ? 0 : 1);
3448
3484
  if (this.config.debugAdTiming) {
3449
3485
  console.log("[StormcloudVideoPlayer] setMuted applied during ad", {
@@ -3452,11 +3488,31 @@ var StormcloudVideoPlayer = class {
3452
3488
  }
3453
3489
  return;
3454
3490
  }
3455
- this.ima.updateOriginalMutedState(muted);
3491
+ this.ima.updateOriginalMutedState(muted, this.video.volume);
3456
3492
  if (this.config.debugAdTiming) {
3457
3493
  console.log("[StormcloudVideoPlayer] setMuted called:", muted);
3458
3494
  }
3459
3495
  }
3496
+ setVolume(volume) {
3497
+ const clampedVolume = Math.max(0, Math.min(1, volume));
3498
+ const adPlaying = this.ima.isAdPlaying();
3499
+ if (adPlaying) {
3500
+ this.ima.setAdVolume(clampedVolume);
3501
+ this.ima.updateOriginalMutedState(clampedVolume === 0, clampedVolume);
3502
+ if (this.config.debugAdTiming) {
3503
+ console.log("[StormcloudVideoPlayer] setVolume applied during ad", {
3504
+ volume: clampedVolume
3505
+ });
3506
+ }
3507
+ } else {
3508
+ this.video.volume = clampedVolume;
3509
+ this.video.muted = clampedVolume === 0;
3510
+ this.ima.updateOriginalMutedState(clampedVolume === 0, clampedVolume);
3511
+ if (this.config.debugAdTiming) {
3512
+ console.log("[StormcloudVideoPlayer] setVolume called:", clampedVolume);
3513
+ }
3514
+ }
3515
+ }
3460
3516
  isFullscreen() {
3461
3517
  return !!document.fullscreenElement;
3462
3518
  }