@xibosignage/xibo-layout-renderer 1.0.27 → 1.0.29

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.
@@ -19,30 +19,6 @@ var XiboLayoutRenderer = (function (exports) {
19
19
  return !!t;
20
20
  })();
21
21
  }
22
- function _iterableToArrayLimit(r, l) {
23
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
24
- if (null != t) {
25
- var e,
26
- n,
27
- i,
28
- u,
29
- a = [],
30
- f = !0,
31
- o = !1;
32
- try {
33
- if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
34
- } catch (r) {
35
- o = !0, n = r;
36
- } finally {
37
- try {
38
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
39
- } finally {
40
- if (o) throw n;
41
- }
42
- }
43
- return a;
44
- }
45
- }
46
22
  function ownKeys(e, r) {
47
23
  var t = Object.keys(e);
48
24
  if (Object.getOwnPropertySymbols) {
@@ -521,18 +497,12 @@ var XiboLayoutRenderer = (function (exports) {
521
497
  }
522
498
  return _assertThisInitialized(self);
523
499
  }
524
- function _slicedToArray(arr, i) {
525
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest();
526
- }
527
500
  function _toConsumableArray(arr) {
528
501
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
529
502
  }
530
503
  function _arrayWithoutHoles(arr) {
531
504
  if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
532
505
  }
533
- function _arrayWithHoles(arr) {
534
- if (Array.isArray(arr)) return arr;
535
- }
536
506
  function _iterableToArray(iter) {
537
507
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
538
508
  }
@@ -552,9 +522,6 @@ var XiboLayoutRenderer = (function (exports) {
552
522
  function _nonIterableSpread() {
553
523
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
554
524
  }
555
- function _nonIterableRest() {
556
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
557
- }
558
525
  function _createForOfIteratorHelper(o, allowArrayLike) {
559
526
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
560
527
  if (!it) {
@@ -1061,6 +1028,13 @@ var XiboLayoutRenderer = (function (exports) {
1061
1028
  },
1062
1029
  gotoNextLayout: function gotoNextLayout() {},
1063
1030
  gotoPrevLayout: function gotoPrevLayout() {},
1031
+ gotoLayoutByCode: function gotoLayoutByCode(_layoutCode) {
1032
+ return Promise.resolve();
1033
+ },
1034
+ playInterruptLayout: function playInterruptLayout(_inputLayout) {
1035
+ return Promise.resolve();
1036
+ },
1037
+ triggerAction: function triggerAction(_triggerCode, _widgetId) {},
1064
1038
  init: function init() {
1065
1039
  return Promise.resolve({});
1066
1040
  },
@@ -1099,7 +1073,7 @@ var XiboLayoutRenderer = (function (exports) {
1099
1073
  renderOverlayLayouts: function renderOverlayLayouts() {
1100
1074
  return Promise.resolve();
1101
1075
  },
1102
- uniqueLayouts: {},
1076
+ uniqueLayouts: new Map(),
1103
1077
  updateInputLayout: function updateInputLayout(layoutIndex, layout) {},
1104
1078
  updateLayouts: function updateLayouts(inputLayouts) {},
1105
1079
  updateLoop: function updateLoop(inputLayouts) {
@@ -14019,11 +13993,11 @@ var XiboLayoutRenderer = (function (exports) {
14019
13993
  * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
14020
13994
  * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization
14021
13995
  */
14022
- function DOMParser$1(options){
13996
+ function DOMParser$2(options){
14023
13997
  this.options = options ||{locator:{}};
14024
13998
  }
14025
13999
 
14026
- DOMParser$1.prototype.parseFromString = function(source,mimeType){
14000
+ DOMParser$2.prototype.parseFromString = function(source,mimeType){
14027
14001
  var options = this.options;
14028
14002
  var sax = new XMLReader();
14029
14003
  var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
@@ -14270,9 +14244,9 @@ var XiboLayoutRenderer = (function (exports) {
14270
14244
 
14271
14245
  domParser.__DOMHandler = DOMHandler;
14272
14246
  domParser.normalizeLineEndings = normalizeLineEndings;
14273
- domParser.DOMParser = DOMParser$1;
14247
+ domParser.DOMParser = DOMParser$2;
14274
14248
 
14275
- var DOMParser = domParser.DOMParser;
14249
+ var DOMParser$1 = domParser.DOMParser;
14276
14250
 
14277
14251
  /*! @name mpd-parser @version 1.3.1 @license Apache-2.0 */
14278
14252
 
@@ -16896,7 +16870,7 @@ var XiboLayoutRenderer = (function (exports) {
16896
16870
  throw new Error(errors.DASH_EMPTY_MANIFEST);
16897
16871
  }
16898
16872
 
16899
- const parser = new DOMParser();
16873
+ const parser = new DOMParser$1();
16900
16874
  let xml;
16901
16875
  let mpd;
16902
16876
 
@@ -73601,7 +73575,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
73601
73575
  cssText += "\n visibility: hidden;\n opacity: 0;\n z-index: 0;\n ";
73602
73576
  }
73603
73577
  $media.style.cssText = cssText;
73604
- if (self.render === 'html' || self.mediaType === 'ticker' || self.mediaType === 'webpage') {
73578
+ if (self.mediaType !== 'spacer' && (self.render === 'html' || self.mediaType === 'ticker' || self.mediaType === 'webpage')) {
73605
73579
  self.checkIframeStatus = true;
73606
73580
  self.iframe = prepareIframe(self);
73607
73581
  } else if (self.mediaType === "image") {
@@ -73749,8 +73723,6 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
73749
73723
  region.html.appendChild(media.html);
73750
73724
  }
73751
73725
  function prepareHtmlMedia(media, region) {
73752
- // Set state as false ( for now )
73753
- media.ready = false;
73754
73726
  if (media.html) {
73755
73727
  var mediaId = getMediaId(media);
73756
73728
  // Clean up old copy of the media
@@ -73762,14 +73734,16 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
73762
73734
  mediaId: mediaId,
73763
73735
  mediaInRegion: mediaInRegion
73764
73736
  });
73765
- // Append iframe
73766
- media.html.innerHTML = '';
73767
- media.html.appendChild(media.iframe);
73768
73737
  if (!mediaInRegion) {
73769
- // Add fresh copy of the media into the region using the direct reference
73738
+ // Append iframe and insert into region only when not already in the DOM.
73739
+ // Calling innerHTML = '' when the element is already present detaches the
73740
+ // iframe, causing the browser to reload its src unnecessarily (e.g. when
73741
+ // a media was preloaded then skipped by a navigation action).
73742
+ media.html.innerHTML = '';
73743
+ media.html.appendChild(media.iframe);
73770
73744
  region.html.appendChild(media.html);
73771
- media.ready = true;
73772
73745
  }
73746
+ media.ready = true;
73773
73747
  }
73774
73748
  }
73775
73749
  exports.FaultCodes = void 0;
@@ -74025,14 +73999,13 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74025
73999
  _this.startMediaTimer(media);
74026
74000
  }
74027
74001
  } else if (media.mediaType === 'shellcommand') {
74028
- if (_this.hasCommandExecuted && !_this.loop) {
74029
- return;
74030
- }
74031
- _this.hasCommandExecuted = true;
74032
- _this.emitCommand(media);
74033
- if (media.duration > 0) {
74034
- _this.startMediaTimer(media);
74002
+ // Fire once per cycle unless loop is enabled, in which case re-fire every play.
74003
+ if (!_this.hasCommandExecuted || _this.loop) {
74004
+ _this.hasCommandExecuted = true;
74005
+ _this.emitCommand(media);
74035
74006
  }
74007
+ // Always run the timer so the layout advances and stats are recorded correctly.
74008
+ _this.startMediaTimer(media);
74036
74009
  } else {
74037
74010
  _this.startMediaTimer(media);
74038
74011
  }
@@ -74078,7 +74051,12 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74078
74051
  var _this$sspImpressionUr, _this$sspErrorUrls;
74079
74052
  _this.xlr.emitter.emit('sspWidgetEnd', (_this$sspImpressionUr = _this.sspImpressionUrls) !== null && _this$sspImpressionUr !== void 0 ? _this$sspImpressionUr : [], (_this$sspErrorUrls = _this.sspErrorUrls) !== null && _this$sspErrorUrls !== void 0 ? _this$sspErrorUrls : [], _this.sspImpressionUrls ? _this.duration : 0);
74080
74053
  }
74081
- media.region.playNextMedia();
74054
+ // Only advance the region if this media is still the active one.
74055
+ // A user-triggered next/prev action may have already moved currMedia
74056
+ // on, in which case the timer firing here would cause a double-advance.
74057
+ if (media === media.region.currMedia) {
74058
+ media.region.playNextMedia();
74059
+ }
74082
74060
  });
74083
74061
  this.on('cancelled', function (media) {
74084
74062
  if (media.state === MediaState.CANCELLED) return;
@@ -74108,7 +74086,12 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74108
74086
  var _this$sspImpressionUr2, _this$sspErrorUrls2;
74109
74087
  _this.xlr.emitter.emit('sspWidgetEnd', (_this$sspImpressionUr2 = _this.sspImpressionUrls) !== null && _this$sspImpressionUr2 !== void 0 ? _this$sspImpressionUr2 : [], (_this$sspErrorUrls2 = _this.sspErrorUrls) !== null && _this$sspErrorUrls2 !== void 0 ? _this$sspErrorUrls2 : [], _this.sspImpressionUrls ? _this.duration : 0);
74110
74088
  }
74111
- media.region.playNextMedia();
74089
+ // Only advance the region if this media is still the active one.
74090
+ // A user-triggered next/prev action may have already moved currMedia
74091
+ // on, in which case the timer firing here would cause a double-advance.
74092
+ if (media === media.region.currMedia) {
74093
+ media.region.playNextMedia();
74094
+ }
74112
74095
  });
74113
74096
  // Initialize Media object
74114
74097
  this.init();
@@ -74117,6 +74100,10 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74117
74100
  key: "startMediaTimer",
74118
74101
  value: function startMediaTimer(media) {
74119
74102
  var _this2 = this;
74103
+ // Always reset the counter so a media replayed after cancellation runs
74104
+ // for its full duration rather than the residual time left from the
74105
+ // previous play.
74106
+ this.mediaTimeCount = 0;
74120
74107
  var preloadTimeMs = 2000;
74121
74108
  var preloadTimeBufferMs = media.duration * 1000 / 2 - preloadTimeMs;
74122
74109
  var isPreparingNextMedia = false;
@@ -74341,11 +74328,11 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74341
74328
  };
74342
74329
  var getNewMedia = function getNewMedia() {
74343
74330
  var $region = _this3.region.html;
74344
- // This function is for checking whether
74345
- // the region still has to show a media item
74346
- // when another region is not finished yet
74347
- if (_this3.region.complete && !_this3.region.layout.allEnded) {
74348
- // Add currentMedia to the region
74331
+ // Re-insert the element whenever it is missing from the DOM. This covers:
74332
+ // 1. Region completed early but the layout is still running (freeze last frame).
74333
+ // 2. Backward navigation the previous media's element was removed by the
74334
+ // removeOldMedia setTimeout in transitionNodes.
74335
+ if (_this3.html) {
74349
74336
  $region.insertBefore(_this3.html, $region.lastElementChild);
74350
74337
  return _this3.html;
74351
74338
  }
@@ -74611,15 +74598,21 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74611
74598
  });
74612
74599
  // Add media to region for targeted actions
74613
74600
  (_this$layout$actionCo = this.layout.actionController) === null || _this$layout$actionCo === void 0 || _this$layout$actionCo.actions.forEach(function (action) {
74601
+ var _ref2, _attributes$actionTyp, _ref3, _attributes$targetId, _ref4, _attributes$widgetId, _attributes$target;
74614
74602
  var attributes = getAllAttributes(action.xml);
74615
- if (attributes.target.value === 'region' && attributes.actionType.value === 'navWidget' && attributes.targetId.value == _this.id) {
74603
+ // getAllAttributes preserves the XML attribute case. Xibo CMS may export
74604
+ // attributes in camelCase (actionType, targetId, widgetId) or lowercase.
74605
+ // Read both variants so we work with either XLF format.
74606
+ var actionType = (_ref2 = (_attributes$actionTyp = attributes['actionType']) !== null && _attributes$actionTyp !== void 0 ? _attributes$actionTyp : attributes['actiontype']) === null || _ref2 === void 0 ? void 0 : _ref2.value;
74607
+ var targetId = (_ref3 = (_attributes$targetId = attributes['targetId']) !== null && _attributes$targetId !== void 0 ? _attributes$targetId : attributes['targetid']) === null || _ref3 === void 0 ? void 0 : _ref3.value;
74608
+ var widgetId = (_ref4 = (_attributes$widgetId = attributes['widgetId']) !== null && _attributes$widgetId !== void 0 ? _attributes$widgetId : attributes['widgetid']) === null || _ref4 === void 0 ? void 0 : _ref4.value;
74609
+ if (((_attributes$target = attributes['target']) === null || _attributes$target === void 0 ? void 0 : _attributes$target.value) === 'region' && actionType === 'navWidget' && targetId == _this.id) {
74616
74610
  var _this$layout$drawer;
74617
74611
  var drawerMediaItems = Array.from(((_this$layout$drawer = _this.layout.drawer) === null || _this$layout$drawer === void 0 ? void 0 : _this$layout$drawer.getElementsByTagName('media')) || []);
74618
74612
  drawerMediaItems.forEach(function (drawerMedia) {
74619
- var _attributes$widgetId;
74620
- if (drawerMedia.id === ((_attributes$widgetId = attributes.widgetId) === null || _attributes$widgetId === void 0 ? void 0 : _attributes$widgetId.value)) {
74613
+ if (drawerMedia.getAttribute('id') === widgetId) {
74621
74614
  // Add drawer media to the region
74622
- _this.mediaObjectsActions.push(new Media(_this, (drawerMedia === null || drawerMedia === void 0 ? void 0 : drawerMedia.getAttribute('id')) || '', drawerMedia, _this.options, _this.xlr));
74615
+ _this.mediaObjectsActions.push(new Media(_this, drawerMedia.getAttribute('id') || '', drawerMedia, _this.options, _this.xlr));
74623
74616
  }
74624
74617
  });
74625
74618
  }
@@ -74651,6 +74644,11 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74651
74644
  prepareAudioMedia(media, this);
74652
74645
  } else if ((media.render === 'html' || media.mediaType === 'webpage') && media.iframe && media.checkIframeStatus) {
74653
74646
  prepareHtmlMedia(media, this);
74647
+ } else if (media.mediaType === 'shellcommand') {
74648
+ // Shell command widgets are invisible but must be in the DOM to trigger playback.
74649
+ if (media.html) {
74650
+ this.html.appendChild(media.html);
74651
+ }
74654
74652
  }
74655
74653
  }
74656
74654
  }, {
@@ -74874,7 +74872,17 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74874
74872
  }, {
74875
74873
  key: "playNextMedia",
74876
74874
  value: function playNextMedia() {
74877
- var _this$oldMedia3, _this$currMedia2, _this$nxtMedia, _this$currMedia3, _this$currMedia4, _this$currMedia5, _this$currMedia6, _this$oldMedia4, _this$currMedia7, _this$nxtMedia2;
74875
+ var _this$oldMedia3,
74876
+ _this$currMedia2,
74877
+ _this$nxtMedia,
74878
+ _this$currMedia3,
74879
+ _this$currMedia4,
74880
+ _this$currMedia5,
74881
+ _this$currMedia6,
74882
+ _this3 = this,
74883
+ _this$oldMedia4,
74884
+ _this$currMedia7,
74885
+ _this$nxtMedia2;
74878
74886
  console.debug('??? XLR.debug Region playing next media', {
74879
74887
  regionId: this.id,
74880
74888
  currentMediaIndex: this.currentMediaIndex,
@@ -74894,8 +74902,10 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74894
74902
  // cycle completion after the skip loop runs.
74895
74903
  var origIndex = this.currentMediaIndex;
74896
74904
  // When the region has completed and when currentMedia is html
74897
- // Then, preserve the currentMedia state
74898
- if (this.complete && ((_this$currMedia3 = this.currMedia) === null || _this$currMedia3 === void 0 ? void 0 : _this$currMedia3.render) === 'html') {
74905
+ // and there is only one media object, preserve the currentMedia state.
74906
+ // Guard is limited to single-media regions so navWidget injections
74907
+ // (which splice a second media in) are not blocked.
74908
+ if (this.complete && ((_this$currMedia3 = this.currMedia) === null || _this$currMedia3 === void 0 ? void 0 : _this$currMedia3.render) === 'html' && this.totalMediaObjects === 1) {
74899
74909
  return;
74900
74910
  }
74901
74911
  // When the region has completed and mediaObjects.length = 1
@@ -74941,6 +74951,25 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74941
74951
  }
74942
74952
  });
74943
74953
  }
74954
+ // Remove single-play media injected via navWidget actions at the end of each cycle
74955
+ if (crossedEnd && this.mediaObjects.some(function (m) {
74956
+ return m.singlePlay;
74957
+ })) {
74958
+ this.mediaObjects = this.mediaObjects.filter(function (m) {
74959
+ return !m.singlePlay;
74960
+ });
74961
+ this.totalMediaObjects = this.mediaObjects.length;
74962
+ if (this.totalMediaObjects === 0) {
74963
+ this.finished();
74964
+ return;
74965
+ }
74966
+ var newIndex = this.mediaObjects.findIndex(function (m) {
74967
+ return m === _this3.currMedia;
74968
+ });
74969
+ this.currentMediaIndex = newIndex >= 0 ? newIndex : 0;
74970
+ this.currMedia = this.mediaObjects[this.currentMediaIndex];
74971
+ this.nxtMedia = this.mediaObjects[(this.currentMediaIndex + 1) % this.totalMediaObjects];
74972
+ }
74944
74973
  console.debug('??? XLR.debug >> End Region::playNextMedia > execute transitionNodes', {
74945
74974
  regionId: this.id,
74946
74975
  currentMediaIndex: this.currentMediaIndex,
@@ -74950,25 +74979,41 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
74950
74979
  nxtMedia: (_this$nxtMedia2 = this.nxtMedia) === null || _this$nxtMedia2 === void 0 ? void 0 : _this$nxtMedia2.containerName
74951
74980
  });
74952
74981
  if (!this.layout.isOverlay && crossedEnd) {
74982
+ var _this$currMedia8;
74953
74983
  this.finished();
74954
74984
  if (this.layout.allEnded) {
74955
74985
  console.debug('??? XLR.debug >> Region - playNextMedia - layout all ended');
74956
74986
  return;
74957
74987
  }
74988
+ // Freeze single-media HTML at its last state while waiting for other
74989
+ // regions to complete. The guard at the top only catches the second
74990
+ // call; this one catches the first completion when complete was just
74991
+ // set by finished() above.
74992
+ if (((_this$currMedia8 = this.currMedia) === null || _this$currMedia8 === void 0 ? void 0 : _this$currMedia8.render) === 'html' && this.totalMediaObjects === 1 && this.oldMedia === this.currMedia) {
74993
+ return;
74994
+ }
74958
74995
  }
74959
74996
  this.transitionNodes(this.oldMedia, this.currMedia);
74960
74997
  }
74961
74998
  }, {
74962
74999
  key: "playPreviousMedia",
74963
75000
  value: function playPreviousMedia() {
74964
- this.currentMediaIndex = this.currentMediaIndex - 1;
74965
- if (this.currentMediaIndex < 0 || this.ended) {
74966
- this.currentMediaIndex = 0;
75001
+ if (this.currentMediaIndex <= 0 || this.ended) {
74967
75002
  return;
74968
75003
  }
74969
- this.prepareMediaObjects();
75004
+ var interruptedMedia = this.currMedia;
75005
+ this.oldMedia = this.currMedia;
75006
+ this.currentMediaIndex -= 1;
75007
+ this.currMedia = this.mediaObjects[this.currentMediaIndex];
75008
+ this.nxtMedia = this.mediaObjects[(this.currentMediaIndex + 1) % this.totalMediaObjects];
75009
+ this.complete = false;
75010
+ // Cancel the interrupted media after advancing currMedia, using the same
75011
+ // pattern as gotoMediaInRegion — emitting after the update ensures the
75012
+ // handler's (media === currMedia) guard correctly skips playNextMedia.
75013
+ if ((interruptedMedia === null || interruptedMedia === void 0 ? void 0 : interruptedMedia.state) === MediaState.PLAYING) {
75014
+ interruptedMedia.emitter.emit('cancelled', interruptedMedia);
75015
+ }
74970
75016
  console.debug('region::playPreviousMedia', this);
74971
- /* Do the transition */
74972
75017
  this.transitionNodes(this.oldMedia, this.currMedia);
74973
75018
  }
74974
75019
  }, {
@@ -75045,6 +75090,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75045
75090
  _defineProperty(this, "$actionControllerTitle", void 0);
75046
75091
  _defineProperty(this, "$actionsContainer", void 0);
75047
75092
  _defineProperty(this, "translations", {});
75093
+ _defineProperty(this, "keyboardHandler", null);
75048
75094
  this.parent = parent;
75049
75095
  this.actions = actions;
75050
75096
  this.options = options;
@@ -75167,6 +75213,10 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75167
75213
  key: "openLayoutInNewTab",
75168
75214
  value: function openLayoutInNewTab(layoutCode, options) {
75169
75215
  var url = options.layoutPreviewUrl.replace('[layoutCode]', layoutCode) + '?findByCode=1';
75216
+ console.debug('[ActionController::openLayoutInNewTab] Navigating to layout in new tab with code', {
75217
+ layoutCode: layoutCode,
75218
+ url: url
75219
+ });
75170
75220
  // Send a postMessage to the parent frame so the CMS can handle the confirmation
75171
75221
  // and navigation (confirm() is blocked in sandboxed iframes without allow-modals).
75172
75222
  window.parent.postMessage({
@@ -75179,41 +75229,78 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75179
75229
  }
75180
75230
  }, {
75181
75231
  key: "openLayoutInPlayer",
75182
- value: function openLayoutInPlayer(layoutCode, options) {
75183
- // this.parent.xlr.updateLoop([]);
75232
+ value: function openLayoutInPlayer(layoutCode, _options) {
75233
+ console.debug('[ActionController::openLayoutInPlayer] Navigating to layout in player with code', {
75234
+ layoutCode: layoutCode,
75235
+ options: _options
75236
+ });
75237
+ this.parent.xlr.emitter.emit('navLayout', layoutCode, '');
75184
75238
  }
75185
75239
  }, {
75186
75240
  key: "prevOrNextLayout",
75187
75241
  value: function prevOrNextLayout(targetId, actionType) {
75188
75242
  var _this$parent$xlr$curr;
75189
- // Check if currentLayout is the targetId
75190
- if (((_this$parent$xlr$curr = this.parent.xlr.currentLayout) === null || _this$parent$xlr$curr === void 0 ? void 0 : _this$parent$xlr$curr.layoutId) === parseInt(targetId)) {
75191
- if (actionType === 'next') {
75192
- this.parent.xlr.gotoNextLayout();
75193
- } else if (actionType === 'previous') {
75194
- this.parent.xlr.gotoPrevLayout();
75195
- }
75243
+ console.debug('[ActionController::prevOrNextLayout] Changing layout with data', {
75244
+ targetId: targetId,
75245
+ actionType: actionType
75246
+ });
75247
+ // For screen-level actions targetId may be "0" (the screen has no numeric ID).
75248
+ // Guard using this.parent.layoutId instead so the check always works.
75249
+ if (((_this$parent$xlr$curr = this.parent.xlr.currentLayout) === null || _this$parent$xlr$curr === void 0 ? void 0 : _this$parent$xlr$curr.layoutId) !== this.parent.layoutId) {
75250
+ return;
75251
+ }
75252
+ if (actionType === 'next') {
75253
+ this.parent.xlr.gotoNextLayout();
75254
+ } else if (actionType === 'previous') {
75255
+ this.parent.xlr.gotoPrevLayout();
75196
75256
  }
75197
75257
  }
75198
- /** Change media in region (next/previous) */
75258
+ /** Change media in region (next/previous) with wrap-around at boundaries. */
75199
75259
  }, {
75200
- key: "nextMediaInRegion",
75201
- value: function nextMediaInRegion(regionId, actionType) {
75202
- // Find target region
75260
+ key: "gotoMediaInRegion",
75261
+ value: function gotoMediaInRegion(regionId, actionType) {
75262
+ console.debug('[ActionController::gotoMediaInRegion] Changing media in region with data', {
75263
+ regionId: regionId,
75264
+ actionType: actionType
75265
+ });
75203
75266
  this.parent.regions.forEach(function (regionObj) {
75204
- if (regionObj.id === regionId) {
75205
- if (actionType === 'next') {
75206
- regionObj.playNextMedia();
75207
- } else {
75208
- regionObj.playPreviousMedia();
75209
- }
75267
+ if (regionObj.id !== regionId || regionObj.ended) return;
75268
+ var total = regionObj.totalMediaObjects;
75269
+ if (total === 0) return;
75270
+ // Snapshot the currently-playing media before updating currMedia so
75271
+ // we can cancel it cleanly after the region state is advanced.
75272
+ var interruptedMedia = regionObj.currMedia;
75273
+ // Compute new index with wrap-around. We do NOT delegate to
75274
+ // playNextMedia() / playPreviousMedia() here because those carry
75275
+ // normal playlist-cycle semantics (finished(), regionExpired()) that
75276
+ // must not fire during user-driven navigation.
75277
+ var newIndex = actionType === 'next' ? (regionObj.currentMediaIndex + 1) % total : (regionObj.currentMediaIndex - 1 + total) % total;
75278
+ regionObj.oldMedia = regionObj.currMedia;
75279
+ regionObj.currentMediaIndex = newIndex;
75280
+ regionObj.currMedia = regionObj.mediaObjects[newIndex];
75281
+ regionObj.nxtMedia = regionObj.mediaObjects[(newIndex + 1) % total];
75282
+ regionObj.complete = false;
75283
+ // Properly cancel the interrupted media AFTER updating currMedia.
75284
+ // Using 'cancelled' rather than bare clearInterval ensures state is
75285
+ // reset from PLAYING and mediaTimeCount is zeroed — without this,
75286
+ // returning to a cancelled media causes run() → 'start' to bail on
75287
+ // the state === PLAYING guard, leaving the region stuck indefinitely.
75288
+ // currMedia is already updated so the handler's guard
75289
+ // (media === media.region.currMedia) correctly skips playNextMedia.
75290
+ if ((interruptedMedia === null || interruptedMedia === void 0 ? void 0 : interruptedMedia.state) === MediaState.PLAYING) {
75291
+ interruptedMedia.emitter.emit('cancelled', interruptedMedia);
75210
75292
  }
75293
+ regionObj.transitionNodes(regionObj.oldMedia, regionObj.currMedia);
75211
75294
  });
75212
75295
  }
75213
75296
  }, {
75214
75297
  key: "loadMediaInRegion",
75215
75298
  value: function loadMediaInRegion(regionId, widgetId) {
75216
- var _targetRegion, _targetRegion2, _targetRegion3;
75299
+ var _targetRegion, _targetRegion2, _targetRegion3, _targetRegion4;
75300
+ console.debug('[ActionController::loadMediaInRegion] Loading media in region with data', {
75301
+ regionId: regionId,
75302
+ widgetId: widgetId
75303
+ });
75217
75304
  var self = this;
75218
75305
  // Find target region
75219
75306
  var targetRegion;
@@ -75236,27 +75323,84 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75236
75323
  targetMedia.singlePlay = true;
75237
75324
  }
75238
75325
  // If region is empty, remove the background color and empty message
75239
- if (((_targetRegion = targetRegion) === null || _targetRegion === void 0 ? void 0 : _targetRegion.mediaObjects.length) === 0) {
75326
+ if (((_targetRegion = targetRegion) === null || _targetRegion === void 0 ? void 0 : _targetRegion.totalMediaObjects) === 0) {
75327
+ targetRegion.complete = false;
75328
+ }
75329
+ // Bail out early when the target widget was not found in the drawer
75330
+ if (!targetMedia) {
75331
+ console.debug('[ActionController::loadMediaInRegion] Target media not found in mediaObjectsActions', {
75332
+ regionId: regionId,
75333
+ widgetId: widgetId
75334
+ });
75335
+ return;
75336
+ }
75337
+ // Guard against duplicate insertion if the action fires multiple times before the widget plays
75338
+ if (targetRegion && targetRegion.mediaObjects.some(function (m) {
75339
+ return m.id === targetMedia.id;
75340
+ })) {
75341
+ console.debug('[ActionController::loadMediaInRegion] Target media already queued, skipping duplicate insertion');
75342
+ return;
75343
+ }
75344
+ // Cancel the interrupted media so it doesn't double-advance when the playlist
75345
+ // returns to it. currMedia has not been advanced yet at this point (playNextMedia
75346
+ // does that below), so we cannot use emitter.emit('cancelled') — the handler's
75347
+ // currMedia guard would fire and call playNextMedia a second time. Instead we
75348
+ // cancel directly: clear the timer and reset state so the 'start' handler does
75349
+ // not bail on the state === PLAYING guard when this media is replayed.
75350
+ if (((_targetRegion2 = targetRegion) === null || _targetRegion2 === void 0 || (_targetRegion2 = _targetRegion2.currMedia) === null || _targetRegion2 === void 0 ? void 0 : _targetRegion2.state) === MediaState.PLAYING) {
75351
+ var interruptedMedia = targetRegion.currMedia;
75352
+ if (interruptedMedia.mediaTimer) {
75353
+ clearInterval(interruptedMedia.mediaTimer);
75354
+ interruptedMedia.mediaTimer = undefined;
75355
+ }
75356
+ interruptedMedia.state = MediaState.CANCELLED;
75357
+ }
75358
+ // Reset complete so the HTML-media guard in playNextMedia() doesn't block
75359
+ // the transition (that guard is for single-media loops, not navWidget injections).
75360
+ if (targetRegion) {
75240
75361
  targetRegion.complete = false;
75241
75362
  }
75242
75363
  // Create media in region and play it next
75243
- (_targetRegion2 = targetRegion) === null || _targetRegion2 === void 0 || _targetRegion2.mediaObjects.splice(targetRegion.currentMediaIndex + 1, 0, targetMedia);
75244
- (_targetRegion3 = targetRegion) === null || _targetRegion3 === void 0 || _targetRegion3.playNextMedia();
75364
+ (_targetRegion3 = targetRegion) === null || _targetRegion3 === void 0 || _targetRegion3.mediaObjects.splice(targetRegion.currentMediaIndex + 1, 0, targetMedia);
75365
+ // Keep totalMediaObjects in sync with the actual array length
75366
+ if (targetRegion) {
75367
+ targetRegion.totalMediaObjects = targetRegion.mediaObjects.length;
75368
+ }
75369
+ // Drawer media items are never run through the normal prepareMedia pipeline,
75370
+ // so their DOM element has no background-image / src set and is not yet in the
75371
+ // region DOM. Prepare it now so Media.run() finds a ready element to show.
75372
+ if (targetRegion) {
75373
+ targetRegion.prepareMedia(targetMedia);
75374
+ }
75375
+ console.debug('[ActionController::loadMediaInRegion] Target media loaded, playing next', {
75376
+ regionId: regionId,
75377
+ widgetId: widgetId
75378
+ });
75379
+ (_targetRegion4 = targetRegion) === null || _targetRegion4 === void 0 || _targetRegion4.playNextMedia();
75245
75380
  }
75246
75381
  /** Run action based on action data */
75247
75382
  }, {
75248
75383
  key: "runAction",
75249
75384
  value: function runAction(actionData, options) {
75385
+ // If this layout is no longer active (being cancelled or navigated away from),
75386
+ // discard the action so it doesn't interfere with the outgoing transition.
75387
+ // inLoop is set to false synchronously before finishAllRegions() in all nav paths.
75388
+ if (!this.parent.inLoop) {
75389
+ return;
75390
+ }
75391
+ console.debug('[ActionController::runAction] Triggering action', {
75392
+ actionData: actionData
75393
+ });
75250
75394
  if (actionData.actiontype == 'navLayout') {
75251
75395
  if (this.parent.xlr.config.platform === exports.ConsumerPlatform.CMS) {
75252
- // Open layout preview in a new tab
75396
+ // Open layout preview in a new tab (CMS preview only)
75253
75397
  this.openLayoutInNewTab(actionData.layoutcode, options);
75254
- } else if (this.parent.xlr.config.platform === exports.ConsumerPlatform.CHROMEOS) {
75255
- // Set target layout as active layout
75398
+ } else {
75399
+ // All player platforms (Electron, ChromeOS, Android, etc.)
75256
75400
  this.openLayoutInPlayer(actionData.layoutcode, options);
75257
75401
  }
75258
75402
  } else if ((actionData.actiontype == 'previous' || actionData.actiontype == 'next') && actionData.target == 'region') {
75259
- this.nextMediaInRegion(actionData.targetid, actionData.actiontype);
75403
+ this.gotoMediaInRegion(actionData.targetid, actionData.actiontype);
75260
75404
  } else if (actionData.actiontype == 'navWidget' && actionData.target == 'region') {
75261
75405
  this.loadMediaInRegion(actionData.targetid, actionData.widgetid);
75262
75406
  } else if (actionData.target === 'screen') {
@@ -75315,35 +75459,53 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75315
75459
  }
75316
75460
  });
75317
75461
  }
75462
+ /** Dispatch an incoming webhook trigger to any matching actions on this layout. */
75463
+ }, {
75464
+ key: "handleWebhookTrigger",
75465
+ value: function handleWebhookTrigger(triggerCode, widgetId) {
75466
+ var _this3 = this;
75467
+ this.$actionController.querySelectorAll('.action[triggertype="webhook"]').forEach(function ($el) {
75468
+ var ds = $el.dataset;
75469
+ if (ds.triggercode !== triggerCode) return;
75470
+ if (widgetId && ds.sourceid !== widgetId) return;
75471
+ _this3.runAction(ds, _this3.options);
75472
+ });
75473
+ }
75318
75474
  }, {
75319
75475
  key: "initKeyboardActions",
75320
75476
  value: function initKeyboardActions() {
75321
75477
  var self = this;
75322
- // Store actions in a map
75323
75478
  var keyActions = new Map();
75324
- this.$actionController.querySelectorAll('.action[triggerType="keyPress"]').forEach(function ($el) {
75479
+ this.$actionController.querySelectorAll('.action[triggertype="keyPress"]').forEach(function ($el) {
75325
75480
  var dataset = $el.dataset;
75326
75481
  var code = dataset.triggercode;
75327
75482
  if (code) {
75328
- // Create an empty array, if not yet set
75329
75483
  if (!keyActions.get(code)) {
75330
75484
  keyActions.set(code, []);
75331
75485
  }
75332
- // Add new action to array
75333
75486
  keyActions.get(code).push(dataset);
75334
75487
  }
75335
75488
  });
75336
- // Keyboard listener
75337
- document.addEventListener('keydown', function (ev) {
75489
+ // Nothing to do if this layout has no keyboard-triggered actions.
75490
+ if (keyActions.size === 0) return;
75491
+ this.keyboardHandler = function (ev) {
75338
75492
  var actions = keyActions.get(ev.code);
75339
- // Are there action for this key code?
75340
75493
  if (actions) {
75341
- // Run all actions associated with it
75342
75494
  actions.forEach(function (dataset) {
75343
75495
  self.runAction(dataset, self.options);
75344
75496
  });
75345
75497
  }
75346
- });
75498
+ };
75499
+ document.addEventListener('keydown', this.keyboardHandler);
75500
+ }
75501
+ /** Remove the keydown listener registered by initKeyboardActions. Call when the layout ends or is cancelled. */
75502
+ }, {
75503
+ key: "removeKeyboardActions",
75504
+ value: function removeKeyboardActions() {
75505
+ if (this.keyboardHandler) {
75506
+ document.removeEventListener('keydown', this.keyboardHandler);
75507
+ this.keyboardHandler = null;
75508
+ }
75347
75509
  }
75348
75510
  }]);
75349
75511
  }();
@@ -75578,6 +75740,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75578
75740
  });
75579
75741
  this.on('end', /*#__PURE__*/function () {
75580
75742
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(layout) {
75743
+ var _layout$actionControl;
75581
75744
  var $layout, _$layout$parentElemen;
75582
75745
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
75583
75746
  while (1) switch (_context2.prev = _context2.next) {
@@ -75636,9 +75799,10 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75636
75799
  }
75637
75800
  // Emit layout end event
75638
75801
  console.debug('>>>>> XLR.debug Awaited XLR::emitSync > End - Calling layoutEnd event');
75639
- _context2.next = 13;
75802
+ (_layout$actionControl = layout.actionController) === null || _layout$actionControl === void 0 || _layout$actionControl.removeKeyboardActions();
75803
+ _context2.next = 14;
75640
75804
  return layout.xlr.emitSync('layoutEnd', layout);
75641
- case 13:
75805
+ case 14:
75642
75806
  if (_this.xlr.config.platform !== exports.ConsumerPlatform.CMS && layout.inLoop) {
75643
75807
  // Transition next layout to current layout and prepare next layout if exist
75644
75808
  _this.xlr.prepareLayouts().then( /*#__PURE__*/function () {
@@ -75668,7 +75832,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75668
75832
  };
75669
75833
  }());
75670
75834
  }
75671
- case 14:
75835
+ case 15:
75672
75836
  case "end":
75673
75837
  return _context2.stop();
75674
75838
  }
@@ -75679,9 +75843,11 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75679
75843
  };
75680
75844
  }());
75681
75845
  this.on('cancelled', function (layout) {
75846
+ var _layout$actionControl2;
75682
75847
  console.debug('>>>>> XLR.debug / Layout cancelled > Layout ID > ', layout.id);
75683
75848
  layout.state = exports.ELayoutState.CANCELLED;
75684
75849
  layout.inLoop = false;
75850
+ (_layout$actionControl2 = layout.actionController) === null || _layout$actionControl2 === void 0 || _layout$actionControl2.removeKeyboardActions();
75685
75851
  // Dispose video handlers immediately so their stall watchdogs and error
75686
75852
  // callbacks can't fire against a layout whose DOM is about to be removed.
75687
75853
  var _iterator = _createForOfIteratorHelper(layout.regions),
@@ -75840,7 +76006,8 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75840
76006
  _this2.regions.push(regionObj);
75841
76007
  });
75842
76008
  this.actionController.initTouchActions();
75843
- this.actionController.initKeyboardActions();
76009
+ // Keyboard actions are registered in run() so the global document listener
76010
+ // is only active while the layout is actually playing, not during background preparation.
75844
76011
  }
75845
76012
  }, {
75846
76013
  key: "run",
@@ -75859,6 +76026,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75859
76026
  shouldParse: false
75860
76027
  });
75861
76028
  if ($layoutContainer) {
76029
+ var _this$actionControlle;
75862
76030
  $layoutContainer.style.setProperty('visibility', 'visible');
75863
76031
  $layoutContainer.style.setProperty('opacity', '1');
75864
76032
  $layoutContainer.style.setProperty('z-index', this.zIndex !== null ? "".concat(this.zIndex) : '1');
@@ -75867,6 +76035,9 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
75867
76035
  // Also set the background color of the player window > body
75868
76036
  document.body.style.setProperty('background-color', "".concat(this.bgColor));
75869
76037
  }
76038
+ // Register keyboard actions now that the layout is active.
76039
+ // Done here (not in parseXlf) so the global listener is scoped to playback time.
76040
+ (_this$actionControlle = this.actionController) === null || _this$actionControlle === void 0 || _this$actionControlle.initKeyboardActions();
75870
76041
  // Emit start event
75871
76042
  this.emitter.emit('start', this);
75872
76043
  // Play regions
@@ -76364,6 +76535,13 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76364
76535
  return _ref4.apply(this, arguments);
76365
76536
  };
76366
76537
  }());
76538
+ xlrObject.on('navLayout', function (layoutCode) {
76539
+ // Non-CMS platforms handle navLayout in their renderer via playInterruptLayout.
76540
+ // CMS navLayout is handled by ActionController (opens layout in a new tab).
76541
+ console.debug('[navLayout] XLR::on("navLayout") - received', {
76542
+ layoutCode: layoutCode
76543
+ });
76544
+ });
76367
76545
  xlrObject.emitSync = /*#__PURE__*/function () {
76368
76546
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(eventName) {
76369
76547
  var _xlrObject$emitter$ev;
@@ -76543,35 +76721,28 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76543
76721
  }));
76544
76722
  xlrObject.updateScheduleLayouts = /*#__PURE__*/function () {
76545
76723
  var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(scheduleLayouts) {
76546
- var inputLayoutIds, _iterator, _step, _step$value, layoutIndex, _layout, uniqueLayout, _i, _Object$keys, layoutId;
76724
+ var next;
76547
76725
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
76548
76726
  while (1) switch (_context9.prev = _context9.next) {
76549
76727
  case 0:
76550
- console.debug('XLR::updateScheduleLayouts > Updating schedule layouts . . .');
76551
- inputLayoutIds = [];
76552
- _iterator = _createForOfIteratorHelper(scheduleLayouts.entries());
76553
- try {
76554
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
76555
- _step$value = _slicedToArray(_step.value, 2), layoutIndex = _step$value[0], _layout = _step$value[1];
76556
- uniqueLayout = _layout;
76557
- uniqueLayout.index = layoutIndex;
76558
- uniqueLayout.id = _layout.layoutId;
76559
- this.uniqueLayouts[_layout.layoutId] = uniqueLayout;
76560
- inputLayoutIds.push(_layout.layoutId);
76561
- }
76562
- // Cross-check if we need to remove non-existing layouts based on inputLayouts
76563
- } catch (err) {
76564
- _iterator.e(err);
76565
- } finally {
76566
- _iterator.f();
76567
- }
76568
- for (_i = 0, _Object$keys = Object.keys(this.uniqueLayouts); _i < _Object$keys.length; _i++) {
76569
- layoutId = _Object$keys[_i];
76570
- if (!inputLayoutIds.includes(parseInt(layoutId))) {
76571
- delete this.uniqueLayouts[layoutId];
76572
- }
76728
+ console.debug('XLR::updateScheduleLayouts > Updating schedule layouts . . .', scheduleLayouts);
76729
+ next = new Map();
76730
+ if (!(scheduleLayouts.length === 0)) {
76731
+ _context9.next = 5;
76732
+ break;
76573
76733
  }
76734
+ this.uniqueLayouts = next;
76735
+ return _context9.abrupt("return");
76574
76736
  case 5:
76737
+ scheduleLayouts.forEach(function (_layout, layoutIndex) {
76738
+ next.set(String(_layout.layoutId), _objectSpread2(_objectSpread2({}, _layout), {}, {
76739
+ index: layoutIndex,
76740
+ id: _layout.layoutId
76741
+ }));
76742
+ });
76743
+ console.debug('XLR::updateScheduleLayouts > next unique layouts', Array.from(next).values());
76744
+ this.uniqueLayouts = next;
76745
+ case 8:
76575
76746
  case "end":
76576
76747
  return _context9.stop();
76577
76748
  }
@@ -76620,6 +76791,36 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76620
76791
  case 0:
76621
76792
  console.debug('>>>> XLR.debug XLR::updateLoop > Updating schedule loop . . .');
76622
76793
  this.inputLayouts = inputLayouts;
76794
+ // Guard against a splash-only update: uniqueLayouts has no entry for layoutId 0,
76795
+ // so parseLayouts() would return undefined current/next and prepareLayoutXlf()
76796
+ // would be called with undefined. Clean up any playing layouts and show splash directly.
76797
+ if (!(inputLayouts.length === 1 && inputLayouts[0].layoutId === 0)) {
76798
+ _context11.next = 14;
76799
+ break;
76800
+ }
76801
+ if (!(this.currentLayout && this.isLayoutInDOM(this.currentLayout.containerName, this.currentLayout.index))) {
76802
+ _context11.next = 8;
76803
+ break;
76804
+ }
76805
+ // Force all regions to complete immediately
76806
+ this.currentLayout.inLoop = false;
76807
+ _context11.next = 7;
76808
+ return this.currentLayout.finishAllRegions();
76809
+ case 7:
76810
+ this.currentLayout.removeLayout();
76811
+ case 8:
76812
+ if (this.nextLayout) {
76813
+ // Discard regardless of DOM presence: nextLayout may be preloaded with
76814
+ // DOM elements and video.js players but not yet attached to the screen container.
76815
+ this.nextLayout.discardLayout(exports.LayoutPlaybackType.NEXT);
76816
+ }
76817
+ this.currentLayout = undefined;
76818
+ this.nextLayout = undefined;
76819
+ _context11.next = 13;
76820
+ return this.playSchedules(this);
76821
+ case 13:
76822
+ return _context11.abrupt("return");
76823
+ case 14:
76623
76824
  playback = this.parseLayouts(true);
76624
76825
  isCurrentLayoutValid = isLayoutValid(this.inputLayouts, (_this$currentLayout = this.currentLayout) === null || _this$currentLayout === void 0 ? void 0 : _this$currentLayout.layoutId);
76625
76826
  if (this.isSspEnabled && this.currentLayoutId === -1) {
@@ -76628,7 +76829,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76628
76829
  if (!isCurrentLayoutValid && this.currentLayout) {
76629
76830
  this.currentLayout.emitter.emit('cancelled', this.currentLayout);
76630
76831
  }
76631
- console.debug('>>>>> XLR.debug XLR::updateLoop > uniqueLayouts', this.uniqueLayouts);
76832
+ console.debug('>>>>> XLR.debug XLR::updateLoop > uniqueLayouts', Array.from(this.uniqueLayouts.values()));
76632
76833
  console.debug('>>>>> XLR.debug XLR::updateLoop > inputLayouts', this.inputLayouts);
76633
76834
  console.debug('>>>>> XLR.debug XLR::updateLoop > isCurrentLayoutValid', isCurrentLayoutValid);
76634
76835
  console.debug('>>>>> XLR.debug XLR::updateLoop > currentLayout', this.currentLayout);
@@ -76656,86 +76857,86 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76656
76857
  };
76657
76858
  }();
76658
76859
  if (isCurrentLayoutValid) {
76659
- _context11.next = 55;
76860
+ _context11.next = 67;
76660
76861
  break;
76661
76862
  }
76662
76863
  if (!playback.hasDefaultOnly) {
76663
- _context11.next = 34;
76864
+ _context11.next = 46;
76664
76865
  break;
76665
76866
  }
76666
76867
  if (!(this.currentLayout && playback.currentLayout && this.currentLayout.layoutId !== playback.currentLayout.layoutId)) {
76667
- _context11.next = 20;
76868
+ _context11.next = 32;
76668
76869
  break;
76669
76870
  }
76670
76871
  this.currentLayout.inLoop = false;
76671
- _context11.next = 19;
76872
+ _context11.next = 31;
76672
76873
  return this.currentLayout.finishAllRegions();
76673
- case 19:
76874
+ case 31:
76674
76875
  this.currentLayout.removeLayout();
76675
- case 20:
76876
+ case 32:
76676
76877
  // Discard old nextLayout before replacing it — same as the
76677
76878
  // other two branches do, otherwise the prepared DOM element
76678
76879
  // and any video.js players are orphaned.
76679
76880
  if (this.nextLayout && this.isLayoutInDOM(this.nextLayout.containerName, this.nextLayout.index)) {
76680
76881
  this.nextLayout.discardLayout(exports.LayoutPlaybackType.NEXT);
76681
76882
  }
76682
- _context11.next = 23;
76883
+ _context11.next = 35;
76683
76884
  return this.prepareLayoutXlf(playback.currentLayout);
76684
- case 23:
76885
+ case 35:
76685
76886
  this.currentLayout = _context11.sent;
76686
76887
  this.currentLayoutId = this.currentLayout.layoutId;
76687
76888
  _context11.t0 = this;
76688
- _context11.next = 28;
76889
+ _context11.next = 40;
76689
76890
  return this.prepareLayoutXlf(playback.nextLayout);
76690
- case 28:
76891
+ case 40:
76691
76892
  _context11.t1 = _context11.sent;
76692
- _context11.next = 31;
76893
+ _context11.next = 43;
76693
76894
  return _context11.t0.prepareForSsp.call(_context11.t0, _context11.t1);
76694
- case 31:
76895
+ case 43:
76695
76896
  this.nextLayout = _context11.sent;
76696
- _context11.next = 51;
76897
+ _context11.next = 63;
76697
76898
  break;
76698
- case 34:
76899
+ case 46:
76699
76900
  if (!(this.currentLayout && this.isLayoutInDOM(this.currentLayout.containerName, this.currentLayout.index))) {
76700
- _context11.next = 39;
76901
+ _context11.next = 51;
76701
76902
  break;
76702
76903
  }
76703
76904
  this.currentLayout.inLoop = false;
76704
- _context11.next = 38;
76905
+ _context11.next = 50;
76705
76906
  return this.currentLayout.finishAllRegions();
76706
- case 38:
76907
+ case 50:
76707
76908
  this.currentLayout.removeLayout();
76708
- case 39:
76909
+ case 51:
76709
76910
  if (this.nextLayout && this.isLayoutInDOM(this.nextLayout.containerName, this.nextLayout.index)) {
76710
76911
  this.nextLayout.discardLayout(exports.LayoutPlaybackType.NEXT);
76711
76912
  }
76712
76913
  if (!playback.currentLayout) {
76713
- _context11.next = 43;
76914
+ _context11.next = 55;
76714
76915
  break;
76715
76916
  }
76716
- _context11.next = 43;
76917
+ _context11.next = 55;
76717
76918
  return prepareNewCurrentLayout();
76718
- case 43:
76919
+ case 55:
76719
76920
  if (!playback.nextLayout) {
76720
- _context11.next = 51;
76921
+ _context11.next = 63;
76721
76922
  break;
76722
76923
  }
76723
76924
  _context11.t2 = this;
76724
- _context11.next = 47;
76925
+ _context11.next = 59;
76725
76926
  return this.prepareLayoutXlf(playback.nextLayout);
76726
- case 47:
76927
+ case 59:
76727
76928
  _context11.t3 = _context11.sent;
76728
- _context11.next = 50;
76929
+ _context11.next = 62;
76729
76930
  return _context11.t2.prepareForSsp.call(_context11.t2, _context11.t3);
76730
- case 50:
76931
+ case 62:
76731
76932
  this.nextLayout = _context11.sent;
76732
- case 51:
76733
- _context11.next = 53;
76933
+ case 63:
76934
+ _context11.next = 65;
76734
76935
  return this.playSchedules(this);
76735
- case 53:
76736
- _context11.next = 67;
76936
+ case 65:
76937
+ _context11.next = 79;
76737
76938
  break;
76738
- case 55:
76939
+ case 67:
76739
76940
  // Remove next layout if it is in the DOM
76740
76941
  if (this.nextLayout && this.isLayoutInDOM(this.nextLayout.containerName, this.nextLayout.index)) {
76741
76942
  this.nextLayout.discardLayout(exports.LayoutPlaybackType.NEXT);
@@ -76762,22 +76963,22 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76762
76963
  // nextLayout keeps the cycle in order; the slot after that will be
76763
76964
  // prepared by the normal prepareLayouts() call at transition time.
76764
76965
  if (!playback.currentLayout) {
76765
- _context11.next = 66;
76966
+ _context11.next = 78;
76766
76967
  break;
76767
76968
  }
76768
76969
  this.currentLayoutIndex = playback.currentLayoutIndex;
76769
76970
  _context11.t4 = this;
76770
- _context11.next = 62;
76971
+ _context11.next = 74;
76771
76972
  return this.prepareLayoutXlf(playback.currentLayout);
76772
- case 62:
76973
+ case 74:
76773
76974
  _context11.t5 = _context11.sent;
76774
- _context11.next = 65;
76975
+ _context11.next = 77;
76775
76976
  return _context11.t4.prepareForSsp.call(_context11.t4, _context11.t5);
76776
- case 65:
76977
+ case 77:
76777
76978
  this.nextLayout = _context11.sent;
76778
- case 66:
76979
+ case 78:
76779
76980
  console.debug('>>>> XLR.debug XLR::updateLoop > updated nextLayout', this.nextLayout);
76780
- case 67:
76981
+ case 79:
76781
76982
  case "end":
76782
76983
  return _context11.stop();
76783
76984
  }
@@ -76807,7 +77008,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76807
77008
  };
76808
77009
  }();
76809
77010
  xlrObject.parseLayouts = function (hasChanged) {
76810
- var _this$currentLayout2, _this$currentLayout3;
77011
+ var _this$currentLayout2, _this$currentLayout3, _this$currentLayout4, _this$nextLayout, _currentLayout2, _nextLayout2;
76811
77012
  var _currentLayout;
76812
77013
  var _nextLayout;
76813
77014
  var _hasDefaultOnly = hasDefaultOnly(this.inputLayouts);
@@ -76820,17 +77021,28 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76820
77021
  if (this.isSspEnabled && ((_this$currentLayout3 = this.currentLayout) === null || _this$currentLayout3 === void 0 ? void 0 : _this$currentLayout3.layoutId) === -1) {
76821
77022
  isCurrentLayoutValid = true;
76822
77023
  }
77024
+ console.debug('XLR::parseLayouts', {
77025
+ currentLayoutId: (_this$currentLayout4 = this.currentLayout) === null || _this$currentLayout4 === void 0 ? void 0 : _this$currentLayout4.layoutId,
77026
+ currentLayoutIndex: this.currentLayoutIndex,
77027
+ nextLayoutId: (_this$nextLayout = this.nextLayout) === null || _this$nextLayout === void 0 ? void 0 : _this$nextLayout.layoutId,
77028
+ isCurrentLayoutValid: isCurrentLayoutValid,
77029
+ hasChanged: !!hasChanged,
77030
+ inputLayoutsCount: this.inputLayouts.length,
77031
+ inputLayoutIds: this.inputLayouts.map(function (l) {
77032
+ return l.layoutId;
77033
+ }).join(', ')
77034
+ });
76823
77035
  _currentLayout = this.currentLayout;
76824
77036
  if (this.currentLayout && this.nextLayout) {
76825
77037
  // Both currentLayout and nextLayout has values
76826
77038
  if (hasLayout) {
76827
77039
  if (!isCurrentLayoutValid) {
76828
- var _this$nextLayout;
77040
+ var _this$nextLayout2;
76829
77041
  // Check if currentLayout.state is PLAYED,
76830
77042
  // then, validate nextLayout and if valid,
76831
77043
  // proceed to nextLayout as new currentLayout
76832
77044
  // Else, go back to first layout in the loop
76833
- if (this.currentLayout.state === exports.ELayoutState.PLAYED && isLayoutValid(this.inputLayouts, (_this$nextLayout = this.nextLayout) === null || _this$nextLayout === void 0 ? void 0 : _this$nextLayout.layoutId)) {
77045
+ if (this.currentLayout.state === exports.ELayoutState.PLAYED && isLayoutValid(this.inputLayouts, (_this$nextLayout2 = this.nextLayout) === null || _this$nextLayout2 === void 0 ? void 0 : _this$nextLayout2.layoutId)) {
76834
77046
  // Get nextLayout from updated loop
76835
77047
  var tempNextLayoutIndex = getLayoutIndexByLayoutId(this.inputLayouts, this.nextLayout.layoutId);
76836
77048
  _currentLayoutIndex = tempNextLayoutIndex !== null && tempNextLayoutIndex !== void 0 ? tempNextLayoutIndex : 0;
@@ -76874,7 +77086,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76874
77086
  _nextLayout = setLayoutIndex(_nextLayout, _nextLayoutIndex);
76875
77087
  }
76876
77088
  } else {
76877
- var _this$currentLayout4, _this$currentLayout5;
77089
+ var _this$currentLayout5, _this$currentLayout6;
76878
77090
  _currentLayout = this.nextLayout;
76879
77091
  _currentLayoutIndex = _currentLayout.index;
76880
77092
  // updateLoop can re-queue the same index that is currently
@@ -76884,7 +77096,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76884
77096
  // whether the queued next-to-current is at the same index as the
76885
77097
  // layout that just finished, and advance past it so the following
76886
77098
  // slot (e.g. an SSP that now has an ad) becomes current instead.
76887
- if (this.inputLayouts.length > 1 && (_this$currentLayout4 = this.currentLayout) !== null && _this$currentLayout4 !== void 0 && _this$currentLayout4.done && _currentLayoutIndex === ((_this$currentLayout5 = this.currentLayout) === null || _this$currentLayout5 === void 0 ? void 0 : _this$currentLayout5.index)) {
77099
+ if (this.inputLayouts.length > 1 && (_this$currentLayout5 = this.currentLayout) !== null && _this$currentLayout5 !== void 0 && _this$currentLayout5.done && _currentLayoutIndex === ((_this$currentLayout6 = this.currentLayout) === null || _this$currentLayout6 === void 0 ? void 0 : _this$currentLayout6.index)) {
76888
77100
  _currentLayoutIndex = (_currentLayoutIndex + 1) % this.inputLayouts.length;
76889
77101
  _currentLayout = this.getLayout(this.inputLayouts[_currentLayoutIndex]);
76890
77102
  _currentLayout = setLayoutIndex(_currentLayout, _currentLayoutIndex);
@@ -76921,6 +77133,12 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76921
77133
  _currentLayout.xlr = this;
76922
77134
  _nextLayout.xlr = this;
76923
77135
  }
77136
+ console.debug('XLR::parseLayouts result', {
77137
+ currentLayoutId: (_currentLayout2 = _currentLayout) === null || _currentLayout2 === void 0 ? void 0 : _currentLayout2.layoutId,
77138
+ currentLayoutIndex: _currentLayoutIndex,
77139
+ nextLayoutId: (_nextLayout2 = _nextLayout) === null || _nextLayout2 === void 0 ? void 0 : _nextLayout2.layoutId,
77140
+ nextLayoutIndex: _nextLayoutIndex
77141
+ });
76924
77142
  return {
76925
77143
  currentLayout: _currentLayout,
76926
77144
  nextLayout: _nextLayout,
@@ -76932,7 +77150,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76932
77150
  };
76933
77151
  xlrObject.getLayout = function (inputLayout) {
76934
77152
  var isCMS = this.config.platform === exports.ConsumerPlatform.CMS;
76935
- if (!isCMS && Object.keys(this.uniqueLayouts).length === 0) {
77153
+ if (!isCMS && this.uniqueLayouts.size === 0) {
76936
77154
  return;
76937
77155
  }
76938
77156
  var _layout = {};
@@ -76949,7 +77167,13 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76949
77167
  activeLayout.id = activeLayout.layoutId;
76950
77168
  }
76951
77169
  } else {
76952
- activeLayout = _objectSpread2({}, this.uniqueLayouts[inputLayout.layoutId]);
77170
+ var layoutFromUniqueLayouts = this.uniqueLayouts.get(String(inputLayout.layoutId));
77171
+ console.debug('XLR::getLayout > layoutFromUniqueLayouts', {
77172
+ layoutFromUniqueLayouts: layoutFromUniqueLayouts,
77173
+ inputLayout: inputLayout,
77174
+ uniqueLayouts: this.uniqueLayouts
77175
+ });
77176
+ activeLayout = layoutFromUniqueLayouts ? _objectSpread2({}, layoutFromUniqueLayouts) : _objectSpread2({}, inputLayout);
76953
77177
  }
76954
77178
  _layout = _objectSpread2(_objectSpread2({}, _layout), activeLayout);
76955
77179
  console.debug('XLR::getLayout > activeLayout from uniqueLayouts', {
@@ -76966,10 +77190,10 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76966
77190
  return iLayout;
76967
77191
  };
76968
77192
  xlrObject.getLayoutById = function (layoutId, layoutIndex) {
76969
- if (!layoutId || Object.keys(this.uniqueLayouts).length === 0) {
77193
+ if (!layoutId || this.uniqueLayouts.size === 0 || !this.uniqueLayouts.has(String(layoutId))) {
76970
77194
  return undefined;
76971
77195
  }
76972
- var _layout = _objectSpread2(_objectSpread2({}, initialLayout), this.uniqueLayouts[layoutId]);
77196
+ var _layout = _objectSpread2(_objectSpread2({}, initialLayout), this.uniqueLayouts.get(String(layoutId)));
76973
77197
  // Set layout index if available
76974
77198
  if (layoutIndex) {
76975
77199
  _layout.index = layoutIndex;
@@ -76977,71 +77201,79 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
76977
77201
  return _layout;
76978
77202
  };
76979
77203
  xlrObject.prepareLayouts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
76980
- var _layoutPlayback$curre, _layoutPlayback$curre2;
77204
+ var _layoutPlayback$curre, _layoutPlayback$nextL, _layoutPlayback$curre2, _layoutPlayback$curre3, _layouts$, _layouts$2, _layouts$3, _layouts$4;
76981
77205
  var self, layoutPlayback, currentLayoutXlf, wasCurrentReused, nextLayoutXlf, layouts;
76982
77206
  return _regeneratorRuntime().wrap(function _callee14$(_context14) {
76983
77207
  while (1) switch (_context14.prev = _context14.next) {
76984
77208
  case 0:
76985
77209
  self = xlrObject;
76986
77210
  if (!this.isUpdatingLoop) {
76987
- _context14.next = 3;
77211
+ _context14.next = 4;
76988
77212
  break;
76989
77213
  }
77214
+ console.debug('XLR::prepareLayouts - skipped (isUpdatingLoop)');
76990
77215
  return _context14.abrupt("return", Promise.resolve(self));
76991
- case 3:
77216
+ case 4:
76992
77217
  layoutPlayback = self.parseLayouts(); // Don't prepare layout if it's just the splash screen
76993
77218
  if (!(self.inputLayouts.length === 1 && self.inputLayouts[0].layoutId === 0)) {
76994
- _context14.next = 6;
77219
+ _context14.next = 8;
76995
77220
  break;
76996
77221
  }
77222
+ console.debug('XLR::prepareLayouts - skipped (splash screen only)');
76997
77223
  return _context14.abrupt("return", Promise.resolve(self));
76998
- case 6:
76999
- console.debug('??? XLR.debug prepareLayouts::playback', {
77000
- layoutPlayback: layoutPlayback,
77001
- shouldParse: false
77224
+ case 8:
77225
+ console.debug('XLR::prepareLayouts', {
77226
+ currentLayoutId: (_layoutPlayback$curre = layoutPlayback.currentLayout) === null || _layoutPlayback$curre === void 0 ? void 0 : _layoutPlayback$curre.layoutId,
77227
+ currentLayoutIndex: layoutPlayback.currentLayoutIndex,
77228
+ nextLayoutId: (_layoutPlayback$nextL = layoutPlayback.nextLayout) === null || _layoutPlayback$nextL === void 0 ? void 0 : _layoutPlayback$nextL.layoutId,
77229
+ nextLayoutIndex: layoutPlayback.nextLayoutIndex
77002
77230
  });
77003
- self.currentLayoutId = (_layoutPlayback$curre = layoutPlayback.currentLayout) === null || _layoutPlayback$curre === void 0 ? void 0 : _layoutPlayback$curre.layoutId;
77231
+ self.currentLayoutId = (_layoutPlayback$curre2 = layoutPlayback.currentLayout) === null || _layoutPlayback$curre2 === void 0 ? void 0 : _layoutPlayback$curre2.layoutId;
77004
77232
  // Only reuse the existing Layout instance if it is fully healthy —
77005
77233
  // a done=true instance was removed from the DOM (e.g. an SSP slot that
77006
77234
  // had no ad), and an empty-XLF instance has no regions so it can never
77007
77235
  // advance the cycle. In either case re-prepare from scratch so we get
77008
77236
  // a fresh request (which may now have a valid ad / XLF).
77009
- if (!((_layoutPlayback$curre2 = layoutPlayback.currentLayout) !== null && _layoutPlayback$curre2 !== void 0 && _layoutPlayback$curre2.layoutNode && !layoutPlayback.currentLayout.done && layoutPlayback.currentLayout.xlfString !== '')) {
77010
- _context14.next = 12;
77237
+ if (!((_layoutPlayback$curre3 = layoutPlayback.currentLayout) !== null && _layoutPlayback$curre3 !== void 0 && _layoutPlayback$curre3.layoutNode && !layoutPlayback.currentLayout.done && layoutPlayback.currentLayout.xlfString !== '')) {
77238
+ _context14.next = 14;
77011
77239
  break;
77012
77240
  }
77013
77241
  _context14.t0 = layoutPlayback.currentLayout;
77014
- _context14.next = 15;
77242
+ _context14.next = 17;
77015
77243
  break;
77016
- case 12:
77017
- _context14.next = 14;
77018
- return self.prepareLayoutXlf(layoutPlayback.currentLayout);
77019
77244
  case 14:
77245
+ _context14.next = 16;
77246
+ return self.prepareLayoutXlf(layoutPlayback.currentLayout);
77247
+ case 16:
77020
77248
  _context14.t0 = _context14.sent;
77021
- case 15:
77249
+ case 17:
77022
77250
  currentLayoutXlf = _context14.t0;
77023
77251
  // True when the same object was returned (reused); false when a fresh
77024
77252
  // Layout was constructed by prepareLayoutXlf above.
77025
77253
  wasCurrentReused = currentLayoutXlf === layoutPlayback.currentLayout;
77026
- _context14.next = 19;
77254
+ _context14.next = 21;
77027
77255
  return self.prepareLayoutXlf(layoutPlayback.nextLayout);
77028
- case 19:
77256
+ case 21:
77029
77257
  nextLayoutXlf = _context14.sent;
77030
77258
  _context14.t1 = Promise;
77031
77259
  _context14.t2 = currentLayoutXlf;
77032
- _context14.next = 24;
77260
+ _context14.next = 26;
77033
77261
  return self.prepareForSsp(nextLayoutXlf);
77034
- case 24:
77262
+ case 26:
77035
77263
  _context14.t3 = _context14.sent;
77036
77264
  _context14.t4 = [_context14.t2, _context14.t3];
77037
- _context14.next = 28;
77265
+ _context14.next = 30;
77038
77266
  return _context14.t1.all.call(_context14.t1, _context14.t4);
77039
- case 28:
77267
+ case 30:
77040
77268
  layouts = _context14.sent;
77041
77269
  if (!(self.isUpdatingLoop || layouts[0].done)) {
77042
- _context14.next = 33;
77270
+ _context14.next = 36;
77043
77271
  break;
77044
77272
  }
77273
+ console.debug('XLR::prepareLayouts - aborted (concurrent updateLoop)', {
77274
+ isUpdatingLoop: self.isUpdatingLoop,
77275
+ currentLayoutDone: layouts[0].done
77276
+ });
77045
77277
  // If currentLayout was freshly prepared (not reused from nextLayout),
77046
77278
  // its DOM element was just appended — discard it now so it does not
77047
77279
  // accumulate in screen_container. Also disposes any video.js players
@@ -77053,8 +77285,14 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
77053
77285
  nextLayoutXlf.discardLayout(exports.LayoutPlaybackType.NEXT);
77054
77286
  }
77055
77287
  return _context14.abrupt("return", Promise.resolve(self));
77056
- case 33:
77057
- console.debug('>>>>> XLR.debug prepared layout XLF', layouts);
77288
+ case 36:
77289
+ console.debug('XLR::prepareLayouts - layouts prepared', {
77290
+ currentLayoutId: (_layouts$ = layouts[0]) === null || _layouts$ === void 0 ? void 0 : _layouts$.layoutId,
77291
+ currentLayoutIndex: (_layouts$2 = layouts[0]) === null || _layouts$2 === void 0 ? void 0 : _layouts$2.index,
77292
+ nextLayoutId: (_layouts$3 = layouts[1]) === null || _layouts$3 === void 0 ? void 0 : _layouts$3.layoutId,
77293
+ nextLayoutIndex: (_layouts$4 = layouts[1]) === null || _layouts$4 === void 0 ? void 0 : _layouts$4.index,
77294
+ currentReused: wasCurrentReused
77295
+ });
77058
77296
  return _context14.abrupt("return", new Promise( /*#__PURE__*/function () {
77059
77297
  var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(resolve) {
77060
77298
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
@@ -77088,7 +77326,7 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
77088
77326
  return _ref14.apply(this, arguments);
77089
77327
  };
77090
77328
  }()));
77091
- case 35:
77329
+ case 38:
77092
77330
  case "end":
77093
77331
  return _context14.stop();
77094
77332
  }
@@ -77251,33 +77489,48 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
77251
77489
  return _ref16.apply(this, arguments);
77252
77490
  };
77253
77491
  }();
77492
+ // Shared re-entry guard for all layout navigation methods.
77493
+ // Prevents a double-tap from advancing two layouts at once.
77494
+ var isNavigatingLayout = false;
77254
77495
  xlrObject.gotoPrevLayout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
77255
77496
  var _this4 = this;
77256
- var _currentLayoutIndex, _assumedPrevIndex, _this$currentLayout6;
77497
+ var _currentLayoutIndex, _assumedPrevIndex, _this$currentLayout7;
77257
77498
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
77258
77499
  while (1) switch (_context18.prev = _context18.next) {
77259
77500
  case 0:
77501
+ if (!isNavigatingLayout) {
77502
+ _context18.next = 2;
77503
+ break;
77504
+ }
77505
+ return _context18.abrupt("return");
77506
+ case 2:
77507
+ isNavigatingLayout = true;
77508
+ _context18.prev = 3;
77260
77509
  _currentLayoutIndex = this.currentLayoutIndex;
77261
77510
  _assumedPrevIndex = _currentLayoutIndex - 1; // If previous layout is same as current layout or
77262
77511
  // if there's only one layout, do nothing
77263
77512
  if (!(_assumedPrevIndex < 0)) {
77264
- _context18.next = 4;
77513
+ _context18.next = 8;
77265
77514
  break;
77266
77515
  }
77267
77516
  return _context18.abrupt("return");
77268
- case 4:
77517
+ case 8:
77269
77518
  console.debug('XLR::gotoPrevLayout', {
77270
- previousLayoutIndex: _assumedPrevIndex,
77271
- method: 'XLR::gotoPrevLayout',
77272
- shouldParse: false
77519
+ previousLayoutIndex: _assumedPrevIndex
77273
77520
  });
77274
77521
  if (!Boolean(this.inputLayouts[_assumedPrevIndex])) {
77275
- _context18.next = 10;
77522
+ _context18.next = 15;
77276
77523
  break;
77277
77524
  }
77278
- _context18.next = 8;
77279
- return (_this$currentLayout6 = this.currentLayout) === null || _this$currentLayout6 === void 0 ? void 0 : _this$currentLayout6.finishAllRegions();
77280
- case 8:
77525
+ // Prevent the natural layout-end handler from also calling
77526
+ // prepareLayouts() when finishAllRegions() causes the layout
77527
+ // 'end' event to fire.
77528
+ if (this.currentLayout) {
77529
+ this.currentLayout.inLoop = false;
77530
+ }
77531
+ _context18.next = 13;
77532
+ return (_this$currentLayout7 = this.currentLayout) === null || _this$currentLayout7 === void 0 ? void 0 : _this$currentLayout7.finishAllRegions();
77533
+ case 13:
77281
77534
  // and set the previous layout as current layout
77282
77535
  this.currentLayoutIndex = _assumedPrevIndex;
77283
77536
  this.prepareLayouts().then( /*#__PURE__*/function () {
@@ -77297,30 +77550,366 @@ ${segmentInfoString(segmentInfo)}`); // If there's an init segment associated wi
77297
77550
  return _ref18.apply(this, arguments);
77298
77551
  };
77299
77552
  }());
77300
- case 10:
77553
+ case 15:
77554
+ _context18.prev = 15;
77555
+ isNavigatingLayout = false;
77556
+ return _context18.finish(15);
77557
+ case 18:
77301
77558
  case "end":
77302
77559
  return _context18.stop();
77303
77560
  }
77304
- }, _callee18, this);
77561
+ }, _callee18, this, [[3,, 15, 18]]);
77305
77562
  }));
77306
- xlrObject.gotoNextLayout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
77307
- var _xlrObject$currentLay2;
77308
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
77309
- while (1) switch (_context19.prev = _context19.next) {
77563
+ xlrObject.gotoNextLayout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
77564
+ var _this5 = this;
77565
+ var _this$currentLayout8, nextIndex;
77566
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
77567
+ while (1) switch (_context20.prev = _context20.next) {
77310
77568
  case 0:
77569
+ if (!isNavigatingLayout) {
77570
+ _context20.next = 2;
77571
+ break;
77572
+ }
77573
+ return _context20.abrupt("return");
77574
+ case 2:
77575
+ isNavigatingLayout = true;
77576
+ _context20.prev = 3;
77577
+ nextIndex = this.currentLayoutIndex + 1;
77578
+ if (Boolean(this.inputLayouts[nextIndex])) {
77579
+ _context20.next = 7;
77580
+ break;
77581
+ }
77582
+ return _context20.abrupt("return");
77583
+ case 7:
77311
77584
  console.debug('XLR::gotoNextLayout', {
77312
- nextLayoutIndex: this.currentLayoutIndex + 1,
77313
- method: 'XLR::gotoNextLayout',
77314
- shouldParse: false
77585
+ nextLayoutIndex: nextIndex
77315
77586
  });
77316
- _context19.next = 3;
77317
- return (_xlrObject$currentLay2 = xlrObject.currentLayout) === null || _xlrObject$currentLay2 === void 0 ? void 0 : _xlrObject$currentLay2.finishAllRegions();
77318
- case 3:
77587
+ if (this.currentLayout) {
77588
+ this.currentLayout.inLoop = false;
77589
+ }
77590
+ _context20.next = 11;
77591
+ return (_this$currentLayout8 = this.currentLayout) === null || _this$currentLayout8 === void 0 ? void 0 : _this$currentLayout8.finishAllRegions();
77592
+ case 11:
77593
+ this.currentLayoutIndex = nextIndex;
77594
+ this.prepareLayouts().then( /*#__PURE__*/function () {
77595
+ var _ref20 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(xlr) {
77596
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
77597
+ while (1) switch (_context19.prev = _context19.next) {
77598
+ case 0:
77599
+ _context19.next = 2;
77600
+ return _this5.playSchedules(xlr);
77601
+ case 2:
77602
+ case "end":
77603
+ return _context19.stop();
77604
+ }
77605
+ }, _callee19);
77606
+ }));
77607
+ return function (_x14) {
77608
+ return _ref20.apply(this, arguments);
77609
+ };
77610
+ }());
77611
+ case 13:
77612
+ _context20.prev = 13;
77613
+ isNavigatingLayout = false;
77614
+ return _context20.finish(13);
77615
+ case 16:
77319
77616
  case "end":
77320
- return _context19.stop();
77617
+ return _context20.stop();
77321
77618
  }
77322
- }, _callee19, this);
77619
+ }, _callee20, this, [[3,, 13, 16]]);
77323
77620
  }));
77621
+ xlrObject.gotoLayoutByCode = /*#__PURE__*/function () {
77622
+ var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(layoutCode) {
77623
+ var _this6 = this;
77624
+ var _this$currentLayout9, targetIndex, parsedLayouts, _loop, _ret, _i, _parsedLayouts, parser, i, _inputLayout$getXlf, _doc$documentElement, inputLayout, xlfString, url, res, doc, foundCode;
77625
+ return _regeneratorRuntime().wrap(function _callee22$(_context23) {
77626
+ while (1) switch (_context23.prev = _context23.next) {
77627
+ case 0:
77628
+ if (!isNavigatingLayout) {
77629
+ _context23.next = 2;
77630
+ break;
77631
+ }
77632
+ return _context23.abrupt("return");
77633
+ case 2:
77634
+ isNavigatingLayout = true;
77635
+ _context23.prev = 3;
77636
+ targetIndex = -1; // 1. Check the two already-parsed layouts first (zero fetch cost)
77637
+ parsedLayouts = [this.layouts['current'], this.layouts['next']];
77638
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
77639
+ var _layout$layoutNode;
77640
+ var layout, code;
77641
+ return _regeneratorRuntime().wrap(function _loop$(_context21) {
77642
+ while (1) switch (_context21.prev = _context21.next) {
77643
+ case 0:
77644
+ layout = _parsedLayouts[_i];
77645
+ if (layout) {
77646
+ _context21.next = 3;
77647
+ break;
77648
+ }
77649
+ return _context21.abrupt("return", 0);
77650
+ case 3:
77651
+ code = (_layout$layoutNode = layout.layoutNode) === null || _layout$layoutNode === void 0 || (_layout$layoutNode = _layout$layoutNode.documentElement) === null || _layout$layoutNode === void 0 ? void 0 : _layout$layoutNode.getAttribute('code');
77652
+ if (!(code === layoutCode)) {
77653
+ _context21.next = 7;
77654
+ break;
77655
+ }
77656
+ targetIndex = _this6.inputLayouts.findIndex(function (i) {
77657
+ return i.layoutId === layout.layoutId;
77658
+ });
77659
+ return _context21.abrupt("return", 1);
77660
+ case 7:
77661
+ case "end":
77662
+ return _context21.stop();
77663
+ }
77664
+ }, _loop);
77665
+ });
77666
+ _i = 0, _parsedLayouts = parsedLayouts;
77667
+ case 8:
77668
+ if (!(_i < _parsedLayouts.length)) {
77669
+ _context23.next = 18;
77670
+ break;
77671
+ }
77672
+ return _context23.delegateYield(_loop(), "t0", 10);
77673
+ case 10:
77674
+ _ret = _context23.t0;
77675
+ if (!(_ret === 0)) {
77676
+ _context23.next = 13;
77677
+ break;
77678
+ }
77679
+ return _context23.abrupt("continue", 15);
77680
+ case 13:
77681
+ if (!(_ret === 1)) {
77682
+ _context23.next = 15;
77683
+ break;
77684
+ }
77685
+ return _context23.abrupt("break", 18);
77686
+ case 15:
77687
+ _i++;
77688
+ _context23.next = 8;
77689
+ break;
77690
+ case 18:
77691
+ if (!(targetIndex === -1)) {
77692
+ _context23.next = 60;
77693
+ break;
77694
+ }
77695
+ parser = new DOMParser();
77696
+ i = 0;
77697
+ case 21:
77698
+ if (!(i < this.inputLayouts.length)) {
77699
+ _context23.next = 60;
77700
+ break;
77701
+ }
77702
+ inputLayout = this.inputLayouts[i]; // Fast check: code pre-populated by the player (no fetch needed)
77703
+ if (!(inputLayout.code !== undefined)) {
77704
+ _context23.next = 28;
77705
+ break;
77706
+ }
77707
+ if (!(inputLayout.code === layoutCode)) {
77708
+ _context23.next = 27;
77709
+ break;
77710
+ }
77711
+ targetIndex = i;
77712
+ return _context23.abrupt("break", 60);
77713
+ case 27:
77714
+ return _context23.abrupt("continue", 57);
77715
+ case 28:
77716
+ xlfString = void 0; // Prefer getXlf() when available (e.g. CMS platform)
77717
+ xlfString = (_inputLayout$getXlf = inputLayout.getXlf) === null || _inputLayout$getXlf === void 0 ? void 0 : _inputLayout$getXlf.call(inputLayout);
77718
+ // Otherwise fetch from the local file server (Electron / ChromeOS)
77719
+ if (!(!xlfString && this.config.appHost && inputLayout.path)) {
77720
+ _context23.next = 49;
77721
+ break;
77722
+ }
77723
+ url = this.config.appHost + inputLayout.path;
77724
+ console.debug('[gotoLayoutByCode] Fetching XLF for layoutId', inputLayout.layoutId, url);
77725
+ _context23.prev = 33;
77726
+ _context23.next = 36;
77727
+ return fetch(url);
77728
+ case 36:
77729
+ res = _context23.sent;
77730
+ if (res.ok) {
77731
+ _context23.next = 40;
77732
+ break;
77733
+ }
77734
+ console.debug('[gotoLayoutByCode] Fetch non-OK', res.status, url);
77735
+ return _context23.abrupt("continue", 57);
77736
+ case 40:
77737
+ _context23.next = 42;
77738
+ return res.text();
77739
+ case 42:
77740
+ xlfString = _context23.sent;
77741
+ _context23.next = 49;
77742
+ break;
77743
+ case 45:
77744
+ _context23.prev = 45;
77745
+ _context23.t1 = _context23["catch"](33);
77746
+ console.debug('[gotoLayoutByCode] Fetch error for', url, _context23.t1);
77747
+ return _context23.abrupt("continue", 57);
77748
+ case 49:
77749
+ if (xlfString) {
77750
+ _context23.next = 52;
77751
+ break;
77752
+ }
77753
+ console.debug('[gotoLayoutByCode] No XLF for layoutId', inputLayout.layoutId, 'path:', inputLayout.path);
77754
+ return _context23.abrupt("continue", 57);
77755
+ case 52:
77756
+ doc = parser.parseFromString(xlfString, 'text/xml');
77757
+ foundCode = (_doc$documentElement = doc.documentElement) === null || _doc$documentElement === void 0 ? void 0 : _doc$documentElement.getAttribute('code');
77758
+ if (!(foundCode === layoutCode)) {
77759
+ _context23.next = 57;
77760
+ break;
77761
+ }
77762
+ targetIndex = i;
77763
+ return _context23.abrupt("break", 60);
77764
+ case 57:
77765
+ i++;
77766
+ _context23.next = 21;
77767
+ break;
77768
+ case 60:
77769
+ if (!(targetIndex === -1)) {
77770
+ _context23.next = 63;
77771
+ break;
77772
+ }
77773
+ console.warn('XLR::gotoLayoutByCode - layout not found for code:', layoutCode);
77774
+ return _context23.abrupt("return");
77775
+ case 63:
77776
+ console.debug('XLR::gotoLayoutByCode', {
77777
+ layoutCode: layoutCode,
77778
+ targetIndex: targetIndex
77779
+ });
77780
+ // Prevent the natural layout-end handler from racing with our own
77781
+ // prepareLayouts() call (same pattern as gotoPrevLayout/gotoNextLayout).
77782
+ if (this.currentLayout) {
77783
+ this.currentLayout.inLoop = false;
77784
+ }
77785
+ _context23.next = 67;
77786
+ return (_this$currentLayout9 = this.currentLayout) === null || _this$currentLayout9 === void 0 ? void 0 : _this$currentLayout9.finishAllRegions();
77787
+ case 67:
77788
+ this.currentLayoutIndex = targetIndex;
77789
+ this.prepareLayouts().then( /*#__PURE__*/function () {
77790
+ var _ref22 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(xlr) {
77791
+ return _regeneratorRuntime().wrap(function _callee21$(_context22) {
77792
+ while (1) switch (_context22.prev = _context22.next) {
77793
+ case 0:
77794
+ _context22.next = 2;
77795
+ return _this6.playSchedules(xlr);
77796
+ case 2:
77797
+ case "end":
77798
+ return _context22.stop();
77799
+ }
77800
+ }, _callee21);
77801
+ }));
77802
+ return function (_x16) {
77803
+ return _ref22.apply(this, arguments);
77804
+ };
77805
+ }());
77806
+ case 69:
77807
+ _context23.prev = 69;
77808
+ isNavigatingLayout = false;
77809
+ return _context23.finish(69);
77810
+ case 72:
77811
+ case "end":
77812
+ return _context23.stop();
77813
+ }
77814
+ }, _callee22, this, [[3,, 69, 72], [33, 45]]);
77815
+ }));
77816
+ return function (_x15) {
77817
+ return _ref21.apply(this, arguments);
77818
+ };
77819
+ }();
77820
+ xlrObject.playInterruptLayout = /*#__PURE__*/function () {
77821
+ var _ref23 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(inputLayout) {
77822
+ var _this7 = this;
77823
+ var _this$currentLayout10, _this$currentLayout11, resumeIndex, savedNextLayout, interruptKey, wasInUniqueLayouts, interruptILayout, cleanup;
77824
+ return _regeneratorRuntime().wrap(function _callee23$(_context24) {
77825
+ while (1) switch (_context24.prev = _context24.next) {
77826
+ case 0:
77827
+ if (!isNavigatingLayout) {
77828
+ _context24.next = 2;
77829
+ break;
77830
+ }
77831
+ return _context24.abrupt("return");
77832
+ case 2:
77833
+ isNavigatingLayout = true;
77834
+ _context24.prev = 3;
77835
+ resumeIndex = this.currentLayoutIndex; // Save B (the layout that was queued to play after A) before stopping A.
77836
+ // After the interrupt ends, parseLayouts() will use this to resume the loop.
77837
+ savedNextLayout = this.nextLayout;
77838
+ console.debug('[navLayout] XLR::playInterruptLayout - Starting interrupt', {
77839
+ interruptLayoutId: inputLayout.layoutId,
77840
+ resumeIndex: resumeIndex,
77841
+ currentLayoutId: (_this$currentLayout10 = this.currentLayout) === null || _this$currentLayout10 === void 0 ? void 0 : _this$currentLayout10.layoutId,
77842
+ resumeNextLayoutId: savedNextLayout === null || savedNextLayout === void 0 ? void 0 : savedNextLayout.layoutId
77843
+ });
77844
+ // Prevent A's end handler from calling prepareLayouts (we take over).
77845
+ if (this.currentLayout) {
77846
+ this.currentLayout.inLoop = false;
77847
+ }
77848
+ _context24.next = 10;
77849
+ return (_this$currentLayout11 = this.currentLayout) === null || _this$currentLayout11 === void 0 ? void 0 : _this$currentLayout11.finishAllRegions();
77850
+ case 10:
77851
+ // Register interrupt in uniqueLayouts so getLayout()/prepareLayoutXlf() resolve it.
77852
+ // Do NOT splice into inputLayouts — keeping the original loop intact means
77853
+ // parseLayouts() will see the interrupt as "not in loop" (isCurrentLayoutValid=false)
77854
+ // after it ends, and will correctly advance to savedNextLayout (B).
77855
+ interruptKey = String(inputLayout.layoutId);
77856
+ wasInUniqueLayouts = this.uniqueLayouts.has(interruptKey);
77857
+ if (!wasInUniqueLayouts) {
77858
+ this.uniqueLayouts.set(interruptKey, _objectSpread2(_objectSpread2({}, inputLayout), {}, {
77859
+ index: resumeIndex,
77860
+ id: inputLayout.layoutId
77861
+ }));
77862
+ }
77863
+ // Prepare the interrupt ILayout (fetches XLF, builds regions).
77864
+ _context24.next = 15;
77865
+ return this.prepareLayoutXlf(this.getLayout(inputLayout));
77866
+ case 15:
77867
+ interruptILayout = _context24.sent;
77868
+ // Wire into XLR so playLayouts picks up the interrupt as current.
77869
+ // inLoop=true lets the interrupt's own end handler call prepareLayouts normally.
77870
+ interruptILayout.inLoop = true;
77871
+ this.layouts.current = interruptILayout;
77872
+ this.currentLayout = interruptILayout;
77873
+ this.currentLayoutId = interruptILayout.layoutId;
77874
+ // Restore nextLayout to B so after the interrupt ends, parseLayouts() resumes
77875
+ // the original loop from B (since interrupt.layoutId is not in inputLayouts,
77876
+ // parseLayouts sees it as invalid and advances to nextLayout).
77877
+ if (savedNextLayout) {
77878
+ this.layouts.next = savedNextLayout;
77879
+ this.nextLayout = savedNextLayout;
77880
+ }
77881
+ // Remove interrupt from uniqueLayouts once it ends.
77882
+ cleanup = this.emitter.on('layoutEnd', function (endedLayout) {
77883
+ if (endedLayout !== interruptILayout) return;
77884
+ cleanup();
77885
+ if (!wasInUniqueLayouts) {
77886
+ _this7.uniqueLayouts["delete"](interruptKey);
77887
+ }
77888
+ console.debug('[navLayout] XLR::playInterruptLayout - Interrupt ended, resuming loop', {
77889
+ interruptLayoutId: inputLayout.layoutId,
77890
+ resumeNextLayoutId: savedNextLayout === null || savedNextLayout === void 0 ? void 0 : savedNextLayout.layoutId
77891
+ });
77892
+ });
77893
+ _context24.next = 24;
77894
+ return this.playSchedules(xlrObject);
77895
+ case 24:
77896
+ _context24.prev = 24;
77897
+ isNavigatingLayout = false;
77898
+ return _context24.finish(24);
77899
+ case 27:
77900
+ case "end":
77901
+ return _context24.stop();
77902
+ }
77903
+ }, _callee23, this, [[3,, 24, 27]]);
77904
+ }));
77905
+ return function (_x17) {
77906
+ return _ref23.apply(this, arguments);
77907
+ };
77908
+ }();
77909
+ xlrObject.triggerAction = function (triggerCode, widgetId) {
77910
+ var _this$currentLayout12;
77911
+ (_this$currentLayout12 = this.currentLayout) === null || _this$currentLayout12 === void 0 || (_this$currentLayout12 = _this$currentLayout12.actionController) === null || _this$currentLayout12 === void 0 || _this$currentLayout12.handleWebhookTrigger(triggerCode, widgetId);
77912
+ };
77324
77913
  xlrObject.updateInputLayout = function (layoutIndex, layout) {
77325
77914
  var xlrInputLayout = this.inputLayouts[layoutIndex];
77326
77915
  if (layout !== null) {