stormcloud-video-player 0.8.34 → 0.8.35

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.
Files changed (37) hide show
  1. package/dist/stormcloud-vp.min.js +1 -1
  2. package/lib/index.cjs +105 -16
  3. package/lib/index.cjs.map +1 -1
  4. package/lib/index.d.cts +2 -0
  5. package/lib/index.d.ts +2 -0
  6. package/lib/index.js +105 -16
  7. package/lib/index.js.map +1 -1
  8. package/lib/player/AdBreakOrchestrator.cjs +36 -16
  9. package/lib/player/AdBreakOrchestrator.cjs.map +1 -1
  10. package/lib/player/AdBreakOrchestrator.d.cts +3 -7
  11. package/lib/player/AdConfigManager.d.cts +1 -1
  12. package/lib/player/AdTimingService.d.cts +1 -1
  13. package/lib/player/HlsEngine.d.cts +1 -1
  14. package/lib/player/PlayerControls.d.cts +1 -1
  15. package/lib/player/Scte35CueManager.d.cts +1 -1
  16. package/lib/player/Scte35Parser.d.cts +1 -1
  17. package/lib/player/StormcloudVideoPlayer.cjs +105 -16
  18. package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
  19. package/lib/player/StormcloudVideoPlayer.d.cts +1 -1
  20. package/lib/player/playerTypes.d.cts +1 -1
  21. package/lib/players/HlsPlayer.cjs +105 -16
  22. package/lib/players/HlsPlayer.cjs.map +1 -1
  23. package/lib/players/HlsPlayer.d.cts +1 -1
  24. package/lib/players/index.cjs +105 -16
  25. package/lib/players/index.cjs.map +1 -1
  26. package/lib/sdk/hlsAdPlayer.cjs +62 -0
  27. package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
  28. package/lib/sdk/hlsAdPlayer.d.cts +1 -1
  29. package/lib/{types-CSHvCbhZ.d.cts → types-cTqIKw_D.d.cts} +1 -0
  30. package/lib/ui/StormcloudVideoPlayer.cjs +105 -16
  31. package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
  32. package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
  33. package/lib/utils/browserCompat.cjs +1 -0
  34. package/lib/utils/browserCompat.cjs.map +1 -1
  35. package/lib/utils/browserCompat.d.cts +1 -0
  36. package/lib/utils/tracking.d.cts +1 -1
  37. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { Component } from 'react';
2
- import { a as StormcloudVideoPlayerConfig } from '../types-CSHvCbhZ.cjs';
2
+ import { a as StormcloudVideoPlayerConfig } from '../types-cTqIKw_D.cjs';
3
3
 
4
4
  interface HlsPlayerProps extends StormcloudVideoPlayerConfig {
5
5
  onMount?: (player: any) => void;
@@ -455,6 +455,11 @@ function createHlsAdPlayer(contentVideo, options) {
455
455
  var preloadingAds = /* @__PURE__ */ new Map();
456
456
  var destroyed = false;
457
457
  var pendingTimeouts = [];
458
+ var STALL_TIMEOUT_MS = 4e3;
459
+ var STALL_CHECK_INTERVAL_MS = 1e3;
460
+ var stallWatchdogId;
461
+ var lastAdProgressTime = 0;
462
+ var lastAdProgressPosition = 0;
458
463
  var trackingFired = {
459
464
  impression: false,
460
465
  start: false,
@@ -1087,6 +1092,7 @@ function createHlsAdPlayer(contentVideo, options) {
1087
1092
  if (!adVideoElement || !currentAd) return;
1088
1093
  adVideoElement.addEventListener("timeupdate", function() {
1089
1094
  if (!currentAd || !adVideoElement) return;
1095
+ noteAdProgress();
1090
1096
  var progress = adVideoElement.currentTime / currentAd.duration;
1091
1097
  if (progress >= 0.25 && !trackingFired.firstQuartile) {
1092
1098
  trackingFired.firstQuartile = true;
@@ -1102,6 +1108,7 @@ function createHlsAdPlayer(contentVideo, options) {
1102
1108
  }
1103
1109
  });
1104
1110
  adVideoElement.addEventListener("playing", function() {
1111
+ startStallWatchdog();
1105
1112
  if (!currentAd || trackingFired.start) return;
1106
1113
  trackingFired.start = true;
1107
1114
  fireTrackingPixels(currentAd.trackingUrls.start);
@@ -1242,8 +1249,52 @@ function createHlsAdPlayer(contentVideo, options) {
1242
1249
  return false;
1243
1250
  }
1244
1251
  }
1252
+ function clearStallWatchdog() {
1253
+ if (stallWatchdogId != null) {
1254
+ clearInterval(stallWatchdogId);
1255
+ stallWatchdogId = void 0;
1256
+ }
1257
+ }
1258
+ function noteAdProgress() {
1259
+ lastAdProgressTime = Date.now();
1260
+ if (adVideoElement) {
1261
+ lastAdProgressPosition = adVideoElement.currentTime;
1262
+ }
1263
+ }
1264
+ function handleAdStall() {
1265
+ console.warn("[HlsAdPlayer] Ad playback stalled (no progress) - recovering to avoid a blank frame");
1266
+ clearStallWatchdog();
1267
+ if (currentAd) {
1268
+ fireTrackingPixels(currentAd.trackingUrls.error);
1269
+ }
1270
+ if (podIndex < podAds.length - 1 && advanceToNextPodAd()) {
1271
+ return;
1272
+ }
1273
+ handleAdError();
1274
+ }
1275
+ function startStallWatchdog() {
1276
+ clearStallWatchdog();
1277
+ noteAdProgress();
1278
+ stallWatchdogId = window.setInterval(function() {
1279
+ if (!adPlaying || !adVideoElement) {
1280
+ return;
1281
+ }
1282
+ if (adVideoElement.currentTime > lastAdProgressPosition + 0.05) {
1283
+ noteAdProgress();
1284
+ return;
1285
+ }
1286
+ if (adVideoElement.paused) {
1287
+ noteAdProgress();
1288
+ return;
1289
+ }
1290
+ if (Date.now() - lastAdProgressTime >= STALL_TIMEOUT_MS) {
1291
+ handleAdStall();
1292
+ }
1293
+ }, STALL_CHECK_INTERVAL_MS);
1294
+ }
1245
1295
  function handleAdComplete() {
1246
1296
  console.log("[HlsAdPlayer] Handling ad completion");
1297
+ clearStallWatchdog();
1247
1298
  adPlaying = false;
1248
1299
  setAdPlayingFlag(false);
1249
1300
  contentVideo.muted = true;
@@ -1251,6 +1302,10 @@ function createHlsAdPlayer(contentVideo, options) {
1251
1302
  adContainerEl.style.display = "none";
1252
1303
  adContainerEl.style.pointerEvents = "none";
1253
1304
  }
1305
+ if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
1306
+ contentVideo.style.visibility = "visible";
1307
+ contentVideo.style.opacity = "1";
1308
+ }
1254
1309
  if (options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds) {
1255
1310
  if (contentVideo.paused) {
1256
1311
  console.log("[HlsAdPlayer] Content video paused in live mode, resuming playback");
@@ -1263,6 +1318,7 @@ function createHlsAdPlayer(contentVideo, options) {
1263
1318
  }
1264
1319
  function handleAdError() {
1265
1320
  console.log("[HlsAdPlayer] Handling ad error");
1321
+ clearStallWatchdog();
1266
1322
  adPlaying = false;
1267
1323
  setAdPlayingFlag(false);
1268
1324
  contentVideo.muted = true;
@@ -1270,6 +1326,10 @@ function createHlsAdPlayer(contentVideo, options) {
1270
1326
  adContainerEl.style.display = "none";
1271
1327
  adContainerEl.style.pointerEvents = "none";
1272
1328
  }
1329
+ if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
1330
+ contentVideo.style.visibility = "visible";
1331
+ contentVideo.style.opacity = "1";
1332
+ }
1273
1333
  emit("ad_error");
1274
1334
  }
1275
1335
  return {
@@ -1467,6 +1527,7 @@ function createHlsAdPlayer(contentVideo, options) {
1467
1527
  var previousMutedState;
1468
1528
  return _ts_generator(this, function(_state) {
1469
1529
  console.log("[HlsAdPlayer] Stopping ad");
1530
+ clearStallWatchdog();
1470
1531
  adPlaying = false;
1471
1532
  setAdPlayingFlag(false);
1472
1533
  previousMutedState = contentVideo.muted;
@@ -1505,6 +1566,7 @@ function createHlsAdPlayer(contentVideo, options) {
1505
1566
  destroy: function destroy() {
1506
1567
  console.log("[HlsAdPlayer] Destroying");
1507
1568
  destroyed = true;
1569
+ clearStallWatchdog();
1508
1570
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1509
1571
  try {
1510
1572
  for(var _iterator = pendingTimeouts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -3896,6 +3958,7 @@ function getBrowserConfigOverrides() {
3896
3958
  var overrides = {};
3897
3959
  if (browser.isSmartTV) {
3898
3960
  overrides.allowNativeHls = true;
3961
+ overrides.pauseContentDuringAds = true;
3899
3962
  }
3900
3963
  return overrides;
3901
3964
  }
@@ -6778,12 +6841,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
6778
6841
  // ───────────────────────────────────────────────────────────────
6779
6842
  // IMA event listeners
6780
6843
  // ───────────────────────────────────────────────────────────────
6781
- /**
6782
- * Produces the next pod ad-request URL for the current break. Every request
6783
- * (initial and continuous-fetch top-up) carries pod macros (pmad/pmnd/pmxd,
6784
- * no ppos); pmxd tracks the remaining break time so top-up pods only ask for
6785
- * what still fits.
6786
- */ key: "nextAdRequestUrl",
6844
+ key: "nextAdRequestUrl",
6787
6845
  value: function nextAdRequestUrl(baseVastUrl) {
6788
6846
  var remaining = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
6789
6847
  var breakDurationMs = remaining > 0 ? remaining : void 0;
@@ -7912,7 +7970,9 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
7912
7970
  if (Math.abs(this.host.video.volume - restoredVolume) > 0.01) {
7913
7971
  this.host.video.volume = restoredVolume;
7914
7972
  }
7915
- if (this.host.shouldContinueLiveStreamDuringAds()) {
7973
+ this.host.video.style.visibility = "visible";
7974
+ this.host.video.style.opacity = "1";
7975
+ if (this.host.isLiveStream()) {
7916
7976
  var liveSyncPos = this.host.getLiveSyncPosition();
7917
7977
  if (liveSyncPos != null && liveSyncPos > this.host.video.currentTime) {
7918
7978
  if (this.debug) {
@@ -7920,16 +7980,39 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
7920
7980
  }
7921
7981
  this.host.video.currentTime = liveSyncPos;
7922
7982
  }
7923
- if (this.host.video.paused) {
7924
- var _this_host_video_play;
7925
- if (this.debug) console.log("[StormcloudVideoPlayer] Content video paused in live mode after ads, resuming playback");
7926
- (_this_host_video_play = this.host.video.play()) === null || _this_host_video_play === void 0 ? void 0 : _this_host_video_play.catch(function() {});
7927
- } else {
7928
- if (this.debug) console.log("[StormcloudVideoPlayer] Content video already playing in live mode after ads");
7983
+ }
7984
+ this.resumeContentPlayback();
7985
+ }
7986
+ },
7987
+ {
7988
+ key: "resumeContentPlayback",
7989
+ value: function resumeContentPlayback() {
7990
+ var _this = this;
7991
+ var attempt = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
7992
+ var maxAttempts = 3;
7993
+ if (!this.host.video.paused) {
7994
+ if (this.debug && attempt === 0) {
7995
+ console.log("[StormcloudVideoPlayer] Content video already playing after ads");
7929
7996
  }
7930
- } else if (this.host.video.paused) {
7931
- var _this_host_video_play1;
7932
- (_this_host_video_play1 = this.host.video.play()) === null || _this_host_video_play1 === void 0 ? void 0 : _this_host_video_play1.catch(function() {});
7997
+ return;
7998
+ }
7999
+ if (this.debug) {
8000
+ console.log("[StormcloudVideoPlayer] Resuming content playback after ads (attempt ".concat(attempt + 1, "/").concat(maxAttempts, ")"));
8001
+ }
8002
+ var playResult = this.host.video.play();
8003
+ if (playResult && typeof playResult.catch === "function") {
8004
+ playResult.catch(function(error) {
8005
+ if (attempt + 1 >= maxAttempts) {
8006
+ if (_this.debug) {
8007
+ console.warn("[StormcloudVideoPlayer] Failed to resume content playback after ads:", error);
8008
+ }
8009
+ return;
8010
+ }
8011
+ var backoffMs = 250 * (attempt + 1);
8012
+ window.setTimeout(function() {
8013
+ _this.resumeContentPlayback(attempt + 1);
8014
+ }, backoffMs);
8015
+ });
7933
8016
  }
7934
8017
  }
7935
8018
  },
@@ -8043,6 +8126,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8043
8126
  shouldContinueLiveStreamDuringAds: function shouldContinueLiveStreamDuringAds() {
8044
8127
  return _this.shouldContinueLiveStreamDuringAds();
8045
8128
  },
8129
+ isLiveStream: function isLiveStream() {
8130
+ return _this.hlsEngine.isLiveStream;
8131
+ },
8046
8132
  getLiveSyncPosition: function getLiveSyncPosition() {
8047
8133
  return _this.hlsEngine.getLiveSyncPosition();
8048
8134
  },
@@ -8265,6 +8351,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8265
8351
  {
8266
8352
  key: "shouldContinueLiveStreamDuringAds",
8267
8353
  value: function shouldContinueLiveStreamDuringAds() {
8354
+ if (this.config.pauseContentDuringAds) {
8355
+ return false;
8356
+ }
8268
8357
  if (this.hlsEngine.isLiveStream) {
8269
8358
  return true;
8270
8359
  }