stormcloud-video-player 0.2.10 → 0.2.12

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.
@@ -267,8 +267,11 @@ function createImaController(video, options) {
267
267
  );
268
268
  emit("ad_error");
269
269
  if (!options?.continueLiveStreamDuringAds) {
270
- video.play()?.catch(() => {
271
- });
270
+ if (video.paused) {
271
+ console.log("[IMA] Resuming paused video after ad error");
272
+ video.play()?.catch(() => {
273
+ });
274
+ }
272
275
  }
273
276
  }
274
277
  }
@@ -359,10 +362,17 @@ function createImaController(video, options) {
359
362
  console.error("[IMA] Error setting up ads manager:", e);
360
363
  adPlaying = false;
361
364
  video.muted = originalMutedState;
362
- if (adContainerEl) adContainerEl.style.pointerEvents = "none";
365
+ if (adContainerEl) {
366
+ adContainerEl.style.pointerEvents = "none";
367
+ adContainerEl.style.display = "none";
368
+ console.log("[IMA] Ad container hidden after setup error");
369
+ }
363
370
  if (!options?.continueLiveStreamDuringAds) {
364
- video.play().catch(() => {
365
- });
371
+ if (video.paused) {
372
+ console.log("[IMA] Resuming paused video after setup error");
373
+ video.play().catch(() => {
374
+ });
375
+ }
366
376
  }
367
377
  if (adsLoadedReject) {
368
378
  adsLoadedReject(new Error("Failed to setup ads manager"));
@@ -380,10 +390,17 @@ function createImaController(video, options) {
380
390
  console.error("[IMA] Ads loader error:", adErrorEvent.getError());
381
391
  adPlaying = false;
382
392
  video.muted = originalMutedState;
383
- if (adContainerEl) adContainerEl.style.pointerEvents = "none";
393
+ if (adContainerEl) {
394
+ adContainerEl.style.pointerEvents = "none";
395
+ adContainerEl.style.display = "none";
396
+ console.log("[IMA] Ad container hidden after loader error");
397
+ }
384
398
  if (!options?.continueLiveStreamDuringAds) {
385
- video.play().catch(() => {
386
- });
399
+ if (video.paused) {
400
+ console.log("[IMA] Resuming paused video after loader error");
401
+ video.play().catch(() => {
402
+ });
403
+ }
387
404
  }
388
405
  if (adsLoadedReject) {
389
406
  adsLoadedReject(new Error("Ads loader error"));
@@ -680,10 +697,18 @@ async function getBrowserID(clientInfo) {
680
697
  if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.digest) {
681
698
  try {
682
699
  await crypto.subtle.digest("SHA-256", new Uint8Array([1, 2, 3]));
683
- const hashBuffer = await crypto.subtle.digest(
684
- "SHA-256",
685
- new TextEncoder().encode(fingerprintString)
686
- );
700
+ let encodedData;
701
+ if (typeof TextEncoder !== "undefined") {
702
+ encodedData = new TextEncoder().encode(fingerprintString);
703
+ } else {
704
+ const utf8 = unescape(encodeURIComponent(fingerprintString));
705
+ const buffer = new Uint8Array(utf8.length);
706
+ for (let i = 0; i < utf8.length; i++) {
707
+ buffer[i] = utf8.charCodeAt(i);
708
+ }
709
+ encodedData = buffer;
710
+ }
711
+ const hashBuffer = await crypto.subtle.digest("SHA-256", encodedData);
687
712
  const hashArray = Array.from(new Uint8Array(hashBuffer));
688
713
  const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
689
714
  cachedBrowserId = hashHex;
@@ -960,15 +985,25 @@ var StormcloudVideoPlayer = class {
960
985
  if (this.config.debugAdTiming) {
961
986
  console.log("[StormcloudVideoPlayer] IMA ad_error event received");
962
987
  }
963
- if (!this.inAdBreak) return;
964
- const remaining = this.getRemainingAdMs();
965
- if (remaining > 500 && this.adPodQueue.length > 0) {
966
- const next = this.adPodQueue.shift();
967
- this.currentAdIndex++;
968
- this.playSingleAd(next).catch(() => {
969
- });
970
- } else {
971
- this.handleAdFailure();
988
+ if (this.showAds) {
989
+ if (this.inAdBreak) {
990
+ const remaining = this.getRemainingAdMs();
991
+ if (remaining > 500 && this.adPodQueue.length > 0) {
992
+ const next = this.adPodQueue.shift();
993
+ this.currentAdIndex++;
994
+ this.playSingleAd(next).catch(() => {
995
+ });
996
+ } else {
997
+ this.handleAdFailure();
998
+ }
999
+ } else {
1000
+ if (this.config.debugAdTiming) {
1001
+ console.log(
1002
+ "[StormcloudVideoPlayer] Ad error before ad break established - cleaning up"
1003
+ );
1004
+ }
1005
+ this.handleAdFailure();
1006
+ }
972
1007
  }
973
1008
  });
974
1009
  this.ima.on("content_pause", () => {
@@ -1549,9 +1584,20 @@ var StormcloudVideoPlayer = class {
1549
1584
  return;
1550
1585
  }
1551
1586
  if (vastTagUrl) {
1587
+ this.inAdBreak = true;
1552
1588
  this.showAds = true;
1553
1589
  this.currentAdIndex++;
1554
- await this.playSingleAd(vastTagUrl);
1590
+ try {
1591
+ await this.playSingleAd(vastTagUrl);
1592
+ } catch (error) {
1593
+ if (this.config.debugAdTiming) {
1594
+ console.error(
1595
+ "[StormcloudVideoPlayer] Ad playback failed in handleAdStart:",
1596
+ error
1597
+ );
1598
+ }
1599
+ this.handleAdFailure();
1600
+ }
1555
1601
  }
1556
1602
  if (this.expectedAdBreakDurationMs == null && scheduled?.durationMs != null) {
1557
1603
  this.expectedAdBreakDurationMs = scheduled.durationMs;
@@ -1682,7 +1728,13 @@ var StormcloudVideoPlayer = class {
1682
1728
  handleAdFailure() {
1683
1729
  if (this.config.debugAdTiming) {
1684
1730
  console.log(
1685
- "[StormcloudVideoPlayer] Handling ad failure - resuming content"
1731
+ "[StormcloudVideoPlayer] Handling ad failure - resuming content",
1732
+ {
1733
+ inAdBreak: this.inAdBreak,
1734
+ showAds: this.showAds,
1735
+ videoPaused: this.video.paused,
1736
+ adPlaying: this.ima.isAdPlaying()
1737
+ }
1686
1738
  );
1687
1739
  }
1688
1740
  this.inAdBreak = false;
@@ -1703,13 +1755,21 @@ var StormcloudVideoPlayer = class {
1703
1755
  );
1704
1756
  }
1705
1757
  if (this.video.paused) {
1706
- this.video.play()?.catch(() => {
1758
+ if (this.config.debugAdTiming) {
1759
+ console.log("[StormcloudVideoPlayer] Resuming paused video");
1760
+ }
1761
+ this.video.play()?.catch((error) => {
1707
1762
  if (this.config.debugAdTiming) {
1708
1763
  console.error(
1709
- "[StormcloudVideoPlayer] Failed to resume video after ad failure"
1764
+ "[StormcloudVideoPlayer] Failed to resume video after ad failure:",
1765
+ error
1710
1766
  );
1711
1767
  }
1712
1768
  });
1769
+ } else {
1770
+ if (this.config.debugAdTiming) {
1771
+ console.log("[StormcloudVideoPlayer] Video is already playing, no resume needed");
1772
+ }
1713
1773
  }
1714
1774
  }
1715
1775
  startAdFailsafeTimer() {
@@ -1721,10 +1781,12 @@ var StormcloudVideoPlayer = class {
1721
1781
  );
1722
1782
  }
1723
1783
  this.adFailsafeTimerId = window.setTimeout(() => {
1724
- if (this.video.paused) {
1784
+ const shouldTrigger = this.video.paused || this.showAds && !this.ima.isAdPlaying();
1785
+ if (shouldTrigger) {
1725
1786
  if (this.config.debugAdTiming) {
1726
1787
  console.warn(
1727
- "[StormcloudVideoPlayer] Failsafe timer triggered - forcing video resume"
1788
+ "[StormcloudVideoPlayer] Failsafe timer triggered - forcing video resume",
1789
+ { paused: this.video.paused, showAds: this.showAds, adPlaying: this.ima.isAdPlaying() }
1728
1790
  );
1729
1791
  }
1730
1792
  this.handleAdFailure();