stormcloud-video-player 0.8.77 → 0.8.79

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 (39) hide show
  1. package/dist/stormcloud-vp.min.js +1 -1
  2. package/lib/Player.cjs +2 -0
  3. package/lib/Player.cjs.map +1 -1
  4. package/lib/Player.d.cts +1 -1
  5. package/lib/StormcloudPlayer.cjs +230 -7
  6. package/lib/StormcloudPlayer.cjs.map +1 -1
  7. package/lib/index.cjs +230 -7
  8. package/lib/index.cjs.map +1 -1
  9. package/lib/index.d.ts +4 -1
  10. package/lib/index.js +231 -7
  11. package/lib/index.js.map +1 -1
  12. package/lib/player/AdBreakOrchestrator.cjs +5 -1
  13. package/lib/player/AdBreakOrchestrator.cjs.map +1 -1
  14. package/lib/player/AdConfigManager.cjs +3 -1
  15. package/lib/player/AdConfigManager.cjs.map +1 -1
  16. package/lib/player/ContentHealthWatchdog.cjs +255 -0
  17. package/lib/player/ContentHealthWatchdog.cjs.map +1 -0
  18. package/lib/player/ContentHealthWatchdog.d.cts +40 -0
  19. package/lib/player/StormcloudVideoPlayer.cjs +230 -7
  20. package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
  21. package/lib/player/StormcloudVideoPlayer.d.cts +1 -0
  22. package/lib/players/HlsPlayer.cjs +230 -7
  23. package/lib/players/HlsPlayer.cjs.map +1 -1
  24. package/lib/players/index.cjs +230 -7
  25. package/lib/players/index.cjs.map +1 -1
  26. package/lib/props.cjs +2 -0
  27. package/lib/props.cjs.map +1 -1
  28. package/lib/sdk/hlsAdPlayer.cjs +16 -6
  29. package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
  30. package/lib/types.d.cts +2 -0
  31. package/lib/ui/StormcloudVideoPlayer.cjs +230 -7
  32. package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
  33. package/lib/utils/browserCompat.cjs +7 -0
  34. package/lib/utils/browserCompat.cjs.map +1 -1
  35. package/lib/utils/browserCompat.d.cts +2 -1
  36. package/lib/utils/tracking.cjs +5 -1
  37. package/lib/utils/tracking.cjs.map +1 -1
  38. package/lib/utils/tracking.d.cts +1 -1
  39. package/package.json +2 -2
package/lib/types.d.cts CHANGED
@@ -25,6 +25,7 @@ interface StormcloudVideoPlayerConfig {
25
25
  debugAdTiming?: boolean;
26
26
  adFailsafeTimeoutMs?: number;
27
27
  adMediaStartTimeoutMs?: number;
28
+ contentStallWatchdog?: boolean;
28
29
  adBreakCheckIntervalMs?: number;
29
30
  maxAdBreakExtensionMs?: number;
30
31
  minRemainingMsToStartAd?: number;
@@ -184,6 +185,7 @@ interface PlayerAnalyticsContext {
184
185
  contentNetwork?: string;
185
186
  contentChannel?: string;
186
187
  contentTitle?: string;
188
+ hlsUrl?: string;
187
189
  }
188
190
  interface HeartbeatData {
189
191
  browserId: string;
@@ -2253,6 +2253,9 @@ function requiresMediaPipelineResetAfterAds() {
2253
2253
  var browser = detectBrowser();
2254
2254
  return browser.name === "Samsung Tizen" && ((_browser_tizenVersion = browser.tizenVersion) !== null && _browser_tizenVersion !== void 0 ? _browser_tizenVersion : 0) >= 5;
2255
2255
  }
2256
+ function prefersProgressiveAdMedia() {
2257
+ return detectBrowser().isSmartTV;
2258
+ }
2256
2259
  function getBrowserConfigOverrides() {
2257
2260
  var browser = detectBrowser();
2258
2261
  var overrides = {};
@@ -3096,6 +3099,7 @@ function createHlsAdPlayer(contentVideo, options) {
3096
3099
  var probe = adVideoElement !== null && adVideoElement !== void 0 ? adVideoElement : document.createElement("video");
3097
3100
  var pageIsHttps = typeof location !== "undefined" && location.protocol === "https:";
3098
3101
  var target = getMediaTargetQuality();
3102
+ var deprioritizeHls = prefersProgressiveAdMedia();
3099
3103
  var accepted = [];
3100
3104
  mediaFiles.forEach(function(file, index) {
3101
3105
  var isHls = isHlsMediaFile(file);
@@ -3126,19 +3130,24 @@ function createHlsAdPlayer(contentVideo, options) {
3126
3130
  var bitrateDiff = Math.abs((file.bitrate || 5e3) * 1e3 - target.bitrate);
3127
3131
  score = resolutionDiff * 2 + bitrateDiff / 1e3;
3128
3132
  }
3133
+ var deprioritizedHls = deprioritizeHls && isHls;
3129
3134
  accepted.push({
3130
3135
  file: file,
3131
3136
  score: score,
3132
- insecure: insecure
3137
+ insecure: insecure,
3138
+ deprioritizedHls: deprioritizedHls
3133
3139
  });
3134
3140
  logFunnel("media_candidate", _object_spread_props(_object_spread({}, details), {
3135
3141
  reason: "accepted",
3136
- why: insecure ? "insecure_http_deprioritized" : "playable",
3142
+ why: insecure ? "insecure_http_deprioritized" : deprioritizedHls ? "hls_deprioritized_on_tv" : "playable",
3137
3143
  score: score
3138
3144
  }));
3139
3145
  });
3140
3146
  accepted.sort(function(a, b) {
3141
3147
  if (a.insecure !== b.insecure) return a.insecure ? 1 : -1;
3148
+ if (a.deprioritizedHls !== b.deprioritizedHls) {
3149
+ return a.deprioritizedHls ? 1 : -1;
3150
+ }
3142
3151
  return a.score - b.score;
3143
3152
  });
3144
3153
  return accepted.map(function(entry) {
@@ -4811,8 +4820,8 @@ function createHlsAdPlayer(contentVideo, options) {
4811
4820
  console.warn("[HlsAdPlayer] Error preparing ad video for new source:", error);
4812
4821
  }
4813
4822
  }
4814
- function recreateAdVideoElement() {
4815
- console.log("[HlsAdPlayer] Recreating ad video element (single-decoder platform)");
4823
+ function recreateAdVideoElement(reason) {
4824
+ console.log("[HlsAdPlayer] Recreating ad video element (".concat(reason, ")"));
4816
4825
  teardownAdEventListeners();
4817
4826
  prepareVideoElementForNewSource();
4818
4827
  if (adVideoElement) {
@@ -4856,8 +4865,9 @@ function createHlsAdPlayer(contentVideo, options) {
4856
4865
  }
4857
4866
  function resetVideoElementForNextSource() {
4858
4867
  clearStallWatchdog();
4859
- if (requiresMediaPipelineResetAfterAds()) {
4860
- recreateAdVideoElement();
4868
+ var previousSourceUsedHlsJs = adHls !== void 0;
4869
+ if (requiresMediaPipelineResetAfterAds() || previousSourceUsedHlsJs) {
4870
+ recreateAdVideoElement(previousSourceUsedHlsJs ? "after hls.js source" : "single-decoder platform");
4861
4871
  setupAdEventListeners();
4862
4872
  } else {
4863
4873
  prepareVideoElementForNewSource();
@@ -6073,14 +6083,16 @@ function ingestPlayerTracking(licenseKey, channel, body) {
6073
6083
  // src/utils/tracking.ts
6074
6084
  var cachedBrowserId = null;
6075
6085
  function buildAnalyticsContext(config) {
6076
- var _config_contentNetwork, _config_channelName, _config_programTitle;
6086
+ var _config_contentNetwork, _config_channelName, _config_programTitle, _config_src;
6077
6087
  var context = {};
6078
6088
  var contentNetwork = (_config_contentNetwork = config.contentNetwork) === null || _config_contentNetwork === void 0 ? void 0 : _config_contentNetwork.trim();
6079
6089
  var contentChannel = (_config_channelName = config.channelName) === null || _config_channelName === void 0 ? void 0 : _config_channelName.trim();
6080
6090
  var contentTitle = (_config_programTitle = config.programTitle) === null || _config_programTitle === void 0 ? void 0 : _config_programTitle.trim();
6091
+ var hlsUrl = (_config_src = config.src) === null || _config_src === void 0 ? void 0 : _config_src.trim();
6081
6092
  if (contentNetwork) context.contentNetwork = contentNetwork;
6082
6093
  if (contentChannel) context.contentChannel = contentChannel;
6083
6094
  if (contentTitle) context.contentTitle = contentTitle;
6095
+ if (hlsUrl) context.hlsUrl = hlsUrl;
6084
6096
  if (config.debugAdTiming) {
6085
6097
  context.debugAdTiming = true;
6086
6098
  }
@@ -6586,6 +6598,8 @@ function sendAdImpressionTracking(_0, _1) {
6586
6598
  content_channel: context.contentChannel
6587
6599
  } : {}, context.contentTitle ? {
6588
6600
  content_title: context.contentTitle
6601
+ } : {}, context.hlsUrl ? {
6602
+ hls_url: context.hlsUrl
6589
6603
  } : {})
6590
6604
  ]
6591
6605
  })
@@ -12339,6 +12353,181 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
12339
12353
  ]);
12340
12354
  return AdBreakOrchestrator;
12341
12355
  }();
12356
+ // src/player/ContentHealthWatchdog.ts
12357
+ var POLL_INTERVAL_MS = 2e3;
12358
+ var STALL_THRESHOLD_MS = 12e3;
12359
+ var POST_BREAK_GRACE_MS = 5e4;
12360
+ var MAX_BREAK_SUPPRESSION_MS = 10 * 60 * 1e3;
12361
+ var SELF_INFLICTED_PAUSE_WINDOW_MS = 5e3;
12362
+ var HEALTHY_PLAYBACK_SECONDS = 5;
12363
+ var MAX_NORMAL_ADVANCE_PER_TICK_S = 4;
12364
+ var LIGHT_STEP_COOLDOWN_MS = 1e4;
12365
+ var RELOAD_BASE_COOLDOWN_MS = 15e3;
12366
+ var RELOAD_MAX_COOLDOWN_MS = 12e4;
12367
+ var ContentHealthWatchdog = /*#__PURE__*/ function() {
12368
+ function ContentHealthWatchdog(host) {
12369
+ var _this = this;
12370
+ _class_call_check(this, ContentHealthWatchdog);
12371
+ this.host = host;
12372
+ this.armed = false;
12373
+ this.userPaused = false;
12374
+ this.wasInBreak = false;
12375
+ this.breakStartedAt = 0;
12376
+ this.stuckBreakLogged = false;
12377
+ this.graceUntil = 0;
12378
+ this.lastPosition = 0;
12379
+ this.lastProgressAt = 0;
12380
+ this.lastRealPlaybackAt = 0;
12381
+ this.healthySeconds = 0;
12382
+ this.step = 0;
12383
+ this.nextActionAt = 0;
12384
+ this.lastActionAt = 0;
12385
+ this.onPlaying = function() {
12386
+ if (_this.host.isAdPlaying()) return;
12387
+ _this.armed = true;
12388
+ _this.userPaused = false;
12389
+ };
12390
+ this.onPause = function() {
12391
+ if (_this.host.isBreakActive() || _this.host.isAdPlaying() || Date.now() - _this.lastActionAt < SELF_INFLICTED_PAUSE_WINDOW_MS) {
12392
+ return;
12393
+ }
12394
+ _this.userPaused = true;
12395
+ };
12396
+ this.onPlay = function() {
12397
+ _this.userPaused = false;
12398
+ };
12399
+ }
12400
+ _create_class(ContentHealthWatchdog, [
12401
+ {
12402
+ key: "start",
12403
+ value: function start() {
12404
+ var _this = this;
12405
+ if (this.intervalId !== void 0) return;
12406
+ var video = this.host.video;
12407
+ video.addEventListener("playing", this.onPlaying);
12408
+ video.addEventListener("pause", this.onPause);
12409
+ video.addEventListener("play", this.onPlay);
12410
+ this.resetProgress(Date.now());
12411
+ this.intervalId = window.setInterval(function() {
12412
+ return _this.tick();
12413
+ }, POLL_INTERVAL_MS);
12414
+ }
12415
+ },
12416
+ {
12417
+ key: "stop",
12418
+ value: function stop() {
12419
+ if (this.intervalId !== void 0) {
12420
+ clearInterval(this.intervalId);
12421
+ this.intervalId = void 0;
12422
+ }
12423
+ var video = this.host.video;
12424
+ video.removeEventListener("playing", this.onPlaying);
12425
+ video.removeEventListener("pause", this.onPause);
12426
+ video.removeEventListener("play", this.onPlay);
12427
+ this.armed = false;
12428
+ this.step = 0;
12429
+ }
12430
+ },
12431
+ {
12432
+ key: "resetProgress",
12433
+ value: function resetProgress(now) {
12434
+ this.lastPosition = this.host.video.currentTime;
12435
+ this.lastProgressAt = now;
12436
+ }
12437
+ },
12438
+ {
12439
+ key: "tick",
12440
+ value: function tick() {
12441
+ var now = Date.now();
12442
+ var video = this.host.video;
12443
+ var hidden = typeof document !== "undefined" && document.visibilityState === "hidden";
12444
+ if (!this.armed || this.userPaused || hidden || video.ended || !this.host.isLiveStream() || !this.host.hasHlsInstance()) {
12445
+ this.resetProgress(now);
12446
+ return;
12447
+ }
12448
+ var breakActive = this.host.isBreakActive() || this.host.isAdPlaying();
12449
+ if (breakActive && !this.wasInBreak) {
12450
+ this.wasInBreak = true;
12451
+ this.breakStartedAt = now;
12452
+ this.stuckBreakLogged = false;
12453
+ }
12454
+ if (breakActive && now - this.breakStartedAt < MAX_BREAK_SUPPRESSION_MS) {
12455
+ this.resetProgress(now);
12456
+ return;
12457
+ }
12458
+ if (breakActive && !this.stuckBreakLogged) {
12459
+ this.stuckBreakLogged = true;
12460
+ console.warn("[ContentWatchdog] Ad break state active for over ".concat(MAX_BREAK_SUPPRESSION_MS / 6e4, " min — monitoring content anyway"));
12461
+ }
12462
+ if (!breakActive && this.wasInBreak) {
12463
+ this.wasInBreak = false;
12464
+ this.graceUntil = now + POST_BREAK_GRACE_MS;
12465
+ this.resetProgress(now);
12466
+ return;
12467
+ }
12468
+ var currentTime = video.currentTime;
12469
+ var delta = currentTime - this.lastPosition;
12470
+ this.lastPosition = currentTime;
12471
+ if (delta > 0.25 && delta <= MAX_NORMAL_ADVANCE_PER_TICK_S && !video.paused) {
12472
+ this.lastProgressAt = now;
12473
+ this.lastRealPlaybackAt = now;
12474
+ this.healthySeconds += delta;
12475
+ if (this.step > 0 && this.healthySeconds >= HEALTHY_PLAYBACK_SECONDS) {
12476
+ console.log("[ContentWatchdog] Content playback recovered after ".concat(this.step, " recovery step(s)"));
12477
+ this.step = 0;
12478
+ this.nextActionAt = 0;
12479
+ }
12480
+ return;
12481
+ }
12482
+ if (now < this.graceUntil) {
12483
+ this.lastProgressAt = now;
12484
+ return;
12485
+ }
12486
+ if (now - this.lastProgressAt < STALL_THRESHOLD_MS || now < this.nextActionAt) {
12487
+ return;
12488
+ }
12489
+ this.recover(now);
12490
+ }
12491
+ },
12492
+ {
12493
+ key: "recover",
12494
+ value: function recover(now) {
12495
+ var video = this.host.video;
12496
+ var state = "t=".concat(video.currentTime.toFixed(2), " paused=").concat(video.paused, " readyState=").concat(video.readyState, " networkState=").concat(video.networkState, " error=").concat(video.error ? video.error.code : "none");
12497
+ var stalledForS = ((now - (this.lastRealPlaybackAt || this.lastProgressAt)) / 1e3).toFixed(0);
12498
+ var fullReloadOnly = this.host.requiresMediaPipelineResetAfterAds();
12499
+ var action = fullReloadOnly || this.step >= 2 ? "reload" : this.step === 0 ? "recover_media_error" : "restart_load";
12500
+ console.warn("[ContentWatchdog] Content stalled for ".concat(stalledForS, "s — ").concat(action, " (step ").concat(this.step + 1, ") — ").concat(state));
12501
+ this.lastActionAt = now;
12502
+ this.healthySeconds = 0;
12503
+ if (action === "recover_media_error") {
12504
+ this.host.recoverMediaError();
12505
+ this.nextActionAt = now + LIGHT_STEP_COOLDOWN_MS;
12506
+ } else if (action === "restart_load") {
12507
+ var liveSyncPos = this.host.getLiveSyncPosition();
12508
+ var position = liveSyncPos != null && liveSyncPos > video.currentTime ? liveSyncPos : video.currentTime;
12509
+ if (position !== video.currentTime) {
12510
+ video.currentTime = position;
12511
+ }
12512
+ this.host.restartHlsLoad(position);
12513
+ this.nextActionAt = now + LIGHT_STEP_COOLDOWN_MS;
12514
+ } else {
12515
+ var reloadIndex = fullReloadOnly ? this.step : this.step - 2;
12516
+ var cooldown = Math.min(RELOAD_BASE_COOLDOWN_MS * Math.pow(2, reloadIndex), RELOAD_MAX_COOLDOWN_MS);
12517
+ this.host.reloadLiveStream();
12518
+ this.nextActionAt = now + cooldown;
12519
+ }
12520
+ this.step++;
12521
+ this.resetProgress(now);
12522
+ if (video.paused) {
12523
+ var _video_play;
12524
+ (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
12525
+ }
12526
+ }
12527
+ }
12528
+ ]);
12529
+ return ContentHealthWatchdog;
12530
+ }();
12342
12531
  // src/player/StormcloudVideoPlayer.ts
12343
12532
  var StormcloudVideoPlayer = /*#__PURE__*/ function() {
12344
12533
  function StormcloudVideoPlayer(config) {
@@ -12469,6 +12658,36 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
12469
12658
  return _this.palNonce.sendAdTouch(event);
12470
12659
  }
12471
12660
  }, this.timing, this.adConfig, this.cueManager, this.placeholder);
12661
+ this.contentWatchdog = new ContentHealthWatchdog({
12662
+ video: this.video,
12663
+ isLiveStream: function isLiveStream() {
12664
+ return _this.hlsEngine.isLiveStream;
12665
+ },
12666
+ hasHlsInstance: function hasHlsInstance() {
12667
+ return !!_this.hlsEngine.hls;
12668
+ },
12669
+ isBreakActive: function isBreakActive() {
12670
+ return _this.adBreak.inAdBreak || _this.adBreak.isBreakActive();
12671
+ },
12672
+ isAdPlaying: function isAdPlaying() {
12673
+ return _this.adPlayer.isAdPlaying();
12674
+ },
12675
+ requiresMediaPipelineResetAfterAds: function requiresMediaPipelineResetAfterAds1() {
12676
+ return requiresMediaPipelineResetAfterAds();
12677
+ },
12678
+ getLiveSyncPosition: function getLiveSyncPosition() {
12679
+ return _this.hlsEngine.getLiveSyncPosition();
12680
+ },
12681
+ recoverMediaError: function recoverMediaError() {
12682
+ return _this.hlsEngine.recoverMediaError();
12683
+ },
12684
+ restartHlsLoad: function restartHlsLoad(position) {
12685
+ return _this.hlsEngine.restartLoadAt(position);
12686
+ },
12687
+ reloadLiveStream: function reloadLiveStream() {
12688
+ return _this.hlsEngine.reloadLiveStream();
12689
+ }
12690
+ });
12472
12691
  }
12473
12692
  _create_class(StormcloudVideoPlayer, [
12474
12693
  {
@@ -12789,6 +13008,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
12789
13008
  }
12790
13009
  };
12791
13010
  this.video.addEventListener("emptied", this.emptiedHandler);
13011
+ if (this.config.contentStallWatchdog !== false) {
13012
+ this.contentWatchdog.start();
13013
+ }
12792
13014
  }
12793
13015
  },
12794
13016
  {
@@ -13273,6 +13495,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
13273
13495
  key: "destroy",
13274
13496
  value: function destroy() {
13275
13497
  var _this_adPlayer;
13498
+ this.contentWatchdog.stop();
13276
13499
  this.adBreak.cancelScheduledRequest();
13277
13500
  this.timing.destroy();
13278
13501
  this.adBreak.clearPendingAdBreak();