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.js CHANGED
@@ -381,6 +381,7 @@ function createHlsAdPlayer(contentVideo, options) {
381
381
  var mainHlsInstance = options === null || options === void 0 ? void 0 : options.mainHlsInstance;
382
382
  var AD_CONTAINER_PROP = "__stormcloudAdContainer";
383
383
  var AD_VIDEO_PROP = "__stormcloudAdVideo";
384
+ var FRAME_COUNTER_RELIABLE_PROP = "__stormcloudFrameCounterReliable";
384
385
  var adVideoElement = (_contentVideo_AD_VIDEO_PROP = contentVideo[AD_VIDEO_PROP]) !== null && _contentVideo_AD_VIDEO_PROP !== void 0 ? _contentVideo_AD_VIDEO_PROP : void 0;
385
386
  var adHls;
386
387
  var adContainerEl = (_contentVideo_AD_CONTAINER_PROP = contentVideo[AD_CONTAINER_PROP]) !== null && _contentVideo_AD_CONTAINER_PROP !== void 0 ? _contentVideo_AD_CONTAINER_PROP : void 0;
@@ -400,6 +401,7 @@ function createHlsAdPlayer(contentVideo, options) {
400
401
  var lastAdProgressTime = 0;
401
402
  var lastAdProgressPosition = 0;
402
403
  var sawDecodedVideoFrame = false;
404
+ var videoFrameCallbackHandle;
403
405
  var trackingFired = {
404
406
  impression: false,
405
407
  start: false,
@@ -1286,6 +1288,7 @@ function createHlsAdPlayer(contentVideo, options) {
1286
1288
  clearInterval(stallWatchdogId);
1287
1289
  stallWatchdogId = void 0;
1288
1290
  }
1291
+ cancelVideoFrameProbe();
1289
1292
  }
1290
1293
  function noteAdProgress() {
1291
1294
  lastAdProgressTime = Date.now();
@@ -1321,6 +1324,39 @@ function createHlsAdPlayer(contentVideo, options) {
1321
1324
  }
1322
1325
  return void 0;
1323
1326
  }
1327
+ function isFrameCounterReliable() {
1328
+ return contentVideo[FRAME_COUNTER_RELIABLE_PROP] === true;
1329
+ }
1330
+ function markFrameCounterReliable() {
1331
+ contentVideo[FRAME_COUNTER_RELIABLE_PROP] = true;
1332
+ }
1333
+ function cancelVideoFrameProbe() {
1334
+ if (videoFrameCallbackHandle != null && adVideoElement && typeof adVideoElement.cancelVideoFrameCallback === "function") {
1335
+ try {
1336
+ adVideoElement.cancelVideoFrameCallback(videoFrameCallbackHandle);
1337
+ } catch (error) {
1338
+ console.warn("[HlsAdPlayer] Error cancelling video frame callback:", error);
1339
+ }
1340
+ }
1341
+ videoFrameCallbackHandle = void 0;
1342
+ }
1343
+ function startVideoFrameProbe() {
1344
+ cancelVideoFrameProbe();
1345
+ if (!adVideoElement) return;
1346
+ var rvfc = adVideoElement.requestVideoFrameCallback;
1347
+ if (typeof rvfc !== "function") return;
1348
+ var onPresentedFrame = function onPresentedFrame() {
1349
+ videoFrameCallbackHandle = void 0;
1350
+ if (!adPlaying) return;
1351
+ sawDecodedVideoFrame = true;
1352
+ };
1353
+ try {
1354
+ videoFrameCallbackHandle = rvfc.call(adVideoElement, onPresentedFrame);
1355
+ } catch (error) {
1356
+ console.warn("[HlsAdPlayer] Error requesting video frame callback:", error);
1357
+ videoFrameCallbackHandle = void 0;
1358
+ }
1359
+ }
1324
1360
  function handleVideoDecodeFailure() {
1325
1361
  console.warn("[HlsAdPlayer] Ad audio is advancing but no video frames decoded (black screen) - skipping this creative");
1326
1362
  clearStallWatchdog();
@@ -1336,6 +1372,7 @@ function createHlsAdPlayer(contentVideo, options) {
1336
1372
  clearStallWatchdog();
1337
1373
  noteAdProgress();
1338
1374
  sawDecodedVideoFrame = false;
1375
+ startVideoFrameProbe();
1339
1376
  stallWatchdogId = window.setInterval(function() {
1340
1377
  if (!adPlaying || !adVideoElement) {
1341
1378
  return;
@@ -1344,7 +1381,8 @@ function createHlsAdPlayer(contentVideo, options) {
1344
1381
  var decodedFrames = getDecodedVideoFrameCount(adVideoElement);
1345
1382
  if (decodedFrames !== void 0 && decodedFrames > 0) {
1346
1383
  sawDecodedVideoFrame = true;
1347
- } else if (decodedFrames === 0 && adVideoElement.currentTime >= BLACKFRAME_MIN_PLAYBACK_S) {
1384
+ markFrameCounterReliable();
1385
+ } else if (decodedFrames === 0 && adVideoElement.currentTime >= BLACKFRAME_MIN_PLAYBACK_S && isFrameCounterReliable()) {
1348
1386
  handleVideoDecodeFailure();
1349
1387
  return;
1350
1388
  }
@@ -6239,17 +6277,17 @@ var AdTimingService = /*#__PURE__*/ function() {
6239
6277
  {
6240
6278
  key: "logAdState",
6241
6279
  value: function logAdState(event) {
6242
- 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;
6243
- var _ref;
6280
+ var extra = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
6244
6281
  if (!this.debug) {
6245
6282
  return;
6246
6283
  }
6284
+ var _this_callbacks_getAdState = this.callbacks.getAdState(), inAdBreak = _this_callbacks_getAdState.inAdBreak, showAds = _this_callbacks_getAdState.showAds, adPlaying = _this_callbacks_getAdState.adPlaying;
6247
6285
  console.log("[StormcloudVideoPlayer][AdState]", _object_spread({
6248
6286
  event: event,
6249
6287
  timestamp: /* @__PURE__ */ new Date().toISOString(),
6250
- showAds: showAds !== null && showAds !== void 0 ? showAds : false,
6251
- adPlaying: (_ref = adPlayer === null || adPlayer === void 0 ? void 0 : adPlayer.isAdPlaying()) !== null && _ref !== void 0 ? _ref : false,
6252
- inAdBreak: inAdBreak !== null && inAdBreak !== void 0 ? inAdBreak : false,
6288
+ showAds: showAds,
6289
+ adPlaying: adPlaying,
6290
+ inAdBreak: inAdBreak,
6253
6291
  activeAdRequestToken: this.activeAdRequestToken
6254
6292
  }, extra));
6255
6293
  }
@@ -8603,6 +8641,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8603
8641
  },
8604
8642
  onFailsafeTimeout: function onFailsafeTimeout() {
8605
8643
  return _this.adBreak.handleAdFailure();
8644
+ },
8645
+ getAdState: function getAdState() {
8646
+ return {
8647
+ inAdBreak: _this.adBreak.inAdBreak,
8648
+ showAds: _this.adBreak.showAds,
8649
+ adPlaying: _this.adPlayer.isAdPlaying()
8650
+ };
8606
8651
  }
8607
8652
  });
8608
8653
  this.placeholder = new PlaceholderLayer(this.video, !!this.config.debugAdTiming);