stormcloud-video-player 0.6.2 → 0.6.3

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
@@ -1439,7 +1439,7 @@ function createVastAdLayer(contentVideo, options) {
1439
1439
  }
1440
1440
  function playAd(bids) {
1441
1441
  return _async_to_generator(function() {
1442
- var winner, ad, contentVolume, _contentVideo_parentElement, container, adVolume, mediaFile;
1442
+ var winner, ad, contentVolume, adVolume2, mediaFile2, _contentVideo_parentElement, container, adVolume, mediaFile;
1443
1443
  return _ts_generator(this, function(_state) {
1444
1444
  switch(_state.label){
1445
1445
  case 0:
@@ -1483,37 +1483,71 @@ function createVastAdLayer(contentVideo, options) {
1483
1483
  trackingFired.impression = true;
1484
1484
  contentVolume = contentVideo.volume;
1485
1485
  originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
1486
- if (singleElementMode) {
1487
- mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1488
- teardownCurrentPlayback();
1489
- adVideoElement = contentVideo;
1490
- adHls = void 0;
1486
+ if (!singleElementMode) return [
1487
+ 3,
1488
+ 3
1489
+ ];
1490
+ mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1491
+ teardownCurrentPlayback();
1492
+ adVideoElement = contentVideo;
1493
+ adHls = void 0;
1494
+ adPlaying = true;
1495
+ setAdPlayingFlag(true);
1496
+ contentVideo.removeAttribute("src");
1497
+ contentVideo.load();
1498
+ if (!continueLiveStreamDuringAds) {
1499
+ contentVideo.pause();
1500
+ }
1501
+ contentVideo.muted = true;
1502
+ contentVideo.volume = 0;
1503
+ return [
1504
+ 4,
1505
+ new Promise(function(resolve) {
1506
+ return setTimeout(resolve, 200);
1507
+ })
1508
+ ];
1509
+ case 2:
1510
+ _state.sent();
1511
+ if (destroyed || tornDown) return [
1512
+ 2
1513
+ ];
1514
+ contentVideo.style.visibility = "visible";
1515
+ contentVideo.style.opacity = "1";
1516
+ emit("content_pause");
1517
+ setupAdEventListeners();
1518
+ adVolume2 = originalMutedState ? 1 : originalVolume;
1519
+ adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
1520
+ adVideoElement.muted = false;
1521
+ mediaFile2 = selectBestMediaFile(ad.mediaFiles);
1522
+ if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
1523
+ startPlayback(mediaFile2);
1524
+ return [
1525
+ 2
1526
+ ];
1527
+ case 3:
1528
+ if (!adContainerEl) {
1529
+ ;
1530
+ container = document.createElement("div");
1531
+ container.style.position = "absolute";
1532
+ container.style.left = "0";
1533
+ container.style.top = "0";
1534
+ container.style.right = "0";
1535
+ container.style.bottom = "0";
1536
+ container.style.display = "none";
1537
+ container.style.alignItems = "center";
1538
+ container.style.justifyContent = "center";
1539
+ container.style.pointerEvents = "none";
1540
+ container.style.zIndex = "10";
1541
+ container.style.backgroundColor = "#000";
1542
+ (_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
1543
+ adContainerEl = container;
1544
+ }
1545
+ if (!adVideoElement) {
1546
+ adVideoElement = createAdVideoElement();
1547
+ adContainerEl.appendChild(adVideoElement);
1491
1548
  setupAdEventListeners();
1492
1549
  } else {
1493
- if (!adContainerEl) {
1494
- ;
1495
- container = document.createElement("div");
1496
- container.style.position = "absolute";
1497
- container.style.left = "0";
1498
- container.style.top = "0";
1499
- container.style.right = "0";
1500
- container.style.bottom = "0";
1501
- container.style.display = "none";
1502
- container.style.alignItems = "center";
1503
- container.style.justifyContent = "center";
1504
- container.style.pointerEvents = "none";
1505
- container.style.zIndex = "10";
1506
- container.style.backgroundColor = "#000";
1507
- (_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
1508
- adContainerEl = container;
1509
- }
1510
- if (!adVideoElement) {
1511
- adVideoElement = createAdVideoElement();
1512
- adContainerEl.appendChild(adVideoElement);
1513
- setupAdEventListeners();
1514
- } else {
1515
- teardownCurrentPlayback();
1516
- }
1550
+ teardownCurrentPlayback();
1517
1551
  }
1518
1552
  if (!continueLiveStreamDuringAds) {
1519
1553
  contentVideo.pause();
@@ -1525,7 +1559,7 @@ function createVastAdLayer(contentVideo, options) {
1525
1559
  adVolume = originalMutedState ? 1 : originalVolume;
1526
1560
  adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
1527
1561
  adVideoElement.muted = false;
1528
- if (!singleElementMode && adContainerEl) {
1562
+ if (adContainerEl) {
1529
1563
  adContainerEl.style.display = "flex";
1530
1564
  adContainerEl.style.pointerEvents = "auto";
1531
1565
  }
@@ -1629,6 +1663,7 @@ function createVastAdLayer(contentVideo, options) {
1629
1663
  if (debug) console.log("".concat(LOG, " [preload] HLS manifest parsed, token=").concat(token));
1630
1664
  });
1631
1665
  hls.on(import_hls.default.Events.ERROR, function(_evt, data) {
1666
+ if (!preloadSlots.has(token)) return;
1632
1667
  if (data.fatal) {
1633
1668
  if (debug) console.warn("".concat(LOG, " [preload] HLS error for token=").concat(token));
1634
1669
  preloadSlots.delete(token);
@@ -1665,113 +1700,146 @@ function createVastAdLayer(contentVideo, options) {
1665
1700
  }
1666
1701
  function playPreloaded(token) {
1667
1702
  return _async_to_generator(function() {
1668
- var slot, contentVolume, adVolume2, videoEl, container2, adVolume21, adVolume, container;
1703
+ var slot, contentVolume, adVolume2, videoEl, container2, adVolume21, nonFatalNetworkErrors, adVolume, container;
1669
1704
  return _ts_generator(this, function(_state) {
1670
- if (destroyed) return [
1671
- 2,
1672
- Promise.reject(new Error("Layer has been destroyed"))
1673
- ];
1674
- slot = preloadSlots.get(token);
1675
- if (!slot) {
1676
- if (debug) console.warn("".concat(LOG, " [preload] No slot found for token=").concat(token, ", nothing to play"));
1677
- return [
1678
- 2
1679
- ];
1680
- }
1681
- preloadSlots.delete(token);
1682
- if (debug) console.log("".concat(LOG, " [preload] Playing preloaded ad, token=").concat(token, ", ready=").concat(slot.ready));
1683
- contentVolume = contentVideo.volume;
1684
- originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
1685
- sessionId = generateSessionId();
1686
- currentAd = slot.ad;
1687
- trackingFired = _object_spread({}, createEmptyTrackingState());
1688
- fireTrackingPixels2(slot.ad.trackingUrls.impression);
1689
- trackingFired.impression = true;
1690
- if (singleElementMode) {
1691
- mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1692
- teardownCurrentPlayback();
1693
- adVideoElement = contentVideo;
1694
- adHls = void 0;
1695
- setupAdEventListeners();
1696
- if (!continueLiveStreamDuringAds) {
1697
- contentVideo.pause();
1698
- }
1699
- contentVideo.muted = true;
1700
- contentVideo.volume = 0;
1701
- adPlaying = true;
1702
- setAdPlayingFlag(true);
1703
- adVolume2 = originalMutedState ? 1 : originalVolume;
1704
- contentVideo.volume = Math.max(0, Math.min(1, adVolume2));
1705
- contentVideo.muted = false;
1706
- emit("content_pause");
1707
- if (debug) console.log("".concat(LOG, " [preload] singleElementMode: attaching ad to contentVideo, url=").concat(slot.mediaFile.url));
1708
- startPlayback(slot.mediaFile);
1709
- return [
1710
- 2
1711
- ];
1712
- }
1713
- if (smartTVMode && !slot.videoEl) {
1714
- teardownCurrentPlayback();
1715
- if (adVideoElement) {
1716
- adVideoElement.remove();
1717
- adVideoElement = void 0;
1718
- }
1719
- videoEl = createAdVideoElement();
1720
- videoEl.style.visibility = "visible";
1721
- videoEl.style.pointerEvents = "none";
1722
- container2 = ensureAdContainer();
1723
- container2.appendChild(videoEl);
1724
- adVideoElement = videoEl;
1725
- setupAdEventListeners();
1726
- if (!continueLiveStreamDuringAds) {
1727
- contentVideo.pause();
1728
- }
1729
- contentVideo.muted = true;
1730
- contentVideo.volume = 0;
1731
- adPlaying = true;
1732
- setAdPlayingFlag(true);
1733
- adVolume21 = originalMutedState ? 1 : originalVolume;
1734
- adVideoElement.volume = Math.max(0, Math.min(1, adVolume21));
1735
- adVideoElement.muted = false;
1736
- container2.style.display = "flex";
1737
- container2.style.pointerEvents = "auto";
1738
- emit("content_pause");
1739
- if (debug) console.log("".concat(LOG, " [preload] smartTVMode deferred: creating video element and loading, url=").concat(slot.mediaFile.url));
1740
- startPlayback(slot.mediaFile);
1741
- return [
1742
- 2
1743
- ];
1744
- }
1745
- teardownCurrentPlayback();
1746
- if (adVideoElement && adVideoElement !== slot.videoEl) {
1747
- adVideoElement.remove();
1705
+ switch(_state.label){
1706
+ case 0:
1707
+ if (destroyed) return [
1708
+ 2,
1709
+ Promise.reject(new Error("Layer has been destroyed"))
1710
+ ];
1711
+ slot = preloadSlots.get(token);
1712
+ if (!slot) {
1713
+ if (debug) console.warn("".concat(LOG, " [preload] No slot found for token=").concat(token, ", nothing to play"));
1714
+ return [
1715
+ 2
1716
+ ];
1717
+ }
1718
+ preloadSlots.delete(token);
1719
+ if (debug) console.log("".concat(LOG, " [preload] Playing preloaded ad, token=").concat(token, ", ready=").concat(slot.ready));
1720
+ contentVolume = contentVideo.volume;
1721
+ originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
1722
+ sessionId = generateSessionId();
1723
+ currentAd = slot.ad;
1724
+ trackingFired = _object_spread({}, createEmptyTrackingState());
1725
+ fireTrackingPixels2(slot.ad.trackingUrls.impression);
1726
+ trackingFired.impression = true;
1727
+ if (!singleElementMode) return [
1728
+ 3,
1729
+ 2
1730
+ ];
1731
+ mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1732
+ teardownCurrentPlayback();
1733
+ adVideoElement = contentVideo;
1734
+ adHls = void 0;
1735
+ adPlaying = true;
1736
+ setAdPlayingFlag(true);
1737
+ contentVideo.removeAttribute("src");
1738
+ contentVideo.load();
1739
+ contentVideo.muted = true;
1740
+ contentVideo.volume = 0;
1741
+ return [
1742
+ 4,
1743
+ new Promise(function(resolve) {
1744
+ return setTimeout(resolve, 200);
1745
+ })
1746
+ ];
1747
+ case 1:
1748
+ _state.sent();
1749
+ if (destroyed || tornDown) return [
1750
+ 2
1751
+ ];
1752
+ contentVideo.style.visibility = "visible";
1753
+ contentVideo.style.opacity = "1";
1754
+ emit("content_pause");
1755
+ setupAdEventListeners();
1756
+ adVolume2 = originalMutedState ? 1 : originalVolume;
1757
+ contentVideo.volume = Math.max(0, Math.min(1, adVolume2));
1758
+ contentVideo.muted = false;
1759
+ if (debug) console.log("".concat(LOG, " [preload] singleElementMode: attaching ad to contentVideo, url=").concat(slot.mediaFile.url));
1760
+ startPlayback(slot.mediaFile);
1761
+ return [
1762
+ 2
1763
+ ];
1764
+ case 2:
1765
+ if (smartTVMode && !slot.videoEl) {
1766
+ teardownCurrentPlayback();
1767
+ if (adVideoElement) {
1768
+ adVideoElement.remove();
1769
+ adVideoElement = void 0;
1770
+ }
1771
+ videoEl = createAdVideoElement();
1772
+ videoEl.style.visibility = "visible";
1773
+ videoEl.style.pointerEvents = "none";
1774
+ container2 = ensureAdContainer();
1775
+ container2.appendChild(videoEl);
1776
+ adVideoElement = videoEl;
1777
+ setupAdEventListeners();
1778
+ if (!continueLiveStreamDuringAds) {
1779
+ contentVideo.pause();
1780
+ }
1781
+ contentVideo.muted = true;
1782
+ contentVideo.volume = 0;
1783
+ adPlaying = true;
1784
+ setAdPlayingFlag(true);
1785
+ adVolume21 = originalMutedState ? 1 : originalVolume;
1786
+ adVideoElement.volume = Math.max(0, Math.min(1, adVolume21));
1787
+ adVideoElement.muted = false;
1788
+ container2.style.display = "flex";
1789
+ container2.style.pointerEvents = "auto";
1790
+ emit("content_pause");
1791
+ if (debug) console.log("".concat(LOG, " [preload] smartTVMode deferred: creating video element and loading, url=").concat(slot.mediaFile.url));
1792
+ startPlayback(slot.mediaFile);
1793
+ return [
1794
+ 2
1795
+ ];
1796
+ }
1797
+ teardownCurrentPlayback();
1798
+ if (adVideoElement && adVideoElement !== slot.videoEl) {
1799
+ adVideoElement.remove();
1800
+ }
1801
+ slot.videoEl.style.visibility = "visible";
1802
+ slot.videoEl.style.pointerEvents = "none";
1803
+ adVideoElement = slot.videoEl;
1804
+ adHls = slot.hlsInstance;
1805
+ if (adHls) {
1806
+ nonFatalNetworkErrors = 0;
1807
+ adHls.on(import_hls.default.Events.ERROR, function(_event, data) {
1808
+ if (!adPlaying) return;
1809
+ if (data.fatal) {
1810
+ handleAdError();
1811
+ } else if (data.type === import_hls.default.ErrorTypes.NETWORK_ERROR) {
1812
+ nonFatalNetworkErrors++;
1813
+ if (nonFatalNetworkErrors >= 3) {
1814
+ if (debug) console.warn("".concat(LOG, " [preload] Too many non-fatal HLS network errors during playback, treating as fatal"));
1815
+ handleAdError();
1816
+ }
1817
+ }
1818
+ });
1819
+ }
1820
+ setupAdEventListeners();
1821
+ if (!continueLiveStreamDuringAds) {
1822
+ contentVideo.pause();
1823
+ }
1824
+ contentVideo.muted = true;
1825
+ contentVideo.volume = 0;
1826
+ adPlaying = true;
1827
+ setAdPlayingFlag(true);
1828
+ adVolume = originalMutedState ? 1 : originalVolume;
1829
+ adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
1830
+ adVideoElement.muted = false;
1831
+ container = ensureAdContainer();
1832
+ container.style.display = "flex";
1833
+ container.style.pointerEvents = "auto";
1834
+ emit("content_pause");
1835
+ adVideoElement.play().catch(function(error) {
1836
+ console.error("".concat(LOG, " [preload] Error playing preloaded ad:"), error);
1837
+ handleAdError();
1838
+ });
1839
+ return [
1840
+ 2
1841
+ ];
1748
1842
  }
1749
- slot.videoEl.style.visibility = "visible";
1750
- slot.videoEl.style.pointerEvents = "none";
1751
- adVideoElement = slot.videoEl;
1752
- adHls = slot.hlsInstance;
1753
- setupAdEventListeners();
1754
- if (!continueLiveStreamDuringAds) {
1755
- contentVideo.pause();
1756
- }
1757
- contentVideo.muted = true;
1758
- contentVideo.volume = 0;
1759
- adPlaying = true;
1760
- setAdPlayingFlag(true);
1761
- adVolume = originalMutedState ? 1 : originalVolume;
1762
- adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
1763
- adVideoElement.muted = false;
1764
- container = ensureAdContainer();
1765
- container.style.display = "flex";
1766
- container.style.pointerEvents = "auto";
1767
- emit("content_pause");
1768
- adVideoElement.play().catch(function(error) {
1769
- console.error("".concat(LOG, " [preload] Error playing preloaded ad:"), error);
1770
- handleAdError();
1771
- });
1772
- return [
1773
- 2
1774
- ];
1775
1843
  });
1776
1844
  })();
1777
1845
  }
@@ -4052,7 +4120,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4052
4120
  };
4053
4121
  this.adLayer.updateOriginalMutedState(this.video.muted, this.video.volume);
4054
4122
  }
4055
- if (!this.config.disableFiller && !this.video.muted) {
4123
+ if (!this.config.disableFiller && !this.video.muted && !this.adLayer.isAdPlaying()) {
4056
4124
  this.video.muted = true;
4057
4125
  this.video.volume = 0;
4058
4126
  if (this.config.debugAdTiming) {
@@ -5686,7 +5754,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5686
5754
  console.log("[StormcloudVideoPlayer] Smart TV: audio state restored on MANIFEST_PARSED after re-attach");
5687
5755
  }
5688
5756
  hlsRef.startLoad(-1);
5689
- tryPlay(0);
5690
5757
  if (debugEnabled) {
5691
5758
  console.log("[StormcloudVideoPlayer] Smart TV: seeking to live edge and resuming playback after re-attach");
5692
5759
  }