stormcloud-video-player 0.8.49 → 0.8.50

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
@@ -601,6 +601,7 @@ function createHlsAdPlayer(contentVideo, options) {
601
601
  var mainHlsInstance = options === null || options === void 0 ? void 0 : options.mainHlsInstance;
602
602
  var AD_CONTAINER_PROP = "__stormcloudAdContainer";
603
603
  var AD_VIDEO_PROP = "__stormcloudAdVideo";
604
+ var FRAME_COUNTER_RELIABLE_PROP = "__stormcloudFrameCounterReliable";
604
605
  var adVideoElement = (_contentVideo_AD_VIDEO_PROP = contentVideo[AD_VIDEO_PROP]) !== null && _contentVideo_AD_VIDEO_PROP !== void 0 ? _contentVideo_AD_VIDEO_PROP : void 0;
605
606
  var adHls;
606
607
  var adContainerEl = (_contentVideo_AD_CONTAINER_PROP = contentVideo[AD_CONTAINER_PROP]) !== null && _contentVideo_AD_CONTAINER_PROP !== void 0 ? _contentVideo_AD_CONTAINER_PROP : void 0;
@@ -620,6 +621,7 @@ function createHlsAdPlayer(contentVideo, options) {
620
621
  var lastAdProgressTime = 0;
621
622
  var lastAdProgressPosition = 0;
622
623
  var sawDecodedVideoFrame = false;
624
+ var videoFrameCallbackHandle;
623
625
  var trackingFired = {
624
626
  impression: false,
625
627
  start: false,
@@ -1506,6 +1508,7 @@ function createHlsAdPlayer(contentVideo, options) {
1506
1508
  clearInterval(stallWatchdogId);
1507
1509
  stallWatchdogId = void 0;
1508
1510
  }
1511
+ cancelVideoFrameProbe();
1509
1512
  }
1510
1513
  function noteAdProgress() {
1511
1514
  lastAdProgressTime = Date.now();
@@ -1541,6 +1544,39 @@ function createHlsAdPlayer(contentVideo, options) {
1541
1544
  }
1542
1545
  return void 0;
1543
1546
  }
1547
+ function isFrameCounterReliable() {
1548
+ return contentVideo[FRAME_COUNTER_RELIABLE_PROP] === true;
1549
+ }
1550
+ function markFrameCounterReliable() {
1551
+ contentVideo[FRAME_COUNTER_RELIABLE_PROP] = true;
1552
+ }
1553
+ function cancelVideoFrameProbe() {
1554
+ if (videoFrameCallbackHandle != null && adVideoElement && typeof adVideoElement.cancelVideoFrameCallback === "function") {
1555
+ try {
1556
+ adVideoElement.cancelVideoFrameCallback(videoFrameCallbackHandle);
1557
+ } catch (error) {
1558
+ console.warn("[HlsAdPlayer] Error cancelling video frame callback:", error);
1559
+ }
1560
+ }
1561
+ videoFrameCallbackHandle = void 0;
1562
+ }
1563
+ function startVideoFrameProbe() {
1564
+ cancelVideoFrameProbe();
1565
+ if (!adVideoElement) return;
1566
+ var rvfc = adVideoElement.requestVideoFrameCallback;
1567
+ if (typeof rvfc !== "function") return;
1568
+ var onPresentedFrame = function onPresentedFrame() {
1569
+ videoFrameCallbackHandle = void 0;
1570
+ if (!adPlaying) return;
1571
+ sawDecodedVideoFrame = true;
1572
+ };
1573
+ try {
1574
+ videoFrameCallbackHandle = rvfc.call(adVideoElement, onPresentedFrame);
1575
+ } catch (error) {
1576
+ console.warn("[HlsAdPlayer] Error requesting video frame callback:", error);
1577
+ videoFrameCallbackHandle = void 0;
1578
+ }
1579
+ }
1544
1580
  function handleVideoDecodeFailure() {
1545
1581
  console.warn("[HlsAdPlayer] Ad audio is advancing but no video frames decoded (black screen) - skipping this creative");
1546
1582
  clearStallWatchdog();
@@ -1556,6 +1592,7 @@ function createHlsAdPlayer(contentVideo, options) {
1556
1592
  clearStallWatchdog();
1557
1593
  noteAdProgress();
1558
1594
  sawDecodedVideoFrame = false;
1595
+ startVideoFrameProbe();
1559
1596
  stallWatchdogId = window.setInterval(function() {
1560
1597
  if (!adPlaying || !adVideoElement) {
1561
1598
  return;
@@ -1564,7 +1601,8 @@ function createHlsAdPlayer(contentVideo, options) {
1564
1601
  var decodedFrames = getDecodedVideoFrameCount(adVideoElement);
1565
1602
  if (decodedFrames !== void 0 && decodedFrames > 0) {
1566
1603
  sawDecodedVideoFrame = true;
1567
- } else if (decodedFrames === 0 && adVideoElement.currentTime >= BLACKFRAME_MIN_PLAYBACK_S) {
1604
+ markFrameCounterReliable();
1605
+ } else if (decodedFrames === 0 && adVideoElement.currentTime >= BLACKFRAME_MIN_PLAYBACK_S && isFrameCounterReliable()) {
1568
1606
  handleVideoDecodeFailure();
1569
1607
  return;
1570
1608
  }
@@ -6453,17 +6491,17 @@ var AdTimingService = /*#__PURE__*/ function() {
6453
6491
  {
6454
6492
  key: "logAdState",
6455
6493
  value: function logAdState(event) {
6456
- var extra = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, adPlayer = arguments.length > 2 ? arguments[2] : void 0, inAdBreak = arguments.length > 3 ? arguments[3] : void 0, showAds = arguments.length > 4 ? arguments[4] : void 0;
6457
- var _ref;
6494
+ var extra = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
6458
6495
  if (!this.debug) {
6459
6496
  return;
6460
6497
  }
6498
+ var _this_callbacks_getAdState = this.callbacks.getAdState(), inAdBreak = _this_callbacks_getAdState.inAdBreak, showAds = _this_callbacks_getAdState.showAds, adPlaying = _this_callbacks_getAdState.adPlaying;
6461
6499
  console.log("[StormcloudVideoPlayer][AdState]", _object_spread({
6462
6500
  event: event,
6463
6501
  timestamp: /* @__PURE__ */ new Date().toISOString(),
6464
- showAds: showAds !== null && showAds !== void 0 ? showAds : false,
6465
- adPlaying: (_ref = adPlayer === null || adPlayer === void 0 ? void 0 : adPlayer.isAdPlaying()) !== null && _ref !== void 0 ? _ref : false,
6466
- inAdBreak: inAdBreak !== null && inAdBreak !== void 0 ? inAdBreak : false,
6502
+ showAds: showAds,
6503
+ adPlaying: adPlaying,
6504
+ inAdBreak: inAdBreak,
6467
6505
  activeAdRequestToken: this.activeAdRequestToken
6468
6506
  }, extra));
6469
6507
  }
@@ -8813,6 +8851,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8813
8851
  },
8814
8852
  onFailsafeTimeout: function onFailsafeTimeout() {
8815
8853
  return _this.adBreak.handleAdFailure();
8854
+ },
8855
+ getAdState: function getAdState() {
8856
+ return {
8857
+ inAdBreak: _this.adBreak.inAdBreak,
8858
+ showAds: _this.adBreak.showAds,
8859
+ adPlaying: _this.adPlayer.isAdPlaying()
8860
+ };
8816
8861
  }
8817
8862
  });
8818
8863
  this.placeholder = new PlaceholderLayer(this.video, !!this.config.debugAdTiming);