@xibosignage/xibo-layout-renderer 1.0.15 → 1.0.17

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';
@@ -3,5 +3,7 @@ import { IXlr } from '../../types';
3
3
  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
+ duration: number;
6
7
  init: () => void;
8
+ stop: (disposeOnly?: boolean) => void;
7
9
  };
@@ -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 {};
@@ -72640,12 +72671,15 @@ function composeVideoSource($media, media) {
72640
72671
  }
72641
72672
  function VideoMedia(media, xlr) {
72642
72673
  return {
72674
+ duration: 0,
72643
72675
  init: function init() {
72676
+ var _this = this;
72644
72677
  var vjsPlayer = media.player;
72678
+ this.duration = media.duration;
72645
72679
  if (vjsPlayer !== undefined) {
72646
72680
  var playerReportFault = /*#__PURE__*/function () {
72647
72681
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(msg) {
72648
- var playerSW, hasSW, endVideo;
72682
+ var playerSW, hasSW;
72649
72683
  return _regeneratorRuntime().wrap(function _callee$(_context) {
72650
72684
  while (1) switch (_context.prev = _context.next) {
72651
72685
  case 0:
@@ -72655,11 +72689,6 @@ function VideoMedia(media, xlr) {
72655
72689
  return playerSW.getSW();
72656
72690
  case 3:
72657
72691
  hasSW = _context.sent;
72658
- endVideo = function endVideo() {
72659
- // Expire the media and dispose the video
72660
- vjsPlayer.dispose();
72661
- media.emitter.emit('end', media);
72662
- };
72663
72692
  if (hasSW) {
72664
72693
  playerSW.postMsg({
72665
72694
  type: 'MEDIA_FAULT',
@@ -72672,12 +72701,12 @@ function VideoMedia(media, xlr) {
72672
72701
  // Temporary setting
72673
72702
  expires: format(new Date(setExpiry(1)), 'yyyy-MM-dd HH:mm:ss')
72674
72703
  })["finally"](function () {
72675
- endVideo();
72704
+ _this.stop();
72676
72705
  });
72677
72706
  } else {
72678
- endVideo();
72707
+ _this.stop();
72679
72708
  }
72680
- case 6:
72709
+ case 5:
72681
72710
  case "end":
72682
72711
  return _context.stop();
72683
72712
  }
@@ -72688,11 +72717,26 @@ function VideoMedia(media, xlr) {
72688
72717
  };
72689
72718
  }();
72690
72719
  vjsPlayer.on('loadstart', function () {
72691
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has started loading data . . ."));
72720
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has started loading data . . ."));
72692
72721
  });
72693
- vjsPlayer.on('canplay', function () {
72694
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " can be played . . ."));
72722
+ vjsPlayer.one('loadedmetadata', function () {
72723
+ if (media.duration === 0) {
72724
+ _this.duration = vjsPlayer.duration();
72725
+ }
72726
+ console.debug('VideoMedia: loadedmetadata: Setting video duration to = ' + _this.duration);
72727
+ });
72728
+ vjsPlayer.one('canplay', function () {
72729
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " can be played . . ."));
72730
+ });
72731
+ vjsPlayer.one('playing', function () {
72732
+ console.debug('VideoMedia: playing: Showing Media ' + media.id + ' for ' + _this.duration + 's of Region ' + media.region.regionId);
72733
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " is now playing . . ."));
72695
72734
  });
72735
+ // @NOTE: When video is paused due to fail in unmuting the video
72736
+ // and video has media.duration = 0, the video will stay paused and the video cycle won't end
72737
+ // @TODO: Add timer when video is paused due to unmuting fail and duration that is equal to 0
72738
+ // @NOTE: The pause issue when unmuting the video is mainly on a browser level.
72739
+ // Please visit https://developer.chrome.com/blog/autoplay/ for more info.
72696
72740
  vjsPlayer.on('ready', function () {
72697
72741
  vjsPlayer.muted(true);
72698
72742
  // Race promise between a 0.5s play and a 5s skip
@@ -72701,57 +72745,57 @@ function VideoMedia(media, xlr) {
72701
72745
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
72702
72746
  while (1) switch (_context2.prev = _context2.next) {
72703
72747
  case 0:
72704
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Trying to force play after 0.1 seconds"));
72748
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Trying to force play after 0.1 seconds"));
72705
72749
  // Try to force play here
72706
72750
  _context2.prev = 1;
72707
- _context2.next = 4;
72751
+ // Set video mute/unmute based on setting once playing
72752
+ vjsPlayer.muted(media.muted);
72753
+ _context2.next = 5;
72708
72754
  return vjsPlayer.play();
72709
- case 4:
72755
+ case 5:
72710
72756
  // Resolve if play works
72711
72757
  resolve(true);
72712
- _context2.next = 10;
72758
+ _context2.next = 11;
72713
72759
  break;
72714
- case 7:
72715
- _context2.prev = 7;
72760
+ case 8:
72761
+ _context2.prev = 8;
72716
72762
  _context2.t0 = _context2["catch"](1);
72717
72763
  // Reject race if play fails
72718
72764
  reject('Play failed');
72719
- case 10:
72765
+ case 11:
72720
72766
  case "end":
72721
72767
  return _context2.stop();
72722
72768
  }
72723
- }, _callee2, null, [[1, 7]]);
72769
+ }, _callee2, null, [[1, 8]]);
72724
72770
  })), 100);
72725
72771
  }), new Promise(function (_, reject) {
72726
72772
  return setTimeout(function () {
72727
72773
  return reject('Timeout');
72728
72774
  }, 5000);
72729
72775
  })]).then(function () {
72730
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Autoplay started"));
72776
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Autoplay started"));
72731
72777
  })["catch"]( /*#__PURE__*/function () {
72732
72778
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(error) {
72733
- var _media$emitter;
72734
72779
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
72735
72780
  while (1) switch (_context3.prev = _context3.next) {
72736
72781
  case 0:
72737
72782
  if (!(error === 'Timeout')) {
72738
- _context3.next = 6;
72783
+ _context3.next = 5;
72739
72784
  break;
72740
72785
  }
72741
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Promise not resolved within 5 seconds. Move to next media"));
72742
- vjsPlayer.dispose();
72743
- (_media$emitter = media.emitter) === null || _media$emitter === void 0 || _media$emitter.emit('end', media);
72744
- _context3.next = 10;
72786
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Promise not resolved within 5 seconds. Move to next media"));
72787
+ _this.stop();
72788
+ _context3.next = 9;
72745
72789
  break;
72746
- case 6:
72747
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Autoplay error: ").concat(error));
72790
+ case 5:
72791
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Autoplay error: ").concat(error));
72748
72792
  if (!(xlr.config.platform === 'chromeOS')) {
72749
- _context3.next = 10;
72793
+ _context3.next = 9;
72750
72794
  break;
72751
72795
  }
72752
- _context3.next = 10;
72796
+ _context3.next = 9;
72753
72797
  return playerReportFault('Media autoplay error');
72754
- case 10:
72798
+ case 9:
72755
72799
  case "end":
72756
72800
  return _context3.stop();
72757
72801
  }
@@ -72762,16 +72806,12 @@ function VideoMedia(media, xlr) {
72762
72806
  };
72763
72807
  }());
72764
72808
  });
72765
- vjsPlayer.on('playing', function () {
72766
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " is now playing . . ."));
72767
- vjsPlayer.muted(media.muted);
72768
- });
72769
72809
  vjsPlayer.on('error', /*#__PURE__*/function () {
72770
72810
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(err) {
72771
72811
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
72772
72812
  while (1) switch (_context4.prev = _context4.next) {
72773
72813
  case 0:
72774
- console.debug("Media Error: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id));
72814
+ console.debug("VideoMedia: Media Error: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id));
72775
72815
  if (!(xlr.config.platform === 'chromeOS')) {
72776
72816
  _context4.next = 6;
72777
72817
  break;
@@ -72784,9 +72824,8 @@ function VideoMedia(media, xlr) {
72784
72824
  case 6:
72785
72825
  // End media after 5 seconds
72786
72826
  setTimeout(function () {
72787
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended . . ."));
72788
- media.emitter.emit('end', media);
72789
- vjsPlayer.dispose();
72827
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended . . ."));
72828
+ _this.stop();
72790
72829
  }, 5000);
72791
72830
  case 7:
72792
72831
  case "end":
@@ -72798,20 +72837,25 @@ function VideoMedia(media, xlr) {
72798
72837
  return _ref4.apply(this, arguments);
72799
72838
  };
72800
72839
  }());
72801
- vjsPlayer.on('ended', function () {
72802
- var _media$emitter2;
72803
- console.debug("VideoMedia: onended: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72804
- (_media$emitter2 = media.emitter) === null || _media$emitter2 === void 0 || _media$emitter2.emit('end', media);
72805
- vjsPlayer.dispose();
72806
- });
72807
- vjsPlayer.on('durationchange', function () {
72808
- if (media.duration === 0 && vjsPlayer.duration() !== undefined) {
72809
- media.duration = vjsPlayer.duration();
72810
- } else if (media.duration > 0) {
72811
- vjsPlayer.duration(media.duration);
72812
- }
72813
- console.debug('VIDEOJS: ondurationchange: Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72814
- });
72840
+ if (media.duration === 0) {
72841
+ vjsPlayer.on('ended', function () {
72842
+ console.debug("VideoMedia: onended: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72843
+ _this.stop();
72844
+ });
72845
+ }
72846
+ }
72847
+ },
72848
+ stop: function stop() {
72849
+ var disposeOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
72850
+ var vjsPlayer = media.player;
72851
+ // Expire the media and dispose the video
72852
+ if (vjsPlayer !== undefined) {
72853
+ if (!disposeOnly) {
72854
+ media.emitter.emit('end', media);
72855
+ }
72856
+ vjsPlayer.dispose();
72857
+ // Clear up media player
72858
+ media.player = undefined;
72815
72859
  }
72816
72860
  }
72817
72861
  };
@@ -72894,13 +72938,19 @@ function Media(region, mediaId, xml, options, xlr) {
72894
72938
  if (mediaTimeCount > media.duration) {
72895
72939
  console.debug('startMediaTimer: emit>end: on media ' + media.id + ' of Region ' + media.region.regionId);
72896
72940
  media.emitter.emit('end', media);
72941
+ if (media.mediaType === 'video') {
72942
+ // Dispose the video media
72943
+ console.debug("VideoMedia::stop - ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72944
+ VideoMedia(media, xlr).stop(true);
72945
+ }
72897
72946
  }
72898
72947
  }, 1000);
72899
72948
  console.debug('startMediaTimer: Showing Media ' + media.id + ' for ' + media.duration + 's of Region ' + media.region.regionId);
72900
72949
  };
72901
72950
  emitter.on('start', function (media) {
72902
72951
  if (media.mediaType === 'video') {
72903
- VideoMedia(media, xlr).init();
72952
+ var videoMedia = VideoMedia(media, xlr);
72953
+ videoMedia.init();
72904
72954
  if (media.duration > 0) {
72905
72955
  startMediaTimer(media);
72906
72956
  }
@@ -73221,7 +73271,7 @@ function Media(region, mediaId, xml, options, xlr) {
73221
73271
  controls: false,
73222
73272
  preload: 'auto',
73223
73273
  autoplay: false,
73224
- muted: self.muted,
73274
+ muted: true,
73225
73275
  errorDisplay: xlr.config.platform !== 'chromeOS',
73226
73276
  loop: self.loop
73227
73277
  });
@@ -74698,15 +74748,22 @@ exports.Region = Region;
74698
74748
  exports.VideoMedia = VideoMedia;
74699
74749
  exports.audioFileType = audioFileType;
74700
74750
  exports.capitalizeStr = capitalizeStr;
74751
+ exports.composeBgUrlByPlatform = composeBgUrlByPlatform;
74752
+ exports.composeMediaUrl = composeMediaUrl;
74753
+ exports.composeResourceUrl = composeResourceUrl;
74754
+ exports.composeResourceUrlByPlatform = composeResourceUrlByPlatform;
74701
74755
  exports.default = XiboLayoutRenderer;
74702
74756
  exports.defaultTrans = defaultTrans;
74703
74757
  exports.fadeInElem = fadeInElem;
74704
74758
  exports.fadeOutElem = fadeOutElem;
74705
74759
  exports.fetchJSON = fetchJSON;
74760
+ exports.fetchText = fetchText;
74706
74761
  exports.flyInElem = flyInElem;
74707
74762
  exports.flyOutElem = flyOutElem;
74708
74763
  exports.flyTransitionKeyframes = flyTransitionKeyframes;
74764
+ exports.getDataBlob = getDataBlob;
74709
74765
  exports.getFileExt = getFileExt;
74766
+ exports.getIndexByLayoutId = getIndexByLayoutId;
74710
74767
  exports.getLayout = getLayout;
74711
74768
  exports.getMediaId = getMediaId;
74712
74769
  exports.getXlf = getXlf;
@@ -74715,6 +74772,7 @@ exports.initialLayout = initialLayout;
74715
74772
  exports.initialMedia = initialMedia;
74716
74773
  exports.initialRegion = initialRegion;
74717
74774
  exports.initialXlr = initialXlr;
74775
+ exports.isEmpty = isEmpty$1;
74718
74776
  exports.nextId = nextId;
74719
74777
  exports.platform = platform;
74720
74778
  exports.preloadMediaBlob = preloadMediaBlob;