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.d.cts CHANGED
@@ -48,8 +48,9 @@ interface ImaController {
48
48
  resize: (width: number, height: number) => void;
49
49
  on: (event: string, listener: (payload?: any) => void) => void;
50
50
  off: (event: string, listener: (payload?: any) => void) => void;
51
- updateOriginalMutedState: (muted: boolean) => void;
51
+ updateOriginalMutedState: (muted: boolean, volume?: number) => void;
52
52
  getOriginalMutedState: () => boolean;
53
+ getOriginalVolume: () => number;
53
54
  setAdVolume: (volume: number) => void;
54
55
  getAdVolume: () => number;
55
56
  showPlaceholder: () => void;
package/lib/index.d.ts CHANGED
@@ -48,8 +48,9 @@ interface ImaController {
48
48
  resize: (width: number, height: number) => void;
49
49
  on: (event: string, listener: (payload?: any) => void) => void;
50
50
  off: (event: string, listener: (payload?: any) => void) => void;
51
- updateOriginalMutedState: (muted: boolean) => void;
51
+ updateOriginalMutedState: (muted: boolean, volume?: number) => void;
52
52
  getOriginalMutedState: () => boolean;
53
+ getOriginalVolume: () => number;
53
54
  setAdVolume: (volume: number) => void;
54
55
  getAdVolume: () => number;
55
56
  showPlaceholder: () => void;
package/lib/index.js CHANGED
@@ -197,6 +197,7 @@ function supportsFeature(feature) {
197
197
  function createImaController(video, options) {
198
198
  let adPlaying = false;
199
199
  let originalMutedState = false;
200
+ let originalVolume = typeof video.volume === "number" && !Number.isNaN(video.volume) ? Math.max(0, Math.min(1, video.volume)) : 1;
200
201
  const listeners = /* @__PURE__ */ new Map();
201
202
  const preloadedVast = /* @__PURE__ */ new Map();
202
203
  const preloadingVast = /* @__PURE__ */ new Map();
@@ -305,6 +306,22 @@ function createImaController(video, options) {
305
306
  adsRequest.linearAdSlotHeight = videoHeight;
306
307
  adsRequest.nonLinearAdSlotWidth = videoWidth;
307
308
  adsRequest.nonLinearAdSlotHeight = videoHeight;
309
+ if (typeof adsRequest.setAdWillAutoPlay === "function") {
310
+ try {
311
+ const willAutoPlay = !video.paused || video.autoplay;
312
+ adsRequest.setAdWillAutoPlay(willAutoPlay);
313
+ } catch (error) {
314
+ console.warn("[IMA] Failed to call setAdWillAutoPlay:", error);
315
+ }
316
+ }
317
+ if (typeof adsRequest.setAdWillPlayMuted === "function") {
318
+ try {
319
+ const willPlayMuted = video.muted || video.volume === 0;
320
+ adsRequest.setAdWillPlayMuted(willPlayMuted);
321
+ } catch (error) {
322
+ console.warn("[IMA] Failed to call setAdWillPlayMuted:", error);
323
+ }
324
+ }
308
325
  adsRequest.vastLoadTimeout = 5e3;
309
326
  console.log(`[IMA] Ads request dimensions: ${videoWidth}x${videoHeight}`);
310
327
  adsLoader.requestAds(adsRequest);
@@ -710,7 +727,7 @@ function createImaController(video, options) {
710
727
  console.log(`[IMA] Initializing ads manager (${width}x${height})`);
711
728
  adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
712
729
  adPlaying = true;
713
- const adVolume = originalMutedState ? 0 : video.volume;
730
+ const adVolume = originalMutedState ? 0 : originalVolume;
714
731
  try {
715
732
  adsManager.setVolume(adVolume);
716
733
  console.log(`[IMA] Set ad volume to ${adVolume}`);
@@ -752,6 +769,7 @@ function createImaController(video, options) {
752
769
  destroyAdsManager();
753
770
  adPlaying = false;
754
771
  video.muted = originalMutedState;
772
+ video.volume = originalVolume;
755
773
  setAdPlayingFlag(false);
756
774
  if (adContainerEl) {
757
775
  adContainerEl.style.pointerEvents = "none";
@@ -796,15 +814,20 @@ function createImaController(video, options) {
796
814
  var _a;
797
815
  (_a = listeners.get(event)) == null ? void 0 : _a.delete(listener);
798
816
  },
799
- updateOriginalMutedState(muted) {
817
+ updateOriginalMutedState(muted, volume) {
818
+ const nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
800
819
  console.log(
801
- `[IMA] updateOriginalMutedState called: ${originalMutedState} -> ${muted}`
820
+ `[IMA] updateOriginalMutedState called: { muted: ${originalMutedState} -> ${muted}, volume: ${originalVolume} -> ${nextVolume} }`
802
821
  );
803
822
  originalMutedState = muted;
823
+ originalVolume = nextVolume;
804
824
  },
805
825
  getOriginalMutedState() {
806
826
  return originalMutedState;
807
827
  },
828
+ getOriginalVolume() {
829
+ return originalVolume;
830
+ },
808
831
  setAdVolume(volume) {
809
832
  if (adsManager && adPlaying) {
810
833
  try {
@@ -846,6 +869,7 @@ import Hls from "hls.js";
846
869
  function createHlsAdPlayer(contentVideo, options) {
847
870
  let adPlaying = false;
848
871
  let originalMutedState = false;
872
+ let originalVolume = Math.max(0, Math.min(1, contentVideo.volume || 1));
849
873
  const listeners = /* @__PURE__ */ new Map();
850
874
  const licenseKey = options == null ? void 0 : options.licenseKey;
851
875
  const mainHlsInstance = options == null ? void 0 : options.mainHlsInstance;
@@ -1203,6 +1227,7 @@ function createHlsAdPlayer(contentVideo, options) {
1203
1227
  setAdPlayingFlag(false);
1204
1228
  const previousMutedState = contentVideo.muted;
1205
1229
  contentVideo.muted = originalMutedState;
1230
+ contentVideo.volume = originalMutedState ? 0 : originalVolume;
1206
1231
  console.log(
1207
1232
  `[HlsAdPlayer] Restored mute state: ${previousMutedState} -> ${originalMutedState}`
1208
1233
  );
@@ -1332,6 +1357,10 @@ function createHlsAdPlayer(contentVideo, options) {
1332
1357
  complete: false
1333
1358
  };
1334
1359
  const contentVolume = contentVideo.volume;
1360
+ originalVolume = Math.max(
1361
+ 0,
1362
+ Math.min(1, contentVolume || originalVolume)
1363
+ );
1335
1364
  if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
1336
1365
  contentVideo.pause();
1337
1366
  console.log("[HlsAdPlayer] Content paused (VOD mode)");
@@ -1344,7 +1373,7 @@ function createHlsAdPlayer(contentVideo, options) {
1344
1373
  adPlaying = true;
1345
1374
  setAdPlayingFlag(true);
1346
1375
  if (adVideoElement) {
1347
- const adVolume = originalMutedState ? 0 : contentVolume;
1376
+ const adVolume = originalMutedState ? 0 : originalVolume;
1348
1377
  adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
1349
1378
  adVideoElement.muted = false;
1350
1379
  console.log(
@@ -1423,6 +1452,7 @@ function createHlsAdPlayer(contentVideo, options) {
1423
1452
  adPlaying = false;
1424
1453
  setAdPlayingFlag(false);
1425
1454
  contentVideo.muted = originalMutedState;
1455
+ contentVideo.volume = originalMutedState ? 0 : originalVolume;
1426
1456
  if (adHls) {
1427
1457
  adHls.destroy();
1428
1458
  adHls = void 0;
@@ -1464,15 +1494,20 @@ function createHlsAdPlayer(contentVideo, options) {
1464
1494
  var _a;
1465
1495
  (_a = listeners.get(event)) == null ? void 0 : _a.delete(listener);
1466
1496
  },
1467
- updateOriginalMutedState(muted) {
1497
+ updateOriginalMutedState(muted, volume) {
1498
+ const nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
1468
1499
  console.log(
1469
- `[HlsAdPlayer] updateOriginalMutedState called: ${originalMutedState} -> ${muted}`
1500
+ `[HlsAdPlayer] updateOriginalMutedState called: { muted: ${originalMutedState} -> ${muted}, volume: ${originalVolume} -> ${nextVolume} }`
1470
1501
  );
1471
1502
  originalMutedState = muted;
1503
+ originalVolume = nextVolume;
1472
1504
  },
1473
1505
  getOriginalMutedState() {
1474
1506
  return originalMutedState;
1475
1507
  },
1508
+ getOriginalVolume() {
1509
+ return originalVolume;
1510
+ },
1476
1511
  setAdVolume(volume) {
1477
1512
  if (adVideoElement && adPlaying) {
1478
1513
  adVideoElement.volume = Math.max(0, Math.min(1, volume));
@@ -2253,7 +2288,7 @@ var StormcloudVideoPlayer = class {
2253
2288
  this.video.autoplay = !!this.config.autoplay;
2254
2289
  this.video.muted = !!this.config.muted;
2255
2290
  this.ima.initialize();
2256
- this.ima.updateOriginalMutedState(this.video.muted);
2291
+ this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
2257
2292
  this.ima.on("all_ads_completed", () => {
2258
2293
  if (this.config.debugAdTiming) {
2259
2294
  console.log(
@@ -3142,7 +3177,7 @@ var StormcloudVideoPlayer = class {
3142
3177
  }
3143
3178
  );
3144
3179
  }
3145
- this.ima.updateOriginalMutedState(this.video.muted);
3180
+ this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3146
3181
  } else if (this.config.debugAdTiming) {
3147
3182
  console.log(
3148
3183
  `[StormcloudVideoPlayer] Keeping existing original mute state (currently showing ads)`
@@ -3204,8 +3239,9 @@ var StormcloudVideoPlayer = class {
3204
3239
  this.ima.stop().catch(() => {
3205
3240
  });
3206
3241
  const originalMutedState = this.ima.getOriginalMutedState();
3242
+ const originalVolume = typeof this.ima.getOriginalVolume === "function" ? this.ima.getOriginalVolume() : this.video.volume;
3207
3243
  this.video.muted = originalMutedState;
3208
- this.video.volume = originalMutedState ? 0 : 1;
3244
+ this.video.volume = originalVolume;
3209
3245
  if (this.config.debugAdTiming) {
3210
3246
  console.log(
3211
3247
  `[StormcloudVideoPlayer] Restored main video - muted: ${originalMutedState}, volume: ${this.video.volume}`
@@ -3356,7 +3392,7 @@ var StormcloudVideoPlayer = class {
3356
3392
  if (this.ima.isAdPlaying()) {
3357
3393
  const currentPerceptualState = this.isMuted();
3358
3394
  const newMutedState = !currentPerceptualState;
3359
- this.ima.updateOriginalMutedState(newMutedState);
3395
+ this.ima.updateOriginalMutedState(newMutedState, this.video.volume);
3360
3396
  this.ima.setAdVolume(newMutedState ? 0 : 1);
3361
3397
  if (this.config.debugAdTiming) {
3362
3398
  console.log(
@@ -3366,7 +3402,7 @@ var StormcloudVideoPlayer = class {
3366
3402
  }
3367
3403
  } else {
3368
3404
  this.video.muted = !this.video.muted;
3369
- this.ima.updateOriginalMutedState(this.video.muted);
3405
+ this.ima.updateOriginalMutedState(this.video.muted, this.video.volume);
3370
3406
  if (this.config.debugAdTiming) {
3371
3407
  console.log("[StormcloudVideoPlayer] Muted:", this.video.muted);
3372
3408
  }
@@ -3438,7 +3474,7 @@ var StormcloudVideoPlayer = class {
3438
3474
  }
3439
3475
  this.video.muted = muted;
3440
3476
  if (adPlaying) {
3441
- this.ima.updateOriginalMutedState(muted);
3477
+ this.ima.updateOriginalMutedState(muted, this.video.volume);
3442
3478
  this.ima.setAdVolume(muted ? 0 : 1);
3443
3479
  if (this.config.debugAdTiming) {
3444
3480
  console.log("[StormcloudVideoPlayer] setMuted applied during ad", {
@@ -3447,7 +3483,7 @@ var StormcloudVideoPlayer = class {
3447
3483
  }
3448
3484
  return;
3449
3485
  }
3450
- this.ima.updateOriginalMutedState(muted);
3486
+ this.ima.updateOriginalMutedState(muted, this.video.volume);
3451
3487
  if (this.config.debugAdTiming) {
3452
3488
  console.log("[StormcloudVideoPlayer] setMuted called:", muted);
3453
3489
  }