stormcloud-video-player 0.2.10 → 0.2.11

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.
@@ -309,8 +309,11 @@ function createImaController(video, options) {
309
309
  );
310
310
  emit("ad_error");
311
311
  if (!options?.continueLiveStreamDuringAds) {
312
- video.play()?.catch(() => {
313
- });
312
+ if (video.paused) {
313
+ console.log("[IMA] Resuming paused video after ad error");
314
+ video.play()?.catch(() => {
315
+ });
316
+ }
314
317
  }
315
318
  }
316
319
  }
@@ -401,10 +404,17 @@ function createImaController(video, options) {
401
404
  console.error("[IMA] Error setting up ads manager:", e);
402
405
  adPlaying = false;
403
406
  video.muted = originalMutedState;
404
- if (adContainerEl) adContainerEl.style.pointerEvents = "none";
407
+ if (adContainerEl) {
408
+ adContainerEl.style.pointerEvents = "none";
409
+ adContainerEl.style.display = "none";
410
+ console.log("[IMA] Ad container hidden after setup error");
411
+ }
405
412
  if (!options?.continueLiveStreamDuringAds) {
406
- video.play().catch(() => {
407
- });
413
+ if (video.paused) {
414
+ console.log("[IMA] Resuming paused video after setup error");
415
+ video.play().catch(() => {
416
+ });
417
+ }
408
418
  }
409
419
  if (adsLoadedReject) {
410
420
  adsLoadedReject(new Error("Failed to setup ads manager"));
@@ -422,10 +432,17 @@ function createImaController(video, options) {
422
432
  console.error("[IMA] Ads loader error:", adErrorEvent.getError());
423
433
  adPlaying = false;
424
434
  video.muted = originalMutedState;
425
- if (adContainerEl) adContainerEl.style.pointerEvents = "none";
435
+ if (adContainerEl) {
436
+ adContainerEl.style.pointerEvents = "none";
437
+ adContainerEl.style.display = "none";
438
+ console.log("[IMA] Ad container hidden after loader error");
439
+ }
426
440
  if (!options?.continueLiveStreamDuringAds) {
427
- video.play().catch(() => {
428
- });
441
+ if (video.paused) {
442
+ console.log("[IMA] Resuming paused video after loader error");
443
+ video.play().catch(() => {
444
+ });
445
+ }
429
446
  }
430
447
  if (adsLoadedReject) {
431
448
  adsLoadedReject(new Error("Ads loader error"));
@@ -1002,15 +1019,25 @@ var StormcloudVideoPlayer = class {
1002
1019
  if (this.config.debugAdTiming) {
1003
1020
  console.log("[StormcloudVideoPlayer] IMA ad_error event received");
1004
1021
  }
1005
- if (!this.inAdBreak) return;
1006
- const remaining = this.getRemainingAdMs();
1007
- if (remaining > 500 && this.adPodQueue.length > 0) {
1008
- const next = this.adPodQueue.shift();
1009
- this.currentAdIndex++;
1010
- this.playSingleAd(next).catch(() => {
1011
- });
1012
- } else {
1013
- this.handleAdFailure();
1022
+ if (this.showAds) {
1023
+ if (this.inAdBreak) {
1024
+ const remaining = this.getRemainingAdMs();
1025
+ if (remaining > 500 && this.adPodQueue.length > 0) {
1026
+ const next = this.adPodQueue.shift();
1027
+ this.currentAdIndex++;
1028
+ this.playSingleAd(next).catch(() => {
1029
+ });
1030
+ } else {
1031
+ this.handleAdFailure();
1032
+ }
1033
+ } else {
1034
+ if (this.config.debugAdTiming) {
1035
+ console.log(
1036
+ "[StormcloudVideoPlayer] Ad error before ad break established - cleaning up"
1037
+ );
1038
+ }
1039
+ this.handleAdFailure();
1040
+ }
1014
1041
  }
1015
1042
  });
1016
1043
  this.ima.on("content_pause", () => {
@@ -1591,9 +1618,20 @@ var StormcloudVideoPlayer = class {
1591
1618
  return;
1592
1619
  }
1593
1620
  if (vastTagUrl) {
1621
+ this.inAdBreak = true;
1594
1622
  this.showAds = true;
1595
1623
  this.currentAdIndex++;
1596
- await this.playSingleAd(vastTagUrl);
1624
+ try {
1625
+ await this.playSingleAd(vastTagUrl);
1626
+ } catch (error) {
1627
+ if (this.config.debugAdTiming) {
1628
+ console.error(
1629
+ "[StormcloudVideoPlayer] Ad playback failed in handleAdStart:",
1630
+ error
1631
+ );
1632
+ }
1633
+ this.handleAdFailure();
1634
+ }
1597
1635
  }
1598
1636
  if (this.expectedAdBreakDurationMs == null && scheduled?.durationMs != null) {
1599
1637
  this.expectedAdBreakDurationMs = scheduled.durationMs;
@@ -1724,7 +1762,13 @@ var StormcloudVideoPlayer = class {
1724
1762
  handleAdFailure() {
1725
1763
  if (this.config.debugAdTiming) {
1726
1764
  console.log(
1727
- "[StormcloudVideoPlayer] Handling ad failure - resuming content"
1765
+ "[StormcloudVideoPlayer] Handling ad failure - resuming content",
1766
+ {
1767
+ inAdBreak: this.inAdBreak,
1768
+ showAds: this.showAds,
1769
+ videoPaused: this.video.paused,
1770
+ adPlaying: this.ima.isAdPlaying()
1771
+ }
1728
1772
  );
1729
1773
  }
1730
1774
  this.inAdBreak = false;
@@ -1745,13 +1789,21 @@ var StormcloudVideoPlayer = class {
1745
1789
  );
1746
1790
  }
1747
1791
  if (this.video.paused) {
1748
- this.video.play()?.catch(() => {
1792
+ if (this.config.debugAdTiming) {
1793
+ console.log("[StormcloudVideoPlayer] Resuming paused video");
1794
+ }
1795
+ this.video.play()?.catch((error) => {
1749
1796
  if (this.config.debugAdTiming) {
1750
1797
  console.error(
1751
- "[StormcloudVideoPlayer] Failed to resume video after ad failure"
1798
+ "[StormcloudVideoPlayer] Failed to resume video after ad failure:",
1799
+ error
1752
1800
  );
1753
1801
  }
1754
1802
  });
1803
+ } else {
1804
+ if (this.config.debugAdTiming) {
1805
+ console.log("[StormcloudVideoPlayer] Video is already playing, no resume needed");
1806
+ }
1755
1807
  }
1756
1808
  }
1757
1809
  startAdFailsafeTimer() {
@@ -1763,10 +1815,12 @@ var StormcloudVideoPlayer = class {
1763
1815
  );
1764
1816
  }
1765
1817
  this.adFailsafeTimerId = window.setTimeout(() => {
1766
- if (this.video.paused) {
1818
+ const shouldTrigger = this.video.paused || this.showAds && !this.ima.isAdPlaying();
1819
+ if (shouldTrigger) {
1767
1820
  if (this.config.debugAdTiming) {
1768
1821
  console.warn(
1769
- "[StormcloudVideoPlayer] Failsafe timer triggered - forcing video resume"
1822
+ "[StormcloudVideoPlayer] Failsafe timer triggered - forcing video resume",
1823
+ { paused: this.video.paused, showAds: this.showAds, adPlaying: this.ima.isAdPlaying() }
1770
1824
  );
1771
1825
  }
1772
1826
  this.handleAdFailure();