@xibosignage/xibo-layout-renderer 1.0.5 → 1.0.6

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.
@@ -1,9 +1,12 @@
1
- import { Unsubscribe, Emitter, DefaultEvents } from 'nanoevents';
1
+ import { Emitter, Unsubscribe, DefaultEvents } from 'nanoevents';
2
2
 
3
3
  declare enum ELayoutType {
4
4
  CURRENT = 0,
5
5
  NEXT = 1
6
6
  }
7
+ type IXlrEvents = {
8
+ layoutChange: (layoutId: number) => void;
9
+ };
7
10
  interface IXlr {
8
11
  inputLayouts: InputLayoutType[];
9
12
  config: OptionsType;
@@ -12,6 +15,7 @@ interface IXlr {
12
15
  currentLayoutId: number | null;
13
16
  currentLayout: ILayout | undefined;
14
17
  nextLayout: ILayout | undefined;
18
+ emitter: Emitter<IXlrEvents>;
15
19
  bootstrap(): void;
16
20
  init(): Promise<IXlr>;
17
21
  playSchedules(xlr: IXlr): void;
@@ -71379,6 +71379,7 @@ var initialXlr = {
71379
71379
  currentLayoutId: null,
71380
71380
  currentLayout: undefined,
71381
71381
  nextLayout: undefined,
71382
+ emitter: {},
71382
71383
  bootstrap: function bootstrap() {},
71383
71384
  init: function init() {
71384
71385
  return Promise.resolve({});
@@ -71467,6 +71468,39 @@ function XiboLayoutRenderer(inputLayouts, options) {
71467
71468
  options: options
71468
71469
  };
71469
71470
  var xlrObject = _objectSpread2({}, initialXlr);
71471
+ var emitter = createNanoEvents();
71472
+ xlrObject.emitter = emitter;
71473
+ xlrObject.emitter.on('layoutChange', /*#__PURE__*/function () {
71474
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(layoutId) {
71475
+ var _xlrObject$nextLayout, _targetLayout, _targetLayout2;
71476
+ var targetLayout;
71477
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
71478
+ while (1) switch (_context.prev = _context.next) {
71479
+ case 0:
71480
+ if (layoutId === ((_xlrObject$nextLayout = xlrObject.nextLayout) === null || _xlrObject$nextLayout === void 0 ? void 0 : _xlrObject$nextLayout.layoutId)) {
71481
+ targetLayout = {
71482
+ layout: xlrObject.nextLayout,
71483
+ pos: ELayoutType.NEXT
71484
+ };
71485
+ }
71486
+ if (!((_targetLayout = targetLayout) !== null && _targetLayout !== void 0 && _targetLayout.layout && (_targetLayout2 = targetLayout) !== null && _targetLayout2 !== void 0 && _targetLayout2.pos)) {
71487
+ _context.next = 5;
71488
+ break;
71489
+ }
71490
+ _context.next = 4;
71491
+ return xlrObject.prepareLayoutXlf(xlrObject.nextLayout);
71492
+ case 4:
71493
+ xlrObject.nextLayout = _context.sent;
71494
+ case 5:
71495
+ case "end":
71496
+ return _context.stop();
71497
+ }
71498
+ }, _callee);
71499
+ }));
71500
+ return function (_x) {
71501
+ return _ref.apply(this, arguments);
71502
+ };
71503
+ }());
71470
71504
  xlrObject.bootstrap = function () {
71471
71505
  // Place to set configurations and initialize required props
71472
71506
  var self = this;
@@ -71508,11 +71542,11 @@ function XiboLayoutRenderer(inputLayouts, options) {
71508
71542
  this.updateLayouts(inputLayouts);
71509
71543
  };
71510
71544
  xlrObject.updateLayouts = /*#__PURE__*/function () {
71511
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(inputLayouts) {
71545
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(inputLayouts) {
71512
71546
  var _this2 = this;
71513
71547
  var xlr, _this$currentLayout, _this$nextLayout, currLayoutIndex, nxtLayoutIndex, tempOldNxtLayout, newNxtLayoutIndex, tempNxtLayout, hasOldNxtLayout, oldNxtLayoutIndex, _this$nextLayout2, tempNewNxtLayout;
71514
- return _regeneratorRuntime().wrap(function _callee$(_context) {
71515
- while (1) switch (_context.prev = _context.next) {
71548
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
71549
+ while (1) switch (_context2.prev = _context2.next) {
71516
71550
  case 0:
71517
71551
  /**
71518
71552
  * @TODO
@@ -71535,19 +71569,19 @@ function XiboLayoutRenderer(inputLayouts, options) {
71535
71569
  var _this2$currentLayout;
71536
71570
  return inputLayout.layoutId === ((_this2$currentLayout = _this2.currentLayout) === null || _this2$currentLayout === void 0 ? void 0 : _this2$currentLayout.layoutId);
71537
71571
  }).length === 0)) {
71538
- _context.next = 11;
71572
+ _context2.next = 11;
71539
71573
  break;
71540
71574
  }
71541
71575
  // Unset currentLayout, nextLayout and layouts
71542
71576
  this.layouts = [];
71543
71577
  this.currentLayout = undefined;
71544
71578
  this.nextLayout = undefined;
71545
- _context.next = 7;
71579
+ _context2.next = 7;
71546
71580
  return this.prepareLayouts();
71547
71581
  case 7:
71548
- xlr = _context.sent;
71582
+ xlr = _context2.sent;
71549
71583
  this.playSchedules(xlr);
71550
- _context.next = 40;
71584
+ _context2.next = 40;
71551
71585
  break;
71552
71586
  case 11:
71553
71587
  /** Case 2: When currentLayout is in inputLayouts, then continue playing
@@ -71562,18 +71596,18 @@ function XiboLayoutRenderer(inputLayouts, options) {
71562
71596
  tempOldNxtLayout = this.layouts[nxtLayoutIndex];
71563
71597
  newNxtLayoutIndex = currLayoutIndex + 1;
71564
71598
  if (!(nxtLayoutIndex !== newNxtLayoutIndex)) {
71565
- _context.next = 33;
71599
+ _context2.next = 33;
71566
71600
  break;
71567
71601
  }
71568
71602
  // Delete old nextLayout
71569
71603
  delete this.layouts[nxtLayoutIndex];
71570
71604
  if (!Boolean(this.layouts[newNxtLayoutIndex])) {
71571
- _context.next = 22;
71605
+ _context2.next = 22;
71572
71606
  break;
71573
71607
  }
71574
71608
  this.nextLayout = this.layouts[newNxtLayoutIndex];
71575
71609
  this.layouts[newNxtLayoutIndex] = this.nextLayout;
71576
- _context.next = 31;
71610
+ _context2.next = 31;
71577
71611
  break;
71578
71612
  case 22:
71579
71613
  // Check if newNxtLayoutIndex is still within inputLayouts
@@ -71582,14 +71616,14 @@ function XiboLayoutRenderer(inputLayouts, options) {
71582
71616
  newNxtLayoutIndex = 0;
71583
71617
  }
71584
71618
  if (!Boolean(inputLayouts[newNxtLayoutIndex])) {
71585
- _context.next = 29;
71619
+ _context2.next = 29;
71586
71620
  break;
71587
71621
  }
71588
71622
  tempNxtLayout = _objectSpread2(_objectSpread2({}, initialLayout), inputLayouts[newNxtLayoutIndex]);
71589
- _context.next = 27;
71623
+ _context2.next = 27;
71590
71624
  return this.prepareLayoutXlf(tempNxtLayout);
71591
71625
  case 27:
71592
- this.nextLayout = _context.sent;
71626
+ this.nextLayout = _context2.sent;
71593
71627
  this.layouts[newNxtLayoutIndex] = this.nextLayout;
71594
71628
  case 29:
71595
71629
  // Move old nextLayout to its index
@@ -71601,18 +71635,18 @@ function XiboLayoutRenderer(inputLayouts, options) {
71601
71635
  this.layouts[oldNxtLayoutIndex] = tempOldNxtLayout;
71602
71636
  }
71603
71637
  case 31:
71604
- _context.next = 40;
71638
+ _context2.next = 40;
71605
71639
  break;
71606
71640
  case 33:
71607
71641
  if (!(inputLayouts[nxtLayoutIndex].layoutId !== ((_this$nextLayout2 = this.nextLayout) === null || _this$nextLayout2 === void 0 ? void 0 : _this$nextLayout2.layoutId))) {
71608
- _context.next = 39;
71642
+ _context2.next = 39;
71609
71643
  break;
71610
71644
  }
71611
71645
  tempNewNxtLayout = _objectSpread2(_objectSpread2({}, initialLayout), inputLayouts[nxtLayoutIndex]);
71612
- _context.next = 37;
71646
+ _context2.next = 37;
71613
71647
  return this.prepareLayoutXlf(tempNewNxtLayout);
71614
71648
  case 37:
71615
- this.nextLayout = _context.sent;
71649
+ this.nextLayout = _context2.sent;
71616
71650
  this.layouts[nxtLayoutIndex] = this.nextLayout;
71617
71651
  case 39:
71618
71652
  // Remove old nextLayout if it's not in inputLayouts
@@ -71625,19 +71659,19 @@ function XiboLayoutRenderer(inputLayouts, options) {
71625
71659
  }
71626
71660
  case 40:
71627
71661
  case "end":
71628
- return _context.stop();
71662
+ return _context2.stop();
71629
71663
  }
71630
- }, _callee, this);
71664
+ }, _callee2, this);
71631
71665
  }));
71632
- return function (_x) {
71633
- return _ref.apply(this, arguments);
71666
+ return function (_x2) {
71667
+ return _ref2.apply(this, arguments);
71634
71668
  };
71635
71669
  }();
71636
- xlrObject.prepareLayouts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
71670
+ xlrObject.prepareLayouts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
71637
71671
  var _xlrLayouts$current;
71638
71672
  var self, xlrLayouts, layoutsXlf, layouts;
71639
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
71640
- while (1) switch (_context2.prev = _context2.next) {
71673
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
71674
+ while (1) switch (_context3.prev = _context3.next) {
71641
71675
  case 0:
71642
71676
  self = this; // Get layouts
71643
71677
  xlrLayouts = getLayout({
@@ -71656,13 +71690,13 @@ function XiboLayoutRenderer(inputLayouts, options) {
71656
71690
  return [].concat(_toConsumableArray(coll), [self.prepareLayoutXlf(item)]);
71657
71691
  }, []);
71658
71692
  };
71659
- _context2.next = 7;
71693
+ _context3.next = 7;
71660
71694
  return Promise.all(layoutsXlf());
71661
71695
  case 7:
71662
- layouts = _context2.sent;
71696
+ layouts = _context3.sent;
71663
71697
  console.debug('prepareLayouts::layouts', layouts);
71664
71698
  console.debug('prepareLayouts::xlr>layouts', self.layouts);
71665
- return _context2.abrupt("return", new Promise(function (resolve) {
71699
+ return _context3.abrupt("return", new Promise(function (resolve) {
71666
71700
  layouts.map(function (layoutItem) {
71667
71701
  if (!Boolean(self.layouts[layoutItem.index])) {
71668
71702
  self.layouts[layoutItem.index] = layoutItem;
@@ -71681,16 +71715,16 @@ function XiboLayoutRenderer(inputLayouts, options) {
71681
71715
  }));
71682
71716
  case 11:
71683
71717
  case "end":
71684
- return _context2.stop();
71718
+ return _context3.stop();
71685
71719
  }
71686
- }, _callee2, this);
71720
+ }, _callee3, this);
71687
71721
  }));
71688
71722
  xlrObject.prepareLayoutXlf = /*#__PURE__*/function () {
71689
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(inputLayout) {
71723
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(inputLayout) {
71690
71724
  var _this3 = this;
71691
71725
  var self, newOptions, layoutXlf, layoutXlfNode, parser;
71692
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
71693
- while (1) switch (_context3.prev = _context3.next) {
71726
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
71727
+ while (1) switch (_context4.prev = _context4.next) {
71694
71728
  case 0:
71695
71729
  self = this; // Compose layout props first
71696
71730
  newOptions = Object.assign({}, platform);
@@ -71701,21 +71735,21 @@ function XiboLayoutRenderer(inputLayouts, options) {
71701
71735
  newOptions.xlfUrl = inputLayout.path;
71702
71736
  }
71703
71737
  if (!(inputLayout && inputLayout.layoutNode === null)) {
71704
- _context3.next = 12;
71738
+ _context4.next = 12;
71705
71739
  break;
71706
71740
  }
71707
- _context3.next = 7;
71741
+ _context4.next = 7;
71708
71742
  return getXlf(newOptions);
71709
71743
  case 7:
71710
- layoutXlf = _context3.sent;
71744
+ layoutXlf = _context4.sent;
71711
71745
  parser = new window.DOMParser();
71712
71746
  layoutXlfNode = parser.parseFromString(layoutXlf, 'text/xml');
71713
- _context3.next = 13;
71747
+ _context4.next = 13;
71714
71748
  break;
71715
71749
  case 12:
71716
71750
  layoutXlfNode = inputLayout && inputLayout.layoutNode;
71717
71751
  case 13:
71718
- return _context3.abrupt("return", new Promise(function (resolve) {
71752
+ return _context4.abrupt("return", new Promise(function (resolve) {
71719
71753
  var xlrLayoutObj = initialLayout;
71720
71754
  xlrLayoutObj.id = Number(inputLayout.layoutId);
71721
71755
  xlrLayoutObj.layoutId = Number(inputLayout.layoutId);
@@ -71725,12 +71759,12 @@ function XiboLayoutRenderer(inputLayouts, options) {
71725
71759
  }));
71726
71760
  case 14:
71727
71761
  case "end":
71728
- return _context3.stop();
71762
+ return _context4.stop();
71729
71763
  }
71730
- }, _callee3, this);
71764
+ }, _callee4, this);
71731
71765
  }));
71732
- return function (_x2) {
71733
- return _ref3.apply(this, arguments);
71766
+ return function (_x3) {
71767
+ return _ref4.apply(this, arguments);
71734
71768
  };
71735
71769
  }();
71736
71770
  xlrObject.bootstrap();