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.
package/lib/index.cjs CHANGED
@@ -295,8 +295,11 @@ function createImaController(video, options) {
295
295
  );
296
296
  emit("ad_error");
297
297
  if (!options?.continueLiveStreamDuringAds) {
298
- video.play()?.catch(() => {
299
- });
298
+ if (video.paused) {
299
+ console.log("[IMA] Resuming paused video after ad error");
300
+ video.play()?.catch(() => {
301
+ });
302
+ }
300
303
  }
301
304
  }
302
305
  }
@@ -387,10 +390,17 @@ function createImaController(video, options) {
387
390
  console.error("[IMA] Error setting up ads manager:", e);
388
391
  adPlaying = false;
389
392
  video.muted = originalMutedState;
390
- 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 setup error");
397
+ }
391
398
  if (!options?.continueLiveStreamDuringAds) {
392
- video.play().catch(() => {
393
- });
399
+ if (video.paused) {
400
+ console.log("[IMA] Resuming paused video after setup error");
401
+ video.play().catch(() => {
402
+ });
403
+ }
394
404
  }
395
405
  if (adsLoadedReject) {
396
406
  adsLoadedReject(new Error("Failed to setup ads manager"));
@@ -408,10 +418,17 @@ function createImaController(video, options) {
408
418
  console.error("[IMA] Ads loader error:", adErrorEvent.getError());
409
419
  adPlaying = false;
410
420
  video.muted = originalMutedState;
411
- if (adContainerEl) adContainerEl.style.pointerEvents = "none";
421
+ if (adContainerEl) {
422
+ adContainerEl.style.pointerEvents = "none";
423
+ adContainerEl.style.display = "none";
424
+ console.log("[IMA] Ad container hidden after loader error");
425
+ }
412
426
  if (!options?.continueLiveStreamDuringAds) {
413
- video.play().catch(() => {
414
- });
427
+ if (video.paused) {
428
+ console.log("[IMA] Resuming paused video after loader error");
429
+ video.play().catch(() => {
430
+ });
431
+ }
415
432
  }
416
433
  if (adsLoadedReject) {
417
434
  adsLoadedReject(new Error("Ads loader error"));
@@ -988,15 +1005,25 @@ var StormcloudVideoPlayer = class {
988
1005
  if (this.config.debugAdTiming) {
989
1006
  console.log("[StormcloudVideoPlayer] IMA ad_error event received");
990
1007
  }
991
- if (!this.inAdBreak) return;
992
- const remaining = this.getRemainingAdMs();
993
- if (remaining > 500 && this.adPodQueue.length > 0) {
994
- const next = this.adPodQueue.shift();
995
- this.currentAdIndex++;
996
- this.playSingleAd(next).catch(() => {
997
- });
998
- } else {
999
- this.handleAdFailure();
1008
+ if (this.showAds) {
1009
+ if (this.inAdBreak) {
1010
+ const remaining = this.getRemainingAdMs();
1011
+ if (remaining > 500 && this.adPodQueue.length > 0) {
1012
+ const next = this.adPodQueue.shift();
1013
+ this.currentAdIndex++;
1014
+ this.playSingleAd(next).catch(() => {
1015
+ });
1016
+ } else {
1017
+ this.handleAdFailure();
1018
+ }
1019
+ } else {
1020
+ if (this.config.debugAdTiming) {
1021
+ console.log(
1022
+ "[StormcloudVideoPlayer] Ad error before ad break established - cleaning up"
1023
+ );
1024
+ }
1025
+ this.handleAdFailure();
1026
+ }
1000
1027
  }
1001
1028
  });
1002
1029
  this.ima.on("content_pause", () => {
@@ -1577,9 +1604,20 @@ var StormcloudVideoPlayer = class {
1577
1604
  return;
1578
1605
  }
1579
1606
  if (vastTagUrl) {
1607
+ this.inAdBreak = true;
1580
1608
  this.showAds = true;
1581
1609
  this.currentAdIndex++;
1582
- await this.playSingleAd(vastTagUrl);
1610
+ try {
1611
+ await this.playSingleAd(vastTagUrl);
1612
+ } catch (error) {
1613
+ if (this.config.debugAdTiming) {
1614
+ console.error(
1615
+ "[StormcloudVideoPlayer] Ad playback failed in handleAdStart:",
1616
+ error
1617
+ );
1618
+ }
1619
+ this.handleAdFailure();
1620
+ }
1583
1621
  }
1584
1622
  if (this.expectedAdBreakDurationMs == null && scheduled?.durationMs != null) {
1585
1623
  this.expectedAdBreakDurationMs = scheduled.durationMs;
@@ -1710,7 +1748,13 @@ var StormcloudVideoPlayer = class {
1710
1748
  handleAdFailure() {
1711
1749
  if (this.config.debugAdTiming) {
1712
1750
  console.log(
1713
- "[StormcloudVideoPlayer] Handling ad failure - resuming content"
1751
+ "[StormcloudVideoPlayer] Handling ad failure - resuming content",
1752
+ {
1753
+ inAdBreak: this.inAdBreak,
1754
+ showAds: this.showAds,
1755
+ videoPaused: this.video.paused,
1756
+ adPlaying: this.ima.isAdPlaying()
1757
+ }
1714
1758
  );
1715
1759
  }
1716
1760
  this.inAdBreak = false;
@@ -1731,13 +1775,21 @@ var StormcloudVideoPlayer = class {
1731
1775
  );
1732
1776
  }
1733
1777
  if (this.video.paused) {
1734
- this.video.play()?.catch(() => {
1778
+ if (this.config.debugAdTiming) {
1779
+ console.log("[StormcloudVideoPlayer] Resuming paused video");
1780
+ }
1781
+ this.video.play()?.catch((error) => {
1735
1782
  if (this.config.debugAdTiming) {
1736
1783
  console.error(
1737
- "[StormcloudVideoPlayer] Failed to resume video after ad failure"
1784
+ "[StormcloudVideoPlayer] Failed to resume video after ad failure:",
1785
+ error
1738
1786
  );
1739
1787
  }
1740
1788
  });
1789
+ } else {
1790
+ if (this.config.debugAdTiming) {
1791
+ console.log("[StormcloudVideoPlayer] Video is already playing, no resume needed");
1792
+ }
1741
1793
  }
1742
1794
  }
1743
1795
  startAdFailsafeTimer() {
@@ -1749,10 +1801,12 @@ var StormcloudVideoPlayer = class {
1749
1801
  );
1750
1802
  }
1751
1803
  this.adFailsafeTimerId = window.setTimeout(() => {
1752
- if (this.video.paused) {
1804
+ const shouldTrigger = this.video.paused || this.showAds && !this.ima.isAdPlaying();
1805
+ if (shouldTrigger) {
1753
1806
  if (this.config.debugAdTiming) {
1754
1807
  console.warn(
1755
- "[StormcloudVideoPlayer] Failsafe timer triggered - forcing video resume"
1808
+ "[StormcloudVideoPlayer] Failsafe timer triggered - forcing video resume",
1809
+ { paused: this.video.paused, showAds: this.showAds, adPlaying: this.ima.isAdPlaying() }
1756
1810
  );
1757
1811
  }
1758
1812
  this.handleAdFailure();