@xibosignage/xibo-layout-renderer 1.0.14 → 1.0.16

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 +1 @@
1
- export { getFileExt, nextId, preloadMediaBlob, getMediaId, fetchJSON, capitalizeStr, audioFileType, MediaTypes, videoFileType, setExpiry, } from './Generators';
1
+ export { getFileExt, nextId, preloadMediaBlob, getMediaId, fetchJSON, capitalizeStr, audioFileType, MediaTypes, videoFileType, setExpiry, composeMediaUrl, fetchText, getDataBlob, composeResourceUrl, composeResourceUrlByPlatform, getIndexByLayoutId, isEmpty, composeBgUrlByPlatform, } from './Generators';
@@ -4,4 +4,5 @@ import './media.css';
4
4
  export declare function composeVideoSource($media: HTMLVideoElement, media: IMedia): HTMLVideoElement;
5
5
  export default function VideoMedia(media: IMedia, xlr: IXlr): {
6
6
  init: () => void;
7
+ stop: (disposeOnly?: boolean) => void;
7
8
  };
@@ -799,6 +799,34 @@ function _fetchJSON() {
799
799
  }));
800
800
  return _fetchJSON.apply(this, arguments);
801
801
  }
802
+ function fetchText(_x5) {
803
+ return _fetchText.apply(this, arguments);
804
+ }
805
+ function _fetchText() {
806
+ _fetchText = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(url) {
807
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
808
+ while (1) switch (_context4.prev = _context4.next) {
809
+ case 0:
810
+ return _context4.abrupt("return", fetch(url).then(function (res) {
811
+ return res.text();
812
+ }).then(function (responseText) {
813
+ if (String(responseText).length > 0) {
814
+ return responseText;
815
+ } else {
816
+ return '';
817
+ }
818
+ })["catch"](function (err) {
819
+ console.debug(err);
820
+ return err === null || err === void 0 ? void 0 : err.message;
821
+ }));
822
+ case 1:
823
+ case "end":
824
+ return _context4.stop();
825
+ }
826
+ }, _callee4);
827
+ }));
828
+ return _fetchText.apply(this, arguments);
829
+ }
802
830
  function getFileExt(filename) {
803
831
  var filenameArr = String(filename).split('.');
804
832
  return filenameArr[filenameArr.length - 1];
@@ -874,6 +902,9 @@ function getIndexByLayoutId(layoutsInput, layoutId) {
874
902
  index: 0
875
903
  };
876
904
  }
905
+ function isEmpty$1(input) {
906
+ return !Boolean(input) || String(input).length === 0;
907
+ }
877
908
  function getAllAttributes(elem) {
878
909
  if (!elem || elem === null) {
879
910
  return {};
@@ -72639,7 +72670,7 @@ function composeVideoSource($media, media) {
72639
72670
  return $media;
72640
72671
  }
72641
72672
  function VideoMedia(media, xlr) {
72642
- return {
72673
+ var videoMediaInstance = {
72643
72674
  init: function init() {
72644
72675
  var vjsPlayer = media.player;
72645
72676
  if (vjsPlayer !== undefined) {
@@ -72667,10 +72698,10 @@ function VideoMedia(media, xlr) {
72667
72698
  // Temporary setting
72668
72699
  expires: format(new Date(setExpiry(1)), 'yyyy-MM-dd HH:mm:ss')
72669
72700
  })["finally"](function () {
72670
- // Expire the media and dispose the video
72671
- vjsPlayer.dispose();
72672
- media.emitter.emit('end', media);
72701
+ videoMediaInstance.stop();
72673
72702
  });
72703
+ } else {
72704
+ videoMediaInstance.stop();
72674
72705
  }
72675
72706
  case 5:
72676
72707
  case "end":
@@ -72690,88 +72721,130 @@ function VideoMedia(media, xlr) {
72690
72721
  });
72691
72722
  vjsPlayer.on('ready', function () {
72692
72723
  vjsPlayer.muted(true);
72693
- var promise = vjsPlayer.play();
72694
- if (promise !== undefined) {
72695
- promise.then(function () {
72696
- // Autoplay restarted
72697
- console.debug('autoplay started . . .');
72698
- })["catch"]( /*#__PURE__*/function () {
72699
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(error) {
72700
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
72701
- while (1) switch (_context2.prev = _context2.next) {
72702
- case 0:
72703
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " autoplay error"));
72704
- if (!(xlr.config.platform === 'chromeOS')) {
72705
- _context2.next = 4;
72706
- break;
72707
- }
72708
- _context2.next = 4;
72709
- return playerReportFault('Media autoplay error');
72710
- case 4:
72711
- case "end":
72712
- return _context2.stop();
72713
- }
72714
- }, _callee2);
72715
- }));
72716
- return function (_x2) {
72717
- return _ref2.apply(this, arguments);
72718
- };
72719
- }());
72720
- }
72724
+ // Race promise between a 0.5s play and a 5s skip
72725
+ Promise.race([new Promise(function (resolve, reject) {
72726
+ return setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
72727
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
72728
+ while (1) switch (_context2.prev = _context2.next) {
72729
+ case 0:
72730
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Trying to force play after 0.1 seconds"));
72731
+ // Try to force play here
72732
+ _context2.prev = 1;
72733
+ _context2.next = 4;
72734
+ return vjsPlayer.play();
72735
+ case 4:
72736
+ // Resolve if play works
72737
+ resolve(true);
72738
+ _context2.next = 10;
72739
+ break;
72740
+ case 7:
72741
+ _context2.prev = 7;
72742
+ _context2.t0 = _context2["catch"](1);
72743
+ // Reject race if play fails
72744
+ reject('Play failed');
72745
+ case 10:
72746
+ case "end":
72747
+ return _context2.stop();
72748
+ }
72749
+ }, _callee2, null, [[1, 7]]);
72750
+ })), 100);
72751
+ }), new Promise(function (_, reject) {
72752
+ return setTimeout(function () {
72753
+ return reject('Timeout');
72754
+ }, 5000);
72755
+ })]).then(function () {
72756
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Autoplay started"));
72757
+ })["catch"]( /*#__PURE__*/function () {
72758
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(error) {
72759
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
72760
+ while (1) switch (_context3.prev = _context3.next) {
72761
+ case 0:
72762
+ if (!(error === 'Timeout')) {
72763
+ _context3.next = 5;
72764
+ break;
72765
+ }
72766
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Promise not resolved within 5 seconds. Move to next media"));
72767
+ videoMediaInstance.stop();
72768
+ _context3.next = 9;
72769
+ break;
72770
+ case 5:
72771
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Autoplay error: ").concat(error));
72772
+ if (!(xlr.config.platform === 'chromeOS')) {
72773
+ _context3.next = 9;
72774
+ break;
72775
+ }
72776
+ _context3.next = 9;
72777
+ return playerReportFault('Media autoplay error');
72778
+ case 9:
72779
+ case "end":
72780
+ return _context3.stop();
72781
+ }
72782
+ }, _callee3);
72783
+ }));
72784
+ return function (_x2) {
72785
+ return _ref3.apply(this, arguments);
72786
+ };
72787
+ }());
72721
72788
  });
72722
72789
  vjsPlayer.on('playing', function () {
72723
72790
  console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " is now playing . . ."));
72724
72791
  vjsPlayer.muted(media.muted);
72725
72792
  });
72726
72793
  vjsPlayer.on('error', /*#__PURE__*/function () {
72727
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(err) {
72728
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
72729
- while (1) switch (_context3.prev = _context3.next) {
72794
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(err) {
72795
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
72796
+ while (1) switch (_context4.prev = _context4.next) {
72730
72797
  case 0:
72731
72798
  console.debug("Media Error: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id));
72732
72799
  if (!(xlr.config.platform === 'chromeOS')) {
72733
- _context3.next = 6;
72800
+ _context4.next = 6;
72734
72801
  break;
72735
72802
  }
72736
- _context3.next = 4;
72803
+ _context4.next = 4;
72737
72804
  return playerReportFault('Video file source not supported');
72738
72805
  case 4:
72739
- _context3.next = 7;
72806
+ _context4.next = 7;
72740
72807
  break;
72741
72808
  case 6:
72742
72809
  // End media after 5 seconds
72743
72810
  setTimeout(function () {
72744
72811
  console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended . . ."));
72745
- media.emitter.emit('end', media);
72746
- vjsPlayer.dispose();
72812
+ videoMediaInstance.stop();
72747
72813
  }, 5000);
72748
72814
  case 7:
72749
72815
  case "end":
72750
- return _context3.stop();
72816
+ return _context4.stop();
72751
72817
  }
72752
- }, _callee3);
72818
+ }, _callee4);
72753
72819
  }));
72754
72820
  return function (_x3) {
72755
- return _ref3.apply(this, arguments);
72821
+ return _ref4.apply(this, arguments);
72756
72822
  };
72757
72823
  }());
72758
- vjsPlayer.on('ended', function () {
72759
- var _media$emitter;
72760
- console.debug("VideoMedia: onended: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72761
- (_media$emitter = media.emitter) === null || _media$emitter === void 0 || _media$emitter.emit('end', media);
72762
- vjsPlayer.dispose();
72763
- });
72764
- vjsPlayer.on('durationchange', function () {
72765
- if (media.duration === 0 && vjsPlayer.duration() !== undefined) {
72766
- media.duration = vjsPlayer.duration();
72767
- } else if (media.duration > 0) {
72768
- vjsPlayer.duration(media.duration);
72769
- }
72770
- console.debug('VIDEOJS: ondurationchange: Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72771
- });
72824
+ if (media.duration === 0) {
72825
+ vjsPlayer.on('ended', function () {
72826
+ console.debug("VideoMedia: onended: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72827
+ videoMediaInstance.stop();
72828
+ });
72829
+ vjsPlayer.on('durationchange', function () {
72830
+ console.debug('VIDEOJS: ondurationchange: Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72831
+ });
72832
+ }
72833
+ }
72834
+ },
72835
+ stop: function stop() {
72836
+ var disposeOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
72837
+ var vjsPlayer = media.player;
72838
+ // Expire the media and dispose the video
72839
+ if (vjsPlayer !== undefined) {
72840
+ if (!disposeOnly) {
72841
+ media.emitter.emit('end', media);
72842
+ }
72843
+ vjsPlayer.dispose();
72772
72844
  }
72773
72845
  }
72774
72846
  };
72847
+ return videoMediaInstance;
72775
72848
  }
72776
72849
 
72777
72850
  function AudioMedia(media) {
@@ -72851,6 +72924,11 @@ function Media(region, mediaId, xml, options, xlr) {
72851
72924
  if (mediaTimeCount > media.duration) {
72852
72925
  console.debug('startMediaTimer: emit>end: on media ' + media.id + ' of Region ' + media.region.regionId);
72853
72926
  media.emitter.emit('end', media);
72927
+ if (media.mediaType === 'video') {
72928
+ // Dispose the video media
72929
+ console.debug("VideoMedia::stop - ".concat(capitalizeStr(media.mediaType), " for media ").concat(media.id, " has been stopped."));
72930
+ VideoMedia(media, xlr).stop(true);
72931
+ }
72854
72932
  }
72855
72933
  }, 1000);
72856
72934
  console.debug('startMediaTimer: Showing Media ' + media.id + ' for ' + media.duration + 's of Region ' + media.region.regionId);
@@ -74655,15 +74733,22 @@ exports.Region = Region;
74655
74733
  exports.VideoMedia = VideoMedia;
74656
74734
  exports.audioFileType = audioFileType;
74657
74735
  exports.capitalizeStr = capitalizeStr;
74736
+ exports.composeBgUrlByPlatform = composeBgUrlByPlatform;
74737
+ exports.composeMediaUrl = composeMediaUrl;
74738
+ exports.composeResourceUrl = composeResourceUrl;
74739
+ exports.composeResourceUrlByPlatform = composeResourceUrlByPlatform;
74658
74740
  exports.default = XiboLayoutRenderer;
74659
74741
  exports.defaultTrans = defaultTrans;
74660
74742
  exports.fadeInElem = fadeInElem;
74661
74743
  exports.fadeOutElem = fadeOutElem;
74662
74744
  exports.fetchJSON = fetchJSON;
74745
+ exports.fetchText = fetchText;
74663
74746
  exports.flyInElem = flyInElem;
74664
74747
  exports.flyOutElem = flyOutElem;
74665
74748
  exports.flyTransitionKeyframes = flyTransitionKeyframes;
74749
+ exports.getDataBlob = getDataBlob;
74666
74750
  exports.getFileExt = getFileExt;
74751
+ exports.getIndexByLayoutId = getIndexByLayoutId;
74667
74752
  exports.getLayout = getLayout;
74668
74753
  exports.getMediaId = getMediaId;
74669
74754
  exports.getXlf = getXlf;
@@ -74672,6 +74757,7 @@ exports.initialLayout = initialLayout;
74672
74757
  exports.initialMedia = initialMedia;
74673
74758
  exports.initialRegion = initialRegion;
74674
74759
  exports.initialXlr = initialXlr;
74760
+ exports.isEmpty = isEmpty$1;
74675
74761
  exports.nextId = nextId;
74676
74762
  exports.platform = platform;
74677
74763
  exports.preloadMediaBlob = preloadMediaBlob;