@xibosignage/xibo-layout-renderer 1.0.5 → 1.0.7

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