@xibosignage/xibo-layout-renderer 1.0.12 → 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,
@@ -73,6 +74,7 @@ interface IMedia {
73
74
  emitter: Emitter<IMediaEvents>;
74
75
  enableStat: boolean;
75
76
  muted?: boolean;
77
+ player?: Player;
76
78
  }
77
79
  declare const initialMedia: IMedia;
78
80
 
@@ -69558,7 +69558,8 @@ var initialMedia = {
69558
69558
  },
69559
69559
  emitter: {},
69560
69560
  enableStat: false,
69561
- muted: false
69561
+ muted: false,
69562
+ player: undefined
69562
69563
  };
69563
69564
 
69564
69565
  /*
@@ -72621,166 +72622,149 @@ function PwaSW() {
72621
72622
  };
72622
72623
  }
72623
72624
 
72624
- function composeVideoSource(_x, _x2) {
72625
- return _composeVideoSource.apply(this, arguments);
72626
- }
72627
- function _composeVideoSource() {
72628
- _composeVideoSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4($media, media) {
72629
- var videoSrc, vidType, $videoSource;
72630
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
72631
- while (1) switch (_context4.prev = _context4.next) {
72632
- case 0:
72633
- _context4.next = 2;
72634
- return preloadMediaBlob(media.url, media.mediaType);
72635
- case 2:
72636
- videoSrc = _context4.sent;
72637
- vidType = videoFileType(getFileExt(media.uri)); // Only add one source per type
72638
- if ($media.querySelectorAll("source[type=\"".concat(vidType, "\"]")).length === 0) {
72639
- $videoSource = document.createElement('source');
72640
- $videoSource.src = videoSrc;
72641
- $videoSource.type = vidType;
72642
- $media.insertBefore($videoSource, $media.lastElementChild);
72643
- }
72644
- return _context4.abrupt("return", $media);
72645
- case 6:
72646
- case "end":
72647
- return _context4.stop();
72648
- }
72649
- }, _callee4);
72650
- }));
72651
- 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;
72652
72636
  }
72653
72637
  function VideoMedia(media, xlr) {
72654
72638
  return {
72655
72639
  init: function init() {
72656
- var $videoMedia = document.getElementById(getMediaId(media));
72657
- if ($videoMedia) {
72658
- var vjsPlayer = videojs.getPlayer($videoMedia);
72659
- if (vjsPlayer !== undefined) {
72660
- var playerReportFault = /*#__PURE__*/function () {
72661
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(msg) {
72662
- var playerSW, hasSW;
72663
- return _regeneratorRuntime().wrap(function _callee$(_context) {
72664
- while (1) switch (_context.prev = _context.next) {
72665
- case 0:
72666
- // Immediately expire media and report a fault
72667
- playerSW = PwaSW();
72668
- _context.next = 3;
72669
- return playerSW.getSW();
72670
- case 3:
72671
- hasSW = _context.sent;
72672
- if (hasSW) {
72673
- playerSW.postMsg({
72674
- type: 'MEDIA_FAULT',
72675
- code: 5002,
72676
- reason: msg,
72677
- mediaId: media.id,
72678
- regionId: media.region.id,
72679
- layoutId: media.region.layout.id,
72680
- date: format(new Date(), 'yyyy-MM-dd HH:mm:ss'),
72681
- // Temporary setting
72682
- expires: format(new Date(setExpiry(1)), 'yyyy-MM-dd HH:mm:ss')
72683
- })["finally"](function () {
72684
- // Expire the media and dispose the video
72685
- vjsPlayer.dispose();
72686
- media.emitter.emit('end', media);
72687
- });
72688
- }
72689
- case 5:
72690
- case "end":
72691
- return _context.stop();
72692
- }
72693
- }, _callee);
72694
- }));
72695
- return function playerReportFault(_x3) {
72696
- return _ref.apply(this, arguments);
72697
- };
72698
- }();
72699
- vjsPlayer.on('loadstart', function () {
72700
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has started loading data . . ."));
72701
- });
72702
- vjsPlayer.on('canplay', function () {
72703
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " can be played . . ."));
72704
- });
72705
- vjsPlayer.ready(function () {
72706
- var promise = vjsPlayer.play();
72707
- if (promise !== undefined) {
72708
- promise.then(function () {
72709
- // Autoplay restarted
72710
- console.debug('autoplay started . . .');
72711
- vjsPlayer.muted(true);
72712
- })["catch"]( /*#__PURE__*/function () {
72713
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(error) {
72714
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
72715
- while (1) switch (_context2.prev = _context2.next) {
72716
- case 0:
72717
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " autoplay error"));
72718
- if (!(xlr.config.platform === 'chromeOS')) {
72719
- _context2.next = 4;
72720
- break;
72721
- }
72640
+ var vjsPlayer = media.player;
72641
+ if (vjsPlayer !== undefined) {
72642
+ var playerReportFault = /*#__PURE__*/function () {
72643
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(msg) {
72644
+ var playerSW, hasSW;
72645
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
72646
+ while (1) switch (_context.prev = _context.next) {
72647
+ case 0:
72648
+ // Immediately expire media and report a fault
72649
+ playerSW = PwaSW();
72650
+ _context.next = 3;
72651
+ return playerSW.getSW();
72652
+ case 3:
72653
+ hasSW = _context.sent;
72654
+ if (hasSW) {
72655
+ playerSW.postMsg({
72656
+ type: 'MEDIA_FAULT',
72657
+ code: 5002,
72658
+ reason: msg,
72659
+ mediaId: media.id,
72660
+ regionId: media.region.id,
72661
+ layoutId: media.region.layout.id,
72662
+ date: format(new Date(), 'yyyy-MM-dd HH:mm:ss'),
72663
+ // Temporary setting
72664
+ expires: format(new Date(setExpiry(1)), 'yyyy-MM-dd HH:mm:ss')
72665
+ })["finally"](function () {
72666
+ // Expire the media and dispose the video
72667
+ vjsPlayer.dispose();
72668
+ media.emitter.emit('end', media);
72669
+ });
72670
+ }
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')) {
72722
72701
  _context2.next = 4;
72723
- return playerReportFault('Media autoplay error');
72724
- case 4:
72725
- case "end":
72726
- return _context2.stop();
72727
- }
72728
- }, _callee2);
72729
- }));
72730
- return function (_x4) {
72731
- return _ref2.apply(this, arguments);
72732
- };
72733
- }());
72734
- }
72735
- });
72736
- vjsPlayer.on('playing', function () {
72737
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " is now playing . . ."));
72738
- vjsPlayer.muted(media.muted);
72739
- });
72740
- vjsPlayer.on('error', /*#__PURE__*/function () {
72741
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(err) {
72742
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
72743
- while (1) switch (_context3.prev = _context3.next) {
72744
- case 0:
72745
- console.debug("Media Error: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id));
72746
- if (!(xlr.config.platform === 'chromeOS')) {
72747
- _context3.next = 6;
72748
- break;
72749
- }
72750
- _context3.next = 4;
72751
- return playerReportFault('Video file source not supported');
72752
- case 4:
72753
- _context3.next = 7;
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;
72754
72730
  break;
72755
- case 6:
72756
- // End media after 5 seconds
72757
- setTimeout(function () {
72758
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended . . ."));
72759
- media.emitter.emit('end', media);
72760
- vjsPlayer.dispose();
72761
- }, 5000);
72762
- case 7:
72763
- case "end":
72764
- return _context3.stop();
72765
- }
72766
- }, _callee3);
72767
- }));
72768
- return function (_x5) {
72769
- return _ref3.apply(this, arguments);
72770
- };
72771
- }());
72772
- if (media.duration === 0) {
72773
- vjsPlayer.on('durationchange', function () {
72774
- console.debug('Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72775
- });
72776
- vjsPlayer.on('ended', function () {
72777
- var _media$emitter;
72778
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72779
- vjsPlayer.dispose();
72780
- (_media$emitter = media.emitter) === null || _media$emitter === void 0 || _media$emitter.emit('end', media);
72781
- });
72731
+ }
72732
+ _context3.next = 4;
72733
+ return playerReportFault('Video file source not supported');
72734
+ case 4:
72735
+ _context3.next = 7;
72736
+ break;
72737
+ case 6:
72738
+ // End media after 5 seconds
72739
+ setTimeout(function () {
72740
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended . . ."));
72741
+ media.emitter.emit('end', media);
72742
+ vjsPlayer.dispose();
72743
+ }, 5000);
72744
+ case 7:
72745
+ case "end":
72746
+ return _context3.stop();
72747
+ }
72748
+ }, _callee3);
72749
+ }));
72750
+ return function (_x3) {
72751
+ return _ref3.apply(this, arguments);
72752
+ };
72753
+ }());
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);
72782
72765
  }
72783
- }
72766
+ console.debug('VIDEOJS: ondurationchange: Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72767
+ });
72784
72768
  }
72785
72769
  }
72786
72770
  };
@@ -72861,10 +72845,11 @@ function Media(region, mediaId, xml, options, xlr) {
72861
72845
  mediaTimer = setInterval(function () {
72862
72846
  mediaTimeCount++;
72863
72847
  if (mediaTimeCount > media.duration) {
72848
+ console.debug('startMediaTimer: emit>end: on media ' + media.id + ' of Region ' + media.region.regionId);
72864
72849
  media.emitter.emit('end', media);
72865
72850
  }
72866
72851
  }, 1000);
72867
- 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);
72868
72853
  };
72869
72854
  emitter.on('start', function (media) {
72870
72855
  if (media.mediaType === 'video') {
@@ -73019,8 +73004,11 @@ function Media(region, mediaId, xml, options, xlr) {
73019
73004
  $media.style.cssText = $media.style.cssText.concat("background-position: ".concat(align, " ").concat(valign));
73020
73005
  }
73021
73006
  } else if (self.mediaType === 'video') {
73022
- var $videoMedia = $media;
73023
- $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
+ }
73024
73012
  if (Boolean(self.options['scaletype'])) {
73025
73013
  if (self.options.scaletype === 'stretch') {
73026
73014
  $videoMedia.style.objectFit = 'fill';
@@ -73028,8 +73016,10 @@ function Media(region, mediaId, xml, options, xlr) {
73028
73016
  }
73029
73017
  $videoMedia.classList.add('video-js', 'vjs-default-skin');
73030
73018
  if (self.loop) {
73019
+ self.loop = true;
73031
73020
  $videoMedia.loop = true;
73032
73021
  }
73022
+ self.muted = isMuted;
73033
73023
  $media = $videoMedia;
73034
73024
  } else if (self.mediaType === 'audio') {
73035
73025
  var $audioMedia = $media;
@@ -73132,7 +73122,7 @@ function Media(region, mediaId, xml, options, xlr) {
73132
73122
  }
73133
73123
  var showCurrentMedia = /*#__PURE__*/function () {
73134
73124
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
73135
- var $mediaId, $media, isCMS, isMuted;
73125
+ var $mediaId, $media, isCMS;
73136
73126
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
73137
73127
  while (1) switch (_context2.prev = _context2.next) {
73138
73128
  case 0:
@@ -73143,7 +73133,7 @@ function Media(region, mediaId, xml, options, xlr) {
73143
73133
  $media = getNewMedia();
73144
73134
  }
73145
73135
  if (!$media) {
73146
- _context2.next = 45;
73136
+ _context2.next = 40;
73147
73137
  break;
73148
73138
  }
73149
73139
  $media.style.setProperty('display', 'block');
@@ -73172,54 +73162,48 @@ function Media(region, mediaId, xml, options, xlr) {
73172
73162
  _context2.t3 = _context2.t2;
73173
73163
  _context2.t4 = _context2.t1.concat.call(_context2.t1, _context2.t3);
73174
73164
  _context2.t0.setProperty.call(_context2.t0, 'background-image', _context2.t4);
73175
- _context2.next = 44;
73165
+ _context2.next = 39;
73176
73166
  break;
73177
73167
  case 22:
73178
73168
  if (!(self.mediaType === 'video' && self.url !== null)) {
73179
- _context2.next = 32;
73169
+ _context2.next = 27;
73180
73170
  break;
73181
73171
  }
73182
- _context2.next = 25;
73183
- return composeVideoSource($media, self);
73184
- case 25:
73185
- $media = _context2.sent;
73186
- isMuted = false;
73187
- if (Boolean(self.options['mute'])) {
73188
- isMuted = self.options.mute === '1';
73189
- }
73190
- self.muted = isMuted;
73172
+ // Initialize video.js
73191
73173
  videojs($media, {
73192
73174
  controls: false,
73193
73175
  preload: 'auto',
73194
73176
  autoplay: false,
73195
- muted: isMuted,
73177
+ muted: self.muted,
73196
73178
  errorDisplay: xlr.config.platform !== 'chromeOS',
73197
- restoreEl: $media
73179
+ restoreEl: $media,
73180
+ loop: self.loop
73198
73181
  });
73199
- _context2.next = 44;
73182
+ self.player = videojs($media);
73183
+ _context2.next = 39;
73200
73184
  break;
73201
- case 32:
73185
+ case 27:
73202
73186
  if (!(self.mediaType === 'audio' && self.url !== null)) {
73203
- _context2.next = 43;
73187
+ _context2.next = 38;
73204
73188
  break;
73205
73189
  }
73206
73190
  if (!isCMS) {
73207
- _context2.next = 39;
73191
+ _context2.next = 34;
73208
73192
  break;
73209
73193
  }
73210
- _context2.next = 36;
73194
+ _context2.next = 31;
73211
73195
  return preloadMediaBlob(self.url, self.mediaType);
73212
- case 36:
73196
+ case 31:
73213
73197
  _context2.t5 = _context2.sent;
73214
- _context2.next = 40;
73198
+ _context2.next = 35;
73215
73199
  break;
73216
- case 39:
73200
+ case 34:
73217
73201
  _context2.t5 = self.url;
73218
- case 40:
73202
+ case 35:
73219
73203
  $media.src = _context2.t5;
73220
- _context2.next = 44;
73204
+ _context2.next = 39;
73221
73205
  break;
73222
- case 43:
73206
+ case 38:
73223
73207
  if ((self.render === 'html' || self.mediaType === 'webpage') && self.iframe && self.checkIframeStatus) {
73224
73208
  // Set state as false ( for now )
73225
73209
  self.ready = false;
@@ -73235,9 +73219,9 @@ function Media(region, mediaId, xml, options, xlr) {
73235
73219
  // }
73236
73220
  // });
73237
73221
  }
73238
- case 44:
73222
+ case 39:
73239
73223
  self.emitter.emit('start', self);
73240
- case 45:
73224
+ case 40:
73241
73225
  case "end":
73242
73226
  return _context2.stop();
73243
73227
  }
@@ -73362,7 +73346,7 @@ function Region(layout, xml, regionId, options, xlr) {
73362
73346
  console.debug('Region::finished called . . . ', self.id);
73363
73347
  // Mark as complete
73364
73348
  self.complete = true;
73365
- self.layout.regions[regionObject.index] = regionObject;
73349
+ self.layout.regions[regionObject.index] = self;
73366
73350
  self.layout.regionExpired();
73367
73351
  };
73368
73352
  regionObject.prepareMediaObjects = function () {
@@ -73484,7 +73468,7 @@ function Region(layout, xml, regionId, options, xlr) {
73484
73468
  }
73485
73469
  };
73486
73470
  regionObject.playNextMedia = function () {
73487
- var _self$curMedia, _self$curMedia2, _self$curMedia3, _self$curMedia4;
73471
+ var _self$curMedia, _self$curMedia2, _self$curMedia3, _self$curMedia4, _self$curMedia5;
73488
73472
  var self = regionObject;
73489
73473
  /* The current media has finished running */
73490
73474
  if (self.ended) {
@@ -73504,7 +73488,7 @@ function Region(layout, xml, regionId, options, xlr) {
73504
73488
  // When the region has completed and mediaObjects.length = 1
73505
73489
  // and curMedia.loop = false, then put the media on
73506
73490
  // its current state
73507
- 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)) {
73508
73492
  return;
73509
73493
  }
73510
73494
  self.currentMediaIndex = self.currentMediaIndex + 1;