@xibosignage/xibo-layout-renderer 1.0.11 → 1.0.13

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 { Emitter, Unsubscribe, DefaultEvents } from 'nanoevents';
2
+ import Player from 'video.js/dist/types/player';
2
3
 
3
4
  declare enum ELayoutType {
4
5
  CURRENT = 0,
@@ -72,6 +73,8 @@ interface IMedia {
72
73
  fileId: string;
73
74
  emitter: Emitter<IMediaEvents>;
74
75
  enableStat: boolean;
76
+ muted?: boolean;
77
+ player?: Player;
75
78
  }
76
79
  declare const initialMedia: IMedia;
77
80
 
@@ -265,7 +268,7 @@ declare function videoFileType(str: string): string | undefined;
265
268
  declare function setExpiry(numDays: number): string;
266
269
 
267
270
  declare function VideoMedia(media: IMedia, xlr: IXlr): {
268
- init(): void;
271
+ init: () => void;
269
272
  };
270
273
 
271
274
  declare function AudioMedia(media: IMedia): {
@@ -69557,7 +69557,9 @@ var initialMedia = {
69557
69557
  return {};
69558
69558
  },
69559
69559
  emitter: {},
69560
- enableStat: false
69560
+ enableStat: false,
69561
+ muted: false,
69562
+ player: undefined
69561
69563
  };
69562
69564
 
69563
69565
  /*
@@ -72620,123 +72622,149 @@ function PwaSW() {
72620
72622
  };
72621
72623
  }
72622
72624
 
72623
- function composeVideoSource(_x, _x2) {
72624
- return _composeVideoSource.apply(this, arguments);
72625
- }
72626
- function _composeVideoSource() {
72627
- _composeVideoSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2($media, media) {
72628
- var videoSrc, vidType, $videoSource;
72629
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
72630
- while (1) switch (_context2.prev = _context2.next) {
72631
- case 0:
72632
- _context2.next = 2;
72633
- return preloadMediaBlob(media.url, media.mediaType);
72634
- case 2:
72635
- videoSrc = _context2.sent;
72636
- vidType = videoFileType(getFileExt(media.uri)); // Only add one source per type
72637
- if ($media.querySelectorAll("source[type=\"".concat(vidType, "\"]")).length === 0) {
72638
- $videoSource = document.createElement('source');
72639
- $videoSource.src = videoSrc;
72640
- $videoSource.type = vidType;
72641
- $media.insertBefore($videoSource, $media.lastElementChild);
72642
- }
72643
- return _context2.abrupt("return", $media);
72644
- case 6:
72645
- case "end":
72646
- return _context2.stop();
72647
- }
72648
- }, _callee2);
72649
- }));
72650
- return _composeVideoSource.apply(this, arguments);
72625
+ function composeVideoSource($media, media) {
72626
+ // const videoSrc = await preloadMediaBlob(media.url as string, media.mediaType as MediaTypes);
72627
+ var vidType = videoFileType(getFileExt(media.uri));
72628
+ // Only add one source per type
72629
+ if ($media.querySelectorAll("source[type=\"".concat(vidType, "\"]")).length === 0) {
72630
+ var $videoSource = document.createElement('source');
72631
+ $videoSource.src = media.url;
72632
+ $videoSource.type = vidType;
72633
+ $media.insertBefore($videoSource, $media.lastElementChild);
72634
+ }
72635
+ return $media;
72651
72636
  }
72652
72637
  function VideoMedia(media, xlr) {
72653
72638
  return {
72654
72639
  init: function init() {
72655
- var $videoMedia = document.getElementById(getMediaId(media));
72656
- if ($videoMedia) {
72657
- var vjsPlayer = videojs.getPlayer($videoMedia);
72658
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('loadstart', function () {
72659
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has started loading data . . ."));
72660
- });
72661
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('loadstart', function () {
72662
- if ($videoMedia.readyState >= 2) {
72663
- console.debug("".concat(capitalizeStr(media.mediaType), " data for media > ").concat(media.id, " has been fully loaded . . ."));
72664
- }
72665
- });
72666
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('canplay', function () {
72667
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " can be played . . ."));
72668
- // Autoplay restarted
72669
- console.debug('autoplay started . . .');
72670
- vjsPlayer.muted(true);
72671
- vjsPlayer.play();
72672
- });
72673
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('playing', function () {
72674
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " is now playing . . ."));
72675
- });
72676
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('error', /*#__PURE__*/function () {
72677
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(err) {
72640
+ var vjsPlayer = media.player;
72641
+ if (vjsPlayer !== undefined) {
72642
+ var playerReportFault = /*#__PURE__*/function () {
72643
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(msg) {
72678
72644
  var playerSW, hasSW;
72679
72645
  return _regeneratorRuntime().wrap(function _callee$(_context) {
72680
72646
  while (1) switch (_context.prev = _context.next) {
72681
72647
  case 0:
72682
- console.debug("Media Error: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id));
72683
- if (!(xlr.config.platform === 'chromeOS')) {
72684
- _context.next = 9;
72685
- break;
72686
- }
72687
72648
  // Immediately expire media and report a fault
72688
72649
  playerSW = PwaSW();
72689
- _context.next = 5;
72650
+ _context.next = 3;
72690
72651
  return playerSW.getSW();
72691
- case 5:
72652
+ case 3:
72692
72653
  hasSW = _context.sent;
72693
72654
  if (hasSW) {
72694
72655
  playerSW.postMsg({
72695
72656
  type: 'MEDIA_FAULT',
72696
72657
  code: 5002,
72697
- reason: 'Video file source not supported',
72658
+ reason: msg,
72698
72659
  mediaId: media.id,
72699
72660
  regionId: media.region.id,
72700
72661
  layoutId: media.region.layout.id,
72701
72662
  date: format(new Date(), 'yyyy-MM-dd HH:mm:ss'),
72702
72663
  // Temporary setting
72703
- expires: format(new Date(setExpiry(7)), 'yyyy-MM-dd HH:mm:ss')
72664
+ expires: format(new Date(setExpiry(1)), 'yyyy-MM-dd HH:mm:ss')
72704
72665
  })["finally"](function () {
72705
72666
  // Expire the media and dispose the video
72706
72667
  vjsPlayer.dispose();
72707
72668
  media.emitter.emit('end', media);
72708
72669
  });
72709
72670
  }
72710
- _context.next = 10;
72671
+ case 5:
72672
+ case "end":
72673
+ return _context.stop();
72674
+ }
72675
+ }, _callee);
72676
+ }));
72677
+ return function playerReportFault(_x) {
72678
+ return _ref.apply(this, arguments);
72679
+ };
72680
+ }();
72681
+ vjsPlayer.on('loadstart', function () {
72682
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has started loading data . . ."));
72683
+ });
72684
+ vjsPlayer.on('canplay', function () {
72685
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " can be played . . ."));
72686
+ });
72687
+ vjsPlayer.on('ready', function () {
72688
+ vjsPlayer.muted(true);
72689
+ var promise = vjsPlayer.play();
72690
+ if (promise !== undefined) {
72691
+ promise.then(function () {
72692
+ // Autoplay restarted
72693
+ console.debug('autoplay started . . .');
72694
+ })["catch"]( /*#__PURE__*/function () {
72695
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(error) {
72696
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
72697
+ while (1) switch (_context2.prev = _context2.next) {
72698
+ case 0:
72699
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " autoplay error"));
72700
+ if (!(xlr.config.platform === 'chromeOS')) {
72701
+ _context2.next = 4;
72702
+ break;
72703
+ }
72704
+ _context2.next = 4;
72705
+ return playerReportFault('Media autoplay error');
72706
+ case 4:
72707
+ case "end":
72708
+ return _context2.stop();
72709
+ }
72710
+ }, _callee2);
72711
+ }));
72712
+ return function (_x2) {
72713
+ return _ref2.apply(this, arguments);
72714
+ };
72715
+ }());
72716
+ }
72717
+ });
72718
+ vjsPlayer.on('playing', function () {
72719
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " is now playing . . ."));
72720
+ vjsPlayer.muted(media.muted);
72721
+ });
72722
+ vjsPlayer.on('error', /*#__PURE__*/function () {
72723
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(err) {
72724
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
72725
+ while (1) switch (_context3.prev = _context3.next) {
72726
+ case 0:
72727
+ console.debug("Media Error: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id));
72728
+ if (!(xlr.config.platform === 'chromeOS')) {
72729
+ _context3.next = 6;
72730
+ break;
72731
+ }
72732
+ _context3.next = 4;
72733
+ return playerReportFault('Video file source not supported');
72734
+ case 4:
72735
+ _context3.next = 7;
72711
72736
  break;
72712
- case 9:
72737
+ case 6:
72713
72738
  // End media after 5 seconds
72714
72739
  setTimeout(function () {
72715
72740
  console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended . . ."));
72716
72741
  media.emitter.emit('end', media);
72717
72742
  vjsPlayer.dispose();
72718
72743
  }, 5000);
72719
- case 10:
72744
+ case 7:
72720
72745
  case "end":
72721
- return _context.stop();
72746
+ return _context3.stop();
72722
72747
  }
72723
- }, _callee);
72748
+ }, _callee3);
72724
72749
  }));
72725
72750
  return function (_x3) {
72726
- return _ref.apply(this, arguments);
72751
+ return _ref3.apply(this, arguments);
72727
72752
  };
72728
72753
  }());
72729
- if (media.duration === 0) {
72730
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('durationchange', function () {
72731
- console.debug('Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72732
- });
72733
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('ended', function () {
72734
- var _media$emitter;
72735
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72736
- (_media$emitter = media.emitter) === null || _media$emitter === void 0 || _media$emitter.emit('end', media);
72737
- vjsPlayer.dispose();
72738
- });
72739
- }
72754
+ vjsPlayer.on('ended', function () {
72755
+ var _media$emitter;
72756
+ console.debug("VideoMedia: onended: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72757
+ (_media$emitter = media.emitter) === null || _media$emitter === void 0 || _media$emitter.emit('end', media);
72758
+ vjsPlayer.dispose();
72759
+ });
72760
+ vjsPlayer.on('durationchange', function () {
72761
+ if (media.duration === 0 && vjsPlayer.duration() !== undefined) {
72762
+ media.duration = vjsPlayer.duration();
72763
+ } else if (media.duration > 0) {
72764
+ vjsPlayer.duration(media.duration);
72765
+ }
72766
+ console.debug('VIDEOJS: ondurationchange: Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72767
+ });
72740
72768
  }
72741
72769
  }
72742
72770
  };
@@ -72817,10 +72845,11 @@ function Media(region, mediaId, xml, options, xlr) {
72817
72845
  mediaTimer = setInterval(function () {
72818
72846
  mediaTimeCount++;
72819
72847
  if (mediaTimeCount > media.duration) {
72848
+ console.debug('startMediaTimer: emit>end: on media ' + media.id + ' of Region ' + media.region.regionId);
72820
72849
  media.emitter.emit('end', media);
72821
72850
  }
72822
72851
  }, 1000);
72823
- console.debug('Showing Media ' + media.id + ' for ' + media.duration + 's of Region ' + media.region.regionId);
72852
+ console.debug('startMediaTimer: Showing Media ' + media.id + ' for ' + media.duration + 's of Region ' + media.region.regionId);
72824
72853
  };
72825
72854
  emitter.on('start', function (media) {
72826
72855
  if (media.mediaType === 'video') {
@@ -72948,7 +72977,7 @@ function Media(region, mediaId, xml, options, xlr) {
72948
72977
  tmpUrl = composeResourceUrlByPlatform(xlr.config, resourceUrlParams);
72949
72978
  } else if (xlr.config.platform === 'chromeOS') {
72950
72979
  tmpUrl = composeResourceUrl(xlr.config, resourceUrlParams);
72951
- if (self.mediaType === 'image' || self.mediaType === 'video') {
72980
+ if (self.mediaType === 'image' || self.mediaType === 'video' || self.mediaType === 'audio') {
72952
72981
  tmpUrl = composeMediaUrl(resourceUrlParams);
72953
72982
  }
72954
72983
  }
@@ -72975,8 +73004,11 @@ function Media(region, mediaId, xml, options, xlr) {
72975
73004
  $media.style.cssText = $media.style.cssText.concat("background-position: ".concat(align, " ").concat(valign));
72976
73005
  }
72977
73006
  } else if (self.mediaType === 'video') {
72978
- var $videoMedia = $media;
72979
- $videoMedia.textContent = 'Unsupported Video';
73007
+ var $videoMedia = composeVideoSource($media, self);
73008
+ var isMuted = false;
73009
+ if (Boolean(self.options['mute'])) {
73010
+ isMuted = self.options.mute === '1';
73011
+ }
72980
73012
  if (Boolean(self.options['scaletype'])) {
72981
73013
  if (self.options.scaletype === 'stretch') {
72982
73014
  $videoMedia.style.objectFit = 'fill';
@@ -72984,8 +73016,10 @@ function Media(region, mediaId, xml, options, xlr) {
72984
73016
  }
72985
73017
  $videoMedia.classList.add('video-js', 'vjs-default-skin');
72986
73018
  if (self.loop) {
73019
+ self.loop = true;
72987
73020
  $videoMedia.loop = true;
72988
73021
  }
73022
+ self.muted = isMuted;
72989
73023
  $media = $videoMedia;
72990
73024
  } else if (self.mediaType === 'audio') {
72991
73025
  var $audioMedia = $media;
@@ -73088,7 +73122,7 @@ function Media(region, mediaId, xml, options, xlr) {
73088
73122
  }
73089
73123
  var showCurrentMedia = /*#__PURE__*/function () {
73090
73124
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
73091
- var $mediaId, $media, isCMS, isMuted;
73125
+ var $mediaId, $media, isCMS;
73092
73126
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
73093
73127
  while (1) switch (_context2.prev = _context2.next) {
73094
73128
  case 0:
@@ -73099,7 +73133,7 @@ function Media(region, mediaId, xml, options, xlr) {
73099
73133
  $media = getNewMedia();
73100
73134
  }
73101
73135
  if (!$media) {
73102
- _context2.next = 44;
73136
+ _context2.next = 40;
73103
73137
  break;
73104
73138
  }
73105
73139
  $media.style.setProperty('display', 'block');
@@ -73128,52 +73162,48 @@ function Media(region, mediaId, xml, options, xlr) {
73128
73162
  _context2.t3 = _context2.t2;
73129
73163
  _context2.t4 = _context2.t1.concat.call(_context2.t1, _context2.t3);
73130
73164
  _context2.t0.setProperty.call(_context2.t0, 'background-image', _context2.t4);
73131
- _context2.next = 43;
73165
+ _context2.next = 39;
73132
73166
  break;
73133
73167
  case 22:
73134
73168
  if (!(self.mediaType === 'video' && self.url !== null)) {
73135
- _context2.next = 31;
73169
+ _context2.next = 27;
73136
73170
  break;
73137
73171
  }
73138
- _context2.next = 25;
73139
- return composeVideoSource($media, self);
73140
- case 25:
73141
- $media = _context2.sent;
73142
- isMuted = false;
73143
- if (Boolean(self.options['mute'])) {
73144
- isMuted = self.options.mute === '1';
73145
- }
73172
+ // Initialize video.js
73146
73173
  videojs($media, {
73147
73174
  controls: false,
73148
73175
  preload: 'auto',
73149
73176
  autoplay: false,
73150
- muted: isMuted,
73151
- errorDisplay: xlr.config.platform !== 'chromeOS'
73177
+ muted: self.muted,
73178
+ errorDisplay: xlr.config.platform !== 'chromeOS',
73179
+ restoreEl: $media,
73180
+ loop: self.loop
73152
73181
  });
73153
- _context2.next = 43;
73182
+ self.player = videojs($media);
73183
+ _context2.next = 39;
73154
73184
  break;
73155
- case 31:
73185
+ case 27:
73156
73186
  if (!(self.mediaType === 'audio' && self.url !== null)) {
73157
- _context2.next = 42;
73187
+ _context2.next = 38;
73158
73188
  break;
73159
73189
  }
73160
73190
  if (!isCMS) {
73161
- _context2.next = 38;
73191
+ _context2.next = 34;
73162
73192
  break;
73163
73193
  }
73164
- _context2.next = 35;
73194
+ _context2.next = 31;
73165
73195
  return preloadMediaBlob(self.url, self.mediaType);
73166
- case 35:
73196
+ case 31:
73167
73197
  _context2.t5 = _context2.sent;
73168
- _context2.next = 39;
73198
+ _context2.next = 35;
73169
73199
  break;
73170
- case 38:
73200
+ case 34:
73171
73201
  _context2.t5 = self.url;
73172
- case 39:
73202
+ case 35:
73173
73203
  $media.src = _context2.t5;
73174
- _context2.next = 43;
73204
+ _context2.next = 39;
73175
73205
  break;
73176
- case 42:
73206
+ case 38:
73177
73207
  if ((self.render === 'html' || self.mediaType === 'webpage') && self.iframe && self.checkIframeStatus) {
73178
73208
  // Set state as false ( for now )
73179
73209
  self.ready = false;
@@ -73189,9 +73219,9 @@ function Media(region, mediaId, xml, options, xlr) {
73189
73219
  // }
73190
73220
  // });
73191
73221
  }
73192
- case 43:
73222
+ case 39:
73193
73223
  self.emitter.emit('start', self);
73194
- case 44:
73224
+ case 40:
73195
73225
  case "end":
73196
73226
  return _context2.stop();
73197
73227
  }
@@ -73316,7 +73346,7 @@ function Region(layout, xml, regionId, options, xlr) {
73316
73346
  console.debug('Region::finished called . . . ', self.id);
73317
73347
  // Mark as complete
73318
73348
  self.complete = true;
73319
- self.layout.regions[regionObject.index] = regionObject;
73349
+ self.layout.regions[regionObject.index] = self;
73320
73350
  self.layout.regionExpired();
73321
73351
  };
73322
73352
  regionObject.prepareMediaObjects = function () {
@@ -73438,7 +73468,7 @@ function Region(layout, xml, regionId, options, xlr) {
73438
73468
  }
73439
73469
  };
73440
73470
  regionObject.playNextMedia = function () {
73441
- var _self$curMedia, _self$curMedia2, _self$curMedia3, _self$curMedia4;
73471
+ var _self$curMedia, _self$curMedia2, _self$curMedia3, _self$curMedia4, _self$curMedia5;
73442
73472
  var self = regionObject;
73443
73473
  /* The current media has finished running */
73444
73474
  if (self.ended) {
@@ -73458,7 +73488,7 @@ function Region(layout, xml, regionId, options, xlr) {
73458
73488
  // When the region has completed and mediaObjects.length = 1
73459
73489
  // and curMedia.loop = false, then put the media on
73460
73490
  // its current state
73461
- if (self.complete && self.mediaObjects.length === 1 && ((_self$curMedia2 = self.curMedia) === null || _self$curMedia2 === void 0 ? void 0 : _self$curMedia2.render) !== 'html' && ((_self$curMedia3 = self.curMedia) === null || _self$curMedia3 === void 0 ? void 0 : _self$curMedia3.mediaType) === 'image' && !((_self$curMedia4 = self.curMedia) !== null && _self$curMedia4 !== void 0 && _self$curMedia4.loop)) {
73491
+ if (self.complete && self.mediaObjects.length === 1 && ((_self$curMedia2 = self.curMedia) === null || _self$curMedia2 === void 0 ? void 0 : _self$curMedia2.render) !== 'html' && (((_self$curMedia3 = self.curMedia) === null || _self$curMedia3 === void 0 ? void 0 : _self$curMedia3.mediaType) === 'image' || ((_self$curMedia4 = self.curMedia) === null || _self$curMedia4 === void 0 ? void 0 : _self$curMedia4.mediaType) === 'video') && !((_self$curMedia5 = self.curMedia) !== null && _self$curMedia5 !== void 0 && _self$curMedia5.loop)) {
73462
73492
  return;
73463
73493
  }
73464
73494
  self.currentMediaIndex = self.currentMediaIndex + 1;