@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,6 +1,6 @@
1
1
  import { IMedia } from '../../Types/Media';
2
2
  import { IXlr } from '../../types';
3
- export declare function composeVideoSource($media: HTMLVideoElement, media: IMedia): Promise<HTMLVideoElement>;
3
+ export declare function composeVideoSource($media: HTMLVideoElement, media: IMedia): HTMLVideoElement;
4
4
  export default function VideoMedia(media: IMedia, xlr: IXlr): {
5
5
  init: () => void;
6
6
  };
@@ -1,4 +1,5 @@
1
1
  import { Emitter, Unsubscribe } from 'nanoevents';
2
+ import Player from "video.js/dist/types/player";
2
3
  import { IMediaEvents } from '../../Modules/Media/Media';
3
4
  import { IRegion } from '../Region';
4
5
  import { OptionsType } from '../Layout';
@@ -43,5 +44,6 @@ export interface IMedia {
43
44
  emitter: Emitter<IMediaEvents>;
44
45
  enableStat: boolean;
45
46
  muted?: boolean;
47
+ player?: Player;
46
48
  }
47
49
  export declare const initialMedia: IMedia;
@@ -69562,7 +69562,8 @@ var initialMedia = {
69562
69562
  },
69563
69563
  emitter: {},
69564
69564
  enableStat: false,
69565
- muted: false
69565
+ muted: false,
69566
+ player: undefined
69566
69567
  };
69567
69568
 
69568
69569
  /*
@@ -72625,166 +72626,149 @@ function PwaSW() {
72625
72626
  };
72626
72627
  }
72627
72628
 
72628
- function composeVideoSource(_x, _x2) {
72629
- return _composeVideoSource.apply(this, arguments);
72630
- }
72631
- function _composeVideoSource() {
72632
- _composeVideoSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4($media, media) {
72633
- var videoSrc, vidType, $videoSource;
72634
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
72635
- while (1) switch (_context4.prev = _context4.next) {
72636
- case 0:
72637
- _context4.next = 2;
72638
- return preloadMediaBlob(media.url, media.mediaType);
72639
- case 2:
72640
- videoSrc = _context4.sent;
72641
- vidType = videoFileType(getFileExt(media.uri)); // Only add one source per type
72642
- if ($media.querySelectorAll("source[type=\"".concat(vidType, "\"]")).length === 0) {
72643
- $videoSource = document.createElement('source');
72644
- $videoSource.src = videoSrc;
72645
- $videoSource.type = vidType;
72646
- $media.insertBefore($videoSource, $media.lastElementChild);
72647
- }
72648
- return _context4.abrupt("return", $media);
72649
- case 6:
72650
- case "end":
72651
- return _context4.stop();
72652
- }
72653
- }, _callee4);
72654
- }));
72655
- return _composeVideoSource.apply(this, arguments);
72629
+ function composeVideoSource($media, media) {
72630
+ // const videoSrc = await preloadMediaBlob(media.url as string, media.mediaType as MediaTypes);
72631
+ var vidType = videoFileType(getFileExt(media.uri));
72632
+ // Only add one source per type
72633
+ if ($media.querySelectorAll("source[type=\"".concat(vidType, "\"]")).length === 0) {
72634
+ var $videoSource = document.createElement('source');
72635
+ $videoSource.src = media.url;
72636
+ $videoSource.type = vidType;
72637
+ $media.insertBefore($videoSource, $media.lastElementChild);
72638
+ }
72639
+ return $media;
72656
72640
  }
72657
72641
  function VideoMedia(media, xlr) {
72658
72642
  return {
72659
72643
  init: function init() {
72660
- var $videoMedia = document.getElementById(getMediaId(media));
72661
- if ($videoMedia) {
72662
- var vjsPlayer = videojs.getPlayer($videoMedia);
72663
- if (vjsPlayer !== undefined) {
72664
- var playerReportFault = /*#__PURE__*/function () {
72665
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(msg) {
72666
- var playerSW, hasSW;
72667
- return _regeneratorRuntime().wrap(function _callee$(_context) {
72668
- while (1) switch (_context.prev = _context.next) {
72669
- case 0:
72670
- // Immediately expire media and report a fault
72671
- playerSW = PwaSW();
72672
- _context.next = 3;
72673
- return playerSW.getSW();
72674
- case 3:
72675
- hasSW = _context.sent;
72676
- if (hasSW) {
72677
- playerSW.postMsg({
72678
- type: 'MEDIA_FAULT',
72679
- code: 5002,
72680
- reason: msg,
72681
- mediaId: media.id,
72682
- regionId: media.region.id,
72683
- layoutId: media.region.layout.id,
72684
- date: format(new Date(), 'yyyy-MM-dd HH:mm:ss'),
72685
- // Temporary setting
72686
- expires: format(new Date(setExpiry(1)), 'yyyy-MM-dd HH:mm:ss')
72687
- })["finally"](function () {
72688
- // Expire the media and dispose the video
72689
- vjsPlayer.dispose();
72690
- media.emitter.emit('end', media);
72691
- });
72692
- }
72693
- case 5:
72694
- case "end":
72695
- return _context.stop();
72696
- }
72697
- }, _callee);
72698
- }));
72699
- return function playerReportFault(_x3) {
72700
- return _ref.apply(this, arguments);
72701
- };
72702
- }();
72703
- vjsPlayer.on('loadstart', function () {
72704
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has started loading data . . ."));
72705
- });
72706
- vjsPlayer.on('canplay', function () {
72707
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " can be played . . ."));
72708
- });
72709
- vjsPlayer.ready(function () {
72710
- var promise = vjsPlayer.play();
72711
- if (promise !== undefined) {
72712
- promise.then(function () {
72713
- // Autoplay restarted
72714
- console.debug('autoplay started . . .');
72715
- vjsPlayer.muted(true);
72716
- })["catch"]( /*#__PURE__*/function () {
72717
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(error) {
72718
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
72719
- while (1) switch (_context2.prev = _context2.next) {
72720
- case 0:
72721
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " autoplay error"));
72722
- if (!(xlr.config.platform === 'chromeOS')) {
72723
- _context2.next = 4;
72724
- break;
72725
- }
72644
+ var vjsPlayer = media.player;
72645
+ if (vjsPlayer !== undefined) {
72646
+ var playerReportFault = /*#__PURE__*/function () {
72647
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(msg) {
72648
+ var playerSW, hasSW;
72649
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
72650
+ while (1) switch (_context.prev = _context.next) {
72651
+ case 0:
72652
+ // Immediately expire media and report a fault
72653
+ playerSW = PwaSW();
72654
+ _context.next = 3;
72655
+ return playerSW.getSW();
72656
+ case 3:
72657
+ hasSW = _context.sent;
72658
+ if (hasSW) {
72659
+ playerSW.postMsg({
72660
+ type: 'MEDIA_FAULT',
72661
+ code: 5002,
72662
+ reason: msg,
72663
+ mediaId: media.id,
72664
+ regionId: media.region.id,
72665
+ layoutId: media.region.layout.id,
72666
+ date: format(new Date(), 'yyyy-MM-dd HH:mm:ss'),
72667
+ // Temporary setting
72668
+ expires: format(new Date(setExpiry(1)), 'yyyy-MM-dd HH:mm:ss')
72669
+ })["finally"](function () {
72670
+ // Expire the media and dispose the video
72671
+ vjsPlayer.dispose();
72672
+ media.emitter.emit('end', media);
72673
+ });
72674
+ }
72675
+ case 5:
72676
+ case "end":
72677
+ return _context.stop();
72678
+ }
72679
+ }, _callee);
72680
+ }));
72681
+ return function playerReportFault(_x) {
72682
+ return _ref.apply(this, arguments);
72683
+ };
72684
+ }();
72685
+ vjsPlayer.on('loadstart', function () {
72686
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has started loading data . . ."));
72687
+ });
72688
+ vjsPlayer.on('canplay', function () {
72689
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " can be played . . ."));
72690
+ });
72691
+ vjsPlayer.on('ready', function () {
72692
+ 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')) {
72726
72705
  _context2.next = 4;
72727
- return playerReportFault('Media autoplay error');
72728
- case 4:
72729
- case "end":
72730
- return _context2.stop();
72731
- }
72732
- }, _callee2);
72733
- }));
72734
- return function (_x4) {
72735
- return _ref2.apply(this, arguments);
72736
- };
72737
- }());
72738
- }
72739
- });
72740
- vjsPlayer.on('playing', function () {
72741
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " is now playing . . ."));
72742
- vjsPlayer.muted(media.muted);
72743
- });
72744
- vjsPlayer.on('error', /*#__PURE__*/function () {
72745
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(err) {
72746
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
72747
- while (1) switch (_context3.prev = _context3.next) {
72748
- case 0:
72749
- console.debug("Media Error: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id));
72750
- if (!(xlr.config.platform === 'chromeOS')) {
72751
- _context3.next = 6;
72752
- break;
72753
- }
72754
- _context3.next = 4;
72755
- return playerReportFault('Video file source not supported');
72756
- case 4:
72757
- _context3.next = 7;
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
+ }
72721
+ });
72722
+ vjsPlayer.on('playing', function () {
72723
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " is now playing . . ."));
72724
+ vjsPlayer.muted(media.muted);
72725
+ });
72726
+ 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) {
72730
+ case 0:
72731
+ console.debug("Media Error: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id));
72732
+ if (!(xlr.config.platform === 'chromeOS')) {
72733
+ _context3.next = 6;
72758
72734
  break;
72759
- case 6:
72760
- // End media after 5 seconds
72761
- setTimeout(function () {
72762
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended . . ."));
72763
- media.emitter.emit('end', media);
72764
- vjsPlayer.dispose();
72765
- }, 5000);
72766
- case 7:
72767
- case "end":
72768
- return _context3.stop();
72769
- }
72770
- }, _callee3);
72771
- }));
72772
- return function (_x5) {
72773
- return _ref3.apply(this, arguments);
72774
- };
72775
- }());
72776
- if (media.duration === 0) {
72777
- vjsPlayer.on('durationchange', function () {
72778
- console.debug('Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72779
- });
72780
- vjsPlayer.on('ended', function () {
72781
- var _media$emitter;
72782
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72783
- vjsPlayer.dispose();
72784
- (_media$emitter = media.emitter) === null || _media$emitter === void 0 || _media$emitter.emit('end', media);
72785
- });
72735
+ }
72736
+ _context3.next = 4;
72737
+ return playerReportFault('Video file source not supported');
72738
+ case 4:
72739
+ _context3.next = 7;
72740
+ break;
72741
+ case 6:
72742
+ // End media after 5 seconds
72743
+ setTimeout(function () {
72744
+ console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended . . ."));
72745
+ media.emitter.emit('end', media);
72746
+ vjsPlayer.dispose();
72747
+ }, 5000);
72748
+ case 7:
72749
+ case "end":
72750
+ return _context3.stop();
72751
+ }
72752
+ }, _callee3);
72753
+ }));
72754
+ return function (_x3) {
72755
+ return _ref3.apply(this, arguments);
72756
+ };
72757
+ }());
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);
72786
72769
  }
72787
- }
72770
+ console.debug('VIDEOJS: ondurationchange: Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72771
+ });
72788
72772
  }
72789
72773
  }
72790
72774
  };
@@ -72865,10 +72849,11 @@ function Media(region, mediaId, xml, options, xlr) {
72865
72849
  mediaTimer = setInterval(function () {
72866
72850
  mediaTimeCount++;
72867
72851
  if (mediaTimeCount > media.duration) {
72852
+ console.debug('startMediaTimer: emit>end: on media ' + media.id + ' of Region ' + media.region.regionId);
72868
72853
  media.emitter.emit('end', media);
72869
72854
  }
72870
72855
  }, 1000);
72871
- console.debug('Showing Media ' + media.id + ' for ' + media.duration + 's of Region ' + media.region.regionId);
72856
+ console.debug('startMediaTimer: Showing Media ' + media.id + ' for ' + media.duration + 's of Region ' + media.region.regionId);
72872
72857
  };
72873
72858
  emitter.on('start', function (media) {
72874
72859
  if (media.mediaType === 'video') {
@@ -73023,8 +73008,11 @@ function Media(region, mediaId, xml, options, xlr) {
73023
73008
  $media.style.cssText = $media.style.cssText.concat("background-position: ".concat(align, " ").concat(valign));
73024
73009
  }
73025
73010
  } else if (self.mediaType === 'video') {
73026
- var $videoMedia = $media;
73027
- $videoMedia.textContent = 'Unsupported Video';
73011
+ var $videoMedia = composeVideoSource($media, self);
73012
+ var isMuted = false;
73013
+ if (Boolean(self.options['mute'])) {
73014
+ isMuted = self.options.mute === '1';
73015
+ }
73028
73016
  if (Boolean(self.options['scaletype'])) {
73029
73017
  if (self.options.scaletype === 'stretch') {
73030
73018
  $videoMedia.style.objectFit = 'fill';
@@ -73032,8 +73020,10 @@ function Media(region, mediaId, xml, options, xlr) {
73032
73020
  }
73033
73021
  $videoMedia.classList.add('video-js', 'vjs-default-skin');
73034
73022
  if (self.loop) {
73023
+ self.loop = true;
73035
73024
  $videoMedia.loop = true;
73036
73025
  }
73026
+ self.muted = isMuted;
73037
73027
  $media = $videoMedia;
73038
73028
  } else if (self.mediaType === 'audio') {
73039
73029
  var $audioMedia = $media;
@@ -73136,7 +73126,7 @@ function Media(region, mediaId, xml, options, xlr) {
73136
73126
  }
73137
73127
  var showCurrentMedia = /*#__PURE__*/function () {
73138
73128
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
73139
- var $mediaId, $media, isCMS, isMuted;
73129
+ var $mediaId, $media, isCMS;
73140
73130
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
73141
73131
  while (1) switch (_context2.prev = _context2.next) {
73142
73132
  case 0:
@@ -73147,7 +73137,7 @@ function Media(region, mediaId, xml, options, xlr) {
73147
73137
  $media = getNewMedia();
73148
73138
  }
73149
73139
  if (!$media) {
73150
- _context2.next = 45;
73140
+ _context2.next = 40;
73151
73141
  break;
73152
73142
  }
73153
73143
  $media.style.setProperty('display', 'block');
@@ -73176,54 +73166,48 @@ function Media(region, mediaId, xml, options, xlr) {
73176
73166
  _context2.t3 = _context2.t2;
73177
73167
  _context2.t4 = _context2.t1.concat.call(_context2.t1, _context2.t3);
73178
73168
  _context2.t0.setProperty.call(_context2.t0, 'background-image', _context2.t4);
73179
- _context2.next = 44;
73169
+ _context2.next = 39;
73180
73170
  break;
73181
73171
  case 22:
73182
73172
  if (!(self.mediaType === 'video' && self.url !== null)) {
73183
- _context2.next = 32;
73173
+ _context2.next = 27;
73184
73174
  break;
73185
73175
  }
73186
- _context2.next = 25;
73187
- return composeVideoSource($media, self);
73188
- case 25:
73189
- $media = _context2.sent;
73190
- isMuted = false;
73191
- if (Boolean(self.options['mute'])) {
73192
- isMuted = self.options.mute === '1';
73193
- }
73194
- self.muted = isMuted;
73176
+ // Initialize video.js
73195
73177
  videojs($media, {
73196
73178
  controls: false,
73197
73179
  preload: 'auto',
73198
73180
  autoplay: false,
73199
- muted: isMuted,
73181
+ muted: self.muted,
73200
73182
  errorDisplay: xlr.config.platform !== 'chromeOS',
73201
- restoreEl: $media
73183
+ restoreEl: $media,
73184
+ loop: self.loop
73202
73185
  });
73203
- _context2.next = 44;
73186
+ self.player = videojs($media);
73187
+ _context2.next = 39;
73204
73188
  break;
73205
- case 32:
73189
+ case 27:
73206
73190
  if (!(self.mediaType === 'audio' && self.url !== null)) {
73207
- _context2.next = 43;
73191
+ _context2.next = 38;
73208
73192
  break;
73209
73193
  }
73210
73194
  if (!isCMS) {
73211
- _context2.next = 39;
73195
+ _context2.next = 34;
73212
73196
  break;
73213
73197
  }
73214
- _context2.next = 36;
73198
+ _context2.next = 31;
73215
73199
  return preloadMediaBlob(self.url, self.mediaType);
73216
- case 36:
73200
+ case 31:
73217
73201
  _context2.t5 = _context2.sent;
73218
- _context2.next = 40;
73202
+ _context2.next = 35;
73219
73203
  break;
73220
- case 39:
73204
+ case 34:
73221
73205
  _context2.t5 = self.url;
73222
- case 40:
73206
+ case 35:
73223
73207
  $media.src = _context2.t5;
73224
- _context2.next = 44;
73208
+ _context2.next = 39;
73225
73209
  break;
73226
- case 43:
73210
+ case 38:
73227
73211
  if ((self.render === 'html' || self.mediaType === 'webpage') && self.iframe && self.checkIframeStatus) {
73228
73212
  // Set state as false ( for now )
73229
73213
  self.ready = false;
@@ -73239,9 +73223,9 @@ function Media(region, mediaId, xml, options, xlr) {
73239
73223
  // }
73240
73224
  // });
73241
73225
  }
73242
- case 44:
73226
+ case 39:
73243
73227
  self.emitter.emit('start', self);
73244
- case 45:
73228
+ case 40:
73245
73229
  case "end":
73246
73230
  return _context2.stop();
73247
73231
  }
@@ -73366,7 +73350,7 @@ function Region(layout, xml, regionId, options, xlr) {
73366
73350
  console.debug('Region::finished called . . . ', self.id);
73367
73351
  // Mark as complete
73368
73352
  self.complete = true;
73369
- self.layout.regions[regionObject.index] = regionObject;
73353
+ self.layout.regions[regionObject.index] = self;
73370
73354
  self.layout.regionExpired();
73371
73355
  };
73372
73356
  regionObject.prepareMediaObjects = function () {
@@ -73488,7 +73472,7 @@ function Region(layout, xml, regionId, options, xlr) {
73488
73472
  }
73489
73473
  };
73490
73474
  regionObject.playNextMedia = function () {
73491
- var _self$curMedia, _self$curMedia2, _self$curMedia3, _self$curMedia4;
73475
+ var _self$curMedia, _self$curMedia2, _self$curMedia3, _self$curMedia4, _self$curMedia5;
73492
73476
  var self = regionObject;
73493
73477
  /* The current media has finished running */
73494
73478
  if (self.ended) {
@@ -73508,7 +73492,7 @@ function Region(layout, xml, regionId, options, xlr) {
73508
73492
  // When the region has completed and mediaObjects.length = 1
73509
73493
  // and curMedia.loop = false, then put the media on
73510
73494
  // its current state
73511
- 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)) {
73495
+ 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)) {
73512
73496
  return;
73513
73497
  }
73514
73498
  self.currentMediaIndex = self.currentMediaIndex + 1;