@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.
@@ -254,12 +254,29 @@ declare function nextId(options: {
254
254
  }): number;
255
255
  declare const getMediaId: ({ mediaType, containerName }: IMedia) => string;
256
256
  declare const capitalizeStr: (inputStr: string) => string;
257
+ declare function getDataBlob(src: string): Promise<unknown>;
257
258
  type MediaTypes = 'video' | 'audio' | 'image';
258
259
  declare function preloadMediaBlob(src: string, type: MediaTypes): Promise<string>;
259
260
  declare function fetchJSON(url: string): Promise<any>;
261
+ declare function fetchText(url: string): Promise<string>;
260
262
  declare function getFileExt(filename: string): string;
261
263
  declare function audioFileType(str: string): string | undefined;
262
264
  declare function videoFileType(str: string): string | undefined;
265
+ declare function composeResourceUrlByPlatform(options: OptionsType, params: any): string;
266
+ declare function composeResourceUrl(options: OptionsType, params: any): string;
267
+ declare function composeMediaUrl(params: any): string;
268
+ declare function composeBgUrlByPlatform(platform: OptionsType['platform'], params: any): string;
269
+ type LayoutIndexType = {
270
+ [k: string]: InputLayoutType & {
271
+ index: number;
272
+ };
273
+ };
274
+ declare function getIndexByLayoutId(layoutsInput: InputLayoutType[], layoutId?: number | null): (InputLayoutType & {
275
+ index: number;
276
+ }) | LayoutIndexType | {
277
+ index: number;
278
+ };
279
+ declare function isEmpty(input: any): boolean;
263
280
  /**
264
281
  * Create expiration day based on current date
265
282
  * @param numDays Number of days as expiry
@@ -268,7 +285,9 @@ declare function videoFileType(str: string): string | undefined;
268
285
  declare function setExpiry(numDays: number): string;
269
286
 
270
287
  declare function VideoMedia(media: IMedia, xlr: IXlr): {
288
+ duration: number;
271
289
  init: () => void;
290
+ stop: (disposeOnly?: boolean) => void;
272
291
  };
273
292
 
274
293
  declare function AudioMedia(media: IMedia): {
@@ -379,4 +398,4 @@ type flyTransitionParams = {
379
398
  };
380
399
  declare const flyTransitionKeyframes: (params: flyTransitionParams) => KeyframeOptionsType;
381
400
 
382
- export { Action, ActionsWrapper, AudioMedia, ELayoutType, type GetLayoutParamType, type GetLayoutType, type ILayout, type ILayoutEvents, type IMedia, type IRegion, type IRegionEvents, type ISplashScreen, type IXlr, type InactOptions, type InputLayoutType, type KeyframeOptionsType, Media, type MediaTypes, type OptionsType, type PreviewSplashElement, Region, type TransitionElementOptions, type TransitionNameType, VideoMedia, audioFileType, capitalizeStr, type compassPoints, XiboLayoutRenderer as default, defaultTrans, fadeInElem, fadeOutElem, fetchJSON, flyInElem, flyOutElem, flyTransitionKeyframes, type flyTransitionParams, getFileExt, getLayout, getMediaId, getXlf, initRenderingDOM, initialLayout, initialMedia, initialRegion, initialXlr, nextId, platform, preloadMediaBlob, setExpiry, transitionElement, videoFileType };
401
+ export { Action, ActionsWrapper, AudioMedia, ELayoutType, type GetLayoutParamType, type GetLayoutType, type ILayout, type ILayoutEvents, type IMedia, type IRegion, type IRegionEvents, type ISplashScreen, type IXlr, type InactOptions, type InputLayoutType, type KeyframeOptionsType, Media, type MediaTypes, type OptionsType, type PreviewSplashElement, Region, type TransitionElementOptions, type TransitionNameType, VideoMedia, audioFileType, capitalizeStr, type compassPoints, composeBgUrlByPlatform, composeMediaUrl, composeResourceUrl, composeResourceUrlByPlatform, XiboLayoutRenderer as default, defaultTrans, fadeInElem, fadeOutElem, fetchJSON, fetchText, flyInElem, flyOutElem, flyTransitionKeyframes, type flyTransitionParams, getDataBlob, getFileExt, getIndexByLayoutId, getLayout, getMediaId, getXlf, initRenderingDOM, initialLayout, initialMedia, initialRegion, initialXlr, isEmpty, nextId, platform, preloadMediaBlob, setExpiry, transitionElement, videoFileType };
@@ -795,6 +795,34 @@ function _fetchJSON() {
795
795
  }));
796
796
  return _fetchJSON.apply(this, arguments);
797
797
  }
798
+ function fetchText(_x5) {
799
+ return _fetchText.apply(this, arguments);
800
+ }
801
+ function _fetchText() {
802
+ _fetchText = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(url) {
803
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
804
+ while (1) switch (_context4.prev = _context4.next) {
805
+ case 0:
806
+ return _context4.abrupt("return", fetch(url).then(function (res) {
807
+ return res.text();
808
+ }).then(function (responseText) {
809
+ if (String(responseText).length > 0) {
810
+ return responseText;
811
+ } else {
812
+ return '';
813
+ }
814
+ })["catch"](function (err) {
815
+ console.debug(err);
816
+ return err === null || err === void 0 ? void 0 : err.message;
817
+ }));
818
+ case 1:
819
+ case "end":
820
+ return _context4.stop();
821
+ }
822
+ }, _callee4);
823
+ }));
824
+ return _fetchText.apply(this, arguments);
825
+ }
798
826
  function getFileExt(filename) {
799
827
  var filenameArr = String(filename).split('.');
800
828
  return filenameArr[filenameArr.length - 1];
@@ -870,6 +898,9 @@ function getIndexByLayoutId(layoutsInput, layoutId) {
870
898
  index: 0
871
899
  };
872
900
  }
901
+ function isEmpty$1(input) {
902
+ return !Boolean(input) || String(input).length === 0;
903
+ }
873
904
  function getAllAttributes(elem) {
874
905
  if (!elem || elem === null) {
875
906
  return {};
@@ -72636,12 +72667,15 @@ function composeVideoSource($media, media) {
72636
72667
  }
72637
72668
  function VideoMedia(media, xlr) {
72638
72669
  return {
72670
+ duration: 0,
72639
72671
  init: function init() {
72672
+ var _this = this;
72640
72673
  var vjsPlayer = media.player;
72674
+ this.duration = media.duration;
72641
72675
  if (vjsPlayer !== undefined) {
72642
72676
  var playerReportFault = /*#__PURE__*/function () {
72643
72677
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(msg) {
72644
- var playerSW, hasSW, endVideo;
72678
+ var playerSW, hasSW;
72645
72679
  return _regeneratorRuntime().wrap(function _callee$(_context) {
72646
72680
  while (1) switch (_context.prev = _context.next) {
72647
72681
  case 0:
@@ -72651,11 +72685,6 @@ function VideoMedia(media, xlr) {
72651
72685
  return playerSW.getSW();
72652
72686
  case 3:
72653
72687
  hasSW = _context.sent;
72654
- endVideo = function endVideo() {
72655
- // Expire the media and dispose the video
72656
- vjsPlayer.dispose();
72657
- media.emitter.emit('end', media);
72658
- };
72659
72688
  if (hasSW) {
72660
72689
  playerSW.postMsg({
72661
72690
  type: 'MEDIA_FAULT',
@@ -72668,12 +72697,12 @@ function VideoMedia(media, xlr) {
72668
72697
  // Temporary setting
72669
72698
  expires: format(new Date(setExpiry(1)), 'yyyy-MM-dd HH:mm:ss')
72670
72699
  })["finally"](function () {
72671
- endVideo();
72700
+ _this.stop();
72672
72701
  });
72673
72702
  } else {
72674
- endVideo();
72703
+ _this.stop();
72675
72704
  }
72676
- case 6:
72705
+ case 5:
72677
72706
  case "end":
72678
72707
  return _context.stop();
72679
72708
  }
@@ -72684,11 +72713,26 @@ function VideoMedia(media, xlr) {
72684
72713
  };
72685
72714
  }();
72686
72715
  vjsPlayer.on('loadstart', function () {
72687
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has started loading data . . ."));
72716
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has started loading data . . ."));
72688
72717
  });
72689
- vjsPlayer.on('canplay', function () {
72690
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " can be played . . ."));
72718
+ vjsPlayer.one('loadedmetadata', function () {
72719
+ if (media.duration === 0) {
72720
+ _this.duration = vjsPlayer.duration();
72721
+ }
72722
+ console.debug('VideoMedia: loadedmetadata: Setting video duration to = ' + _this.duration);
72723
+ });
72724
+ vjsPlayer.one('canplay', function () {
72725
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " can be played . . ."));
72726
+ });
72727
+ vjsPlayer.one('playing', function () {
72728
+ console.debug('VideoMedia: playing: Showing Media ' + media.id + ' for ' + _this.duration + 's of Region ' + media.region.regionId);
72729
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " is now playing . . ."));
72691
72730
  });
72731
+ // @NOTE: When video is paused due to fail in unmuting the video
72732
+ // and video has media.duration = 0, the video will stay paused and the video cycle won't end
72733
+ // @TODO: Add timer when video is paused due to unmuting fail and duration that is equal to 0
72734
+ // @NOTE: The pause issue when unmuting the video is mainly on a browser level.
72735
+ // Please visit https://developer.chrome.com/blog/autoplay/ for more info.
72692
72736
  vjsPlayer.on('ready', function () {
72693
72737
  vjsPlayer.muted(true);
72694
72738
  // Race promise between a 0.5s play and a 5s skip
@@ -72697,57 +72741,57 @@ function VideoMedia(media, xlr) {
72697
72741
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
72698
72742
  while (1) switch (_context2.prev = _context2.next) {
72699
72743
  case 0:
72700
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Trying to force play after 0.1 seconds"));
72744
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Trying to force play after 0.1 seconds"));
72701
72745
  // Try to force play here
72702
72746
  _context2.prev = 1;
72703
- _context2.next = 4;
72747
+ // Set video mute/unmute based on setting once playing
72748
+ vjsPlayer.muted(media.muted);
72749
+ _context2.next = 5;
72704
72750
  return vjsPlayer.play();
72705
- case 4:
72751
+ case 5:
72706
72752
  // Resolve if play works
72707
72753
  resolve(true);
72708
- _context2.next = 10;
72754
+ _context2.next = 11;
72709
72755
  break;
72710
- case 7:
72711
- _context2.prev = 7;
72756
+ case 8:
72757
+ _context2.prev = 8;
72712
72758
  _context2.t0 = _context2["catch"](1);
72713
72759
  // Reject race if play fails
72714
72760
  reject('Play failed');
72715
- case 10:
72761
+ case 11:
72716
72762
  case "end":
72717
72763
  return _context2.stop();
72718
72764
  }
72719
- }, _callee2, null, [[1, 7]]);
72765
+ }, _callee2, null, [[1, 8]]);
72720
72766
  })), 100);
72721
72767
  }), new Promise(function (_, reject) {
72722
72768
  return setTimeout(function () {
72723
72769
  return reject('Timeout');
72724
72770
  }, 5000);
72725
72771
  })]).then(function () {
72726
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Autoplay started"));
72772
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Autoplay started"));
72727
72773
  })["catch"]( /*#__PURE__*/function () {
72728
72774
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(error) {
72729
- var _media$emitter;
72730
72775
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
72731
72776
  while (1) switch (_context3.prev = _context3.next) {
72732
72777
  case 0:
72733
72778
  if (!(error === 'Timeout')) {
72734
- _context3.next = 6;
72779
+ _context3.next = 5;
72735
72780
  break;
72736
72781
  }
72737
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Promise not resolved within 5 seconds. Move to next media"));
72738
- vjsPlayer.dispose();
72739
- (_media$emitter = media.emitter) === null || _media$emitter === void 0 || _media$emitter.emit('end', media);
72740
- _context3.next = 10;
72782
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Promise not resolved within 5 seconds. Move to next media"));
72783
+ _this.stop();
72784
+ _context3.next = 9;
72741
72785
  break;
72742
- case 6:
72743
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Autoplay error: ").concat(error));
72786
+ case 5:
72787
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " : Autoplay error: ").concat(error));
72744
72788
  if (!(xlr.config.platform === 'chromeOS')) {
72745
- _context3.next = 10;
72789
+ _context3.next = 9;
72746
72790
  break;
72747
72791
  }
72748
- _context3.next = 10;
72792
+ _context3.next = 9;
72749
72793
  return playerReportFault('Media autoplay error');
72750
- case 10:
72794
+ case 9:
72751
72795
  case "end":
72752
72796
  return _context3.stop();
72753
72797
  }
@@ -72758,16 +72802,12 @@ function VideoMedia(media, xlr) {
72758
72802
  };
72759
72803
  }());
72760
72804
  });
72761
- vjsPlayer.on('playing', function () {
72762
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " is now playing . . ."));
72763
- vjsPlayer.muted(media.muted);
72764
- });
72765
72805
  vjsPlayer.on('error', /*#__PURE__*/function () {
72766
72806
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(err) {
72767
72807
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
72768
72808
  while (1) switch (_context4.prev = _context4.next) {
72769
72809
  case 0:
72770
- console.debug("Media Error: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id));
72810
+ console.debug("VideoMedia: Media Error: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id));
72771
72811
  if (!(xlr.config.platform === 'chromeOS')) {
72772
72812
  _context4.next = 6;
72773
72813
  break;
@@ -72780,9 +72820,8 @@ function VideoMedia(media, xlr) {
72780
72820
  case 6:
72781
72821
  // End media after 5 seconds
72782
72822
  setTimeout(function () {
72783
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended . . ."));
72784
- media.emitter.emit('end', media);
72785
- vjsPlayer.dispose();
72823
+ console.debug("VideoMedia: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended . . ."));
72824
+ _this.stop();
72786
72825
  }, 5000);
72787
72826
  case 7:
72788
72827
  case "end":
@@ -72794,20 +72833,25 @@ function VideoMedia(media, xlr) {
72794
72833
  return _ref4.apply(this, arguments);
72795
72834
  };
72796
72835
  }());
72797
- vjsPlayer.on('ended', function () {
72798
- var _media$emitter2;
72799
- console.debug("VideoMedia: onended: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72800
- (_media$emitter2 = media.emitter) === null || _media$emitter2 === void 0 || _media$emitter2.emit('end', media);
72801
- vjsPlayer.dispose();
72802
- });
72803
- vjsPlayer.on('durationchange', function () {
72804
- if (media.duration === 0 && vjsPlayer.duration() !== undefined) {
72805
- media.duration = vjsPlayer.duration();
72806
- } else if (media.duration > 0) {
72807
- vjsPlayer.duration(media.duration);
72808
- }
72809
- console.debug('VIDEOJS: ondurationchange: Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72810
- });
72836
+ if (media.duration === 0) {
72837
+ vjsPlayer.on('ended', function () {
72838
+ console.debug("VideoMedia: onended: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72839
+ _this.stop();
72840
+ });
72841
+ }
72842
+ }
72843
+ },
72844
+ stop: function stop() {
72845
+ var disposeOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
72846
+ var vjsPlayer = media.player;
72847
+ // Expire the media and dispose the video
72848
+ if (vjsPlayer !== undefined) {
72849
+ if (!disposeOnly) {
72850
+ media.emitter.emit('end', media);
72851
+ }
72852
+ vjsPlayer.dispose();
72853
+ // Clear up media player
72854
+ media.player = undefined;
72811
72855
  }
72812
72856
  }
72813
72857
  };
@@ -72890,13 +72934,19 @@ function Media(region, mediaId, xml, options, xlr) {
72890
72934
  if (mediaTimeCount > media.duration) {
72891
72935
  console.debug('startMediaTimer: emit>end: on media ' + media.id + ' of Region ' + media.region.regionId);
72892
72936
  media.emitter.emit('end', media);
72937
+ if (media.mediaType === 'video') {
72938
+ // Dispose the video media
72939
+ console.debug("VideoMedia::stop - ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72940
+ VideoMedia(media, xlr).stop(true);
72941
+ }
72893
72942
  }
72894
72943
  }, 1000);
72895
72944
  console.debug('startMediaTimer: Showing Media ' + media.id + ' for ' + media.duration + 's of Region ' + media.region.regionId);
72896
72945
  };
72897
72946
  emitter.on('start', function (media) {
72898
72947
  if (media.mediaType === 'video') {
72899
- VideoMedia(media, xlr).init();
72948
+ var videoMedia = VideoMedia(media, xlr);
72949
+ videoMedia.init();
72900
72950
  if (media.duration > 0) {
72901
72951
  startMediaTimer(media);
72902
72952
  }
@@ -73217,7 +73267,7 @@ function Media(region, mediaId, xml, options, xlr) {
73217
73267
  controls: false,
73218
73268
  preload: 'auto',
73219
73269
  autoplay: false,
73220
- muted: self.muted,
73270
+ muted: true,
73221
73271
  errorDisplay: xlr.config.platform !== 'chromeOS',
73222
73272
  loop: self.loop
73223
73273
  });
@@ -74686,5 +74736,5 @@ function XiboLayoutRenderer(inputLayouts, options) {
74686
74736
  return xlrObject;
74687
74737
  }
74688
74738
 
74689
- export { Action, ActionsWrapper, AudioMedia, ELayoutType, Media, Region, VideoMedia, audioFileType, capitalizeStr, XiboLayoutRenderer as default, defaultTrans, fadeInElem, fadeOutElem, fetchJSON, flyInElem, flyOutElem, flyTransitionKeyframes, getFileExt, getLayout, getMediaId, getXlf, initRenderingDOM, initialLayout, initialMedia, initialRegion, initialXlr, nextId, platform, preloadMediaBlob, setExpiry, transitionElement, videoFileType };
74739
+ export { Action, ActionsWrapper, AudioMedia, ELayoutType, Media, Region, VideoMedia, audioFileType, capitalizeStr, composeBgUrlByPlatform, composeMediaUrl, composeResourceUrl, composeResourceUrlByPlatform, XiboLayoutRenderer as default, defaultTrans, fadeInElem, fadeOutElem, fetchJSON, fetchText, flyInElem, flyOutElem, flyTransitionKeyframes, getDataBlob, getFileExt, getIndexByLayoutId, getLayout, getMediaId, getXlf, initRenderingDOM, initialLayout, initialMedia, initialRegion, initialXlr, isEmpty$1 as isEmpty, nextId, platform, preloadMediaBlob, setExpiry, transitionElement, videoFileType };
74690
74740
  //# sourceMappingURL=xibo-layout-renderer.esm.js.map