stormcloud-video-player 0.8.52 → 0.8.54

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.
@@ -21,6 +21,8 @@ declare class HlsEngine {
21
21
  private bufferedSegmentsCount;
22
22
  private shouldAutoplayAfterBuffering;
23
23
  private hasInitialBufferCompleted;
24
+ private detectedLowLatencyStream;
25
+ private latencyProfileApplied;
24
26
  private readonly config;
25
27
  private readonly video;
26
28
  private readonly cueManager;
@@ -31,6 +33,9 @@ declare class HlsEngine {
31
33
  shouldUseNativeHls(getStreamType: () => "hls" | "other"): boolean;
32
34
  setupNativeHls(): Promise<void>;
33
35
  setupHls(): void;
36
+ isLowLatencyStream(): boolean | undefined;
37
+ private applyStreamLatencyProfile;
38
+ private isLowLatencyManifest;
34
39
  private onId3Tag;
35
40
  private processFragmentScte35Payload;
36
41
  getLiveSyncPosition(): number | undefined;
@@ -1035,7 +1035,7 @@ function createHlsAdPlayer(contentVideo, options) {
1035
1035
  }
1036
1036
  function fetchAndParsePod(vastTagUrl) {
1037
1037
  return _async_to_generator(function() {
1038
- var vastXml, parser, xmlDoc, adElements, ads, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, adElement, parsed, resolved, error, err;
1038
+ var vastXml, trimmedXml, parser, xmlDoc, adElements, ads, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, adElement, parsed, resolved, error, err;
1039
1039
  return _ts_generator(this, function(_state) {
1040
1040
  switch(_state.label){
1041
1041
  case 0:
@@ -1045,11 +1045,19 @@ function createHlsAdPlayer(contentVideo, options) {
1045
1045
  ];
1046
1046
  case 1:
1047
1047
  vastXml = _state.sent();
1048
- console.log("[HlsAdPlayer] Pod VAST XML received");
1048
+ console.log("[HlsAdPlayer] Pod VAST XML received (length=".concat(vastXml.length, ")"));
1049
+ trimmedXml = vastXml.trim();
1050
+ if (trimmedXml.length === 0) {
1051
+ console.warn("[HlsAdPlayer] Pod VAST response body is empty (no fill)");
1052
+ return [
1053
+ 2,
1054
+ []
1055
+ ];
1056
+ }
1049
1057
  parser = new DOMParser();
1050
1058
  xmlDoc = parser.parseFromString(vastXml, "text/xml");
1051
1059
  if (xmlDoc.querySelector("parsererror")) {
1052
- console.error("[HlsAdPlayer] Pod VAST XML parsing error (malformed)");
1060
+ console.error("[HlsAdPlayer] Pod VAST XML parsing error (malformed). Content (first 2000 chars):", vastXml.substring(0, 2e3));
1053
1061
  return [
1054
1062
  2,
1055
1063
  []
@@ -1057,7 +1065,7 @@ function createHlsAdPlayer(contentVideo, options) {
1057
1065
  }
1058
1066
  adElements = Array.from(xmlDoc.querySelectorAll("Ad"));
1059
1067
  if (adElements.length === 0) {
1060
- console.warn("[HlsAdPlayer] No <Ad> elements found in pod VAST response");
1068
+ console.warn("[HlsAdPlayer] No <Ad> elements found in pod VAST response (no fill). Content (first 2000 chars):", vastXml.substring(0, 2e3));
1061
1069
  return [
1062
1070
  2,
1063
1071
  []
@@ -6432,6 +6440,7 @@ var HlsEngine = /*#__PURE__*/ function() {
6432
6440
  this.bufferedSegmentsCount = 0;
6433
6441
  this.shouldAutoplayAfterBuffering = false;
6434
6442
  this.hasInitialBufferCompleted = false;
6443
+ this.latencyProfileApplied = false;
6435
6444
  this.config = config;
6436
6445
  this.video = video;
6437
6446
  this.cueManager = cueManager;
@@ -6500,24 +6509,21 @@ var HlsEngine = /*#__PURE__*/ function() {
6500
6509
  key: "setupHls",
6501
6510
  value: function setupHls() {
6502
6511
  var _this = this;
6503
- this.hls = new import_hls2.default(_object_spread_props(_object_spread({
6512
+ this.hls = new import_hls2.default({
6504
6513
  enableWorker: true,
6505
6514
  backBufferLength: 30,
6506
6515
  liveDurationInfinity: true,
6507
6516
  lowLatencyMode: !!this.config.lowLatencyMode,
6508
- maxLiveSyncPlaybackRate: this.config.lowLatencyMode ? 1.5 : 1
6509
- }, this.config.lowLatencyMode ? {
6510
- liveSyncDuration: 2
6511
- } : {}), {
6517
+ maxLiveSyncPlaybackRate: 1.1,
6512
6518
  maxBufferLength: 30,
6513
6519
  maxMaxBufferLength: 600,
6514
6520
  maxBufferSize: 60 * 1e3 * 1e3,
6515
- maxBufferHole: 0.5,
6521
+ maxBufferHole: 1,
6516
6522
  highBufferWatchdogPeriod: 2,
6517
- nudgeOffset: 0.1,
6518
- nudgeMaxRetry: 3,
6523
+ nudgeOffset: 0.2,
6524
+ nudgeMaxRetry: 5,
6519
6525
  startPosition: -1
6520
- }));
6526
+ });
6521
6527
  this.hls.on(import_hls2.default.Events.MEDIA_ATTACHED, function() {
6522
6528
  var _this_hls;
6523
6529
  (_this_hls = _this.hls) === null || _this_hls === void 0 ? void 0 : _this_hls.loadSource(_this.config.src);
@@ -6541,6 +6547,8 @@ var HlsEngine = /*#__PURE__*/ function() {
6541
6547
  this.bufferedSegmentsCount = 0;
6542
6548
  this.hasInitialBufferCompleted = false;
6543
6549
  this.shouldAutoplayAfterBuffering = !!this.config.autoplay;
6550
+ this.latencyProfileApplied = false;
6551
+ this.detectedLowLatencyStream = void 0;
6544
6552
  minSegments = (_this_config_minSegmentsBeforePlay = this.config.minSegmentsBeforePlay) !== null && _this_config_minSegmentsBeforePlay !== void 0 ? _this_config_minSegmentsBeforePlay : 2;
6545
6553
  if (this.debug) {
6546
6554
  console.log("[StormcloudVideoPlayer] Waiting for", minSegments, "segments to buffer before playback");
@@ -6571,6 +6579,7 @@ var HlsEngine = /*#__PURE__*/ function() {
6571
6579
  }).call(_this);
6572
6580
  });
6573
6581
  this.hls.on(import_hls2.default.Events.LEVEL_LOADED, function(_evt, data) {
6582
+ _this.applyStreamLatencyProfile(data === null || data === void 0 ? void 0 : data.details);
6574
6583
  if (_this.callbacks.isInAdBreak() || _this.callbacks.hasPendingAdBreak()) {
6575
6584
  return;
6576
6585
  }
@@ -6844,6 +6853,70 @@ var HlsEngine = /*#__PURE__*/ function() {
6844
6853
  this.hls.attachMedia(this.video);
6845
6854
  }
6846
6855
  },
6856
+ {
6857
+ key: "isLowLatencyStream",
6858
+ value: function isLowLatencyStream() {
6859
+ return this.detectedLowLatencyStream;
6860
+ }
6861
+ },
6862
+ {
6863
+ key: "applyStreamLatencyProfile",
6864
+ value: function applyStreamLatencyProfile(details) {
6865
+ if (this.latencyProfileApplied || !this.hls) {
6866
+ return;
6867
+ }
6868
+ if (!details) {
6869
+ return;
6870
+ }
6871
+ if (details.live !== true) {
6872
+ this.latencyProfileApplied = true;
6873
+ this.detectedLowLatencyStream = false;
6874
+ return;
6875
+ }
6876
+ var isLowLatencyManifest = this.isLowLatencyManifest(details);
6877
+ var useLowLatency = isLowLatencyManifest && !!this.config.lowLatencyMode;
6878
+ this.detectedLowLatencyStream = useLowLatency;
6879
+ this.latencyProfileApplied = true;
6880
+ var cfg = this.hls.config;
6881
+ if (useLowLatency) {
6882
+ cfg.maxLiveSyncPlaybackRate = 1.5;
6883
+ cfg.maxBufferHole = 0.5;
6884
+ delete cfg.liveSyncDuration;
6885
+ } else {
6886
+ cfg.maxLiveSyncPlaybackRate = 1.1;
6887
+ cfg.maxBufferHole = 1;
6888
+ delete cfg.liveSyncDuration;
6889
+ cfg.liveSyncDurationCount = 3;
6890
+ }
6891
+ if (this.debug) {
6892
+ var _details_targetduration;
6893
+ console.log("[StormcloudVideoPlayer] Live latency profile: ".concat(useLowLatency ? "LL-HLS (low latency)" : "standard live (stability)"), {
6894
+ isLowLatencyManifest: isLowLatencyManifest,
6895
+ lowLatencyModeRequested: !!this.config.lowLatencyMode,
6896
+ canBlockReload: details.canBlockReload,
6897
+ partTarget: details.partTarget,
6898
+ partHoldBack: details.partHoldBack,
6899
+ partListLength: Array.isArray(details.partList) ? details.partList.length : 0,
6900
+ targetDuration: (_details_targetduration = details.targetduration) !== null && _details_targetduration !== void 0 ? _details_targetduration : details.targetDuration,
6901
+ maxLiveSyncPlaybackRate: cfg.maxLiveSyncPlaybackRate,
6902
+ maxBufferHole: cfg.maxBufferHole
6903
+ });
6904
+ }
6905
+ }
6906
+ },
6907
+ {
6908
+ key: "isLowLatencyManifest",
6909
+ value: function isLowLatencyManifest(details) {
6910
+ if (!details) {
6911
+ return false;
6912
+ }
6913
+ var hasParts = Array.isArray(details.partList) && details.partList.length > 0;
6914
+ var hasPartTarget = typeof details.partTarget === "number" && details.partTarget > 0;
6915
+ var hasPartHoldBack = typeof details.partHoldBack === "number" && details.partHoldBack > 0;
6916
+ var canBlockReload = details.canBlockReload === true;
6917
+ return hasParts || hasPartTarget || hasPartHoldBack || canBlockReload;
6918
+ }
6919
+ },
6847
6920
  {
6848
6921
  key: "onId3Tag",
6849
6922
  value: function onId3Tag(tag) {
@@ -9329,6 +9402,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9329
9402
  return this.hlsEngine.isLiveStream;
9330
9403
  }
9331
9404
  },
9405
+ {
9406
+ key: "isLowLatencyStream",
9407
+ value: function isLowLatencyStream() {
9408
+ return this.hlsEngine.isLowLatencyStream();
9409
+ }
9410
+ },
9332
9411
  {
9333
9412
  key: "videoElement",
9334
9413
  get: function get() {