@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,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
- init(): void;
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';
@@ -42,5 +43,7 @@ export interface IMedia {
42
43
  fileId: string;
43
44
  emitter: Emitter<IMediaEvents>;
44
45
  enableStat: boolean;
46
+ muted?: boolean;
47
+ player?: Player;
45
48
  }
46
49
  export declare const initialMedia: IMedia;
@@ -69561,7 +69561,9 @@ var initialMedia = {
69561
69561
  return {};
69562
69562
  },
69563
69563
  emitter: {},
69564
- enableStat: false
69564
+ enableStat: false,
69565
+ muted: false,
69566
+ player: undefined
69565
69567
  };
69566
69568
 
69567
69569
  /*
@@ -72624,123 +72626,149 @@ function PwaSW() {
72624
72626
  };
72625
72627
  }
72626
72628
 
72627
- function composeVideoSource(_x, _x2) {
72628
- return _composeVideoSource.apply(this, arguments);
72629
- }
72630
- function _composeVideoSource() {
72631
- _composeVideoSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2($media, media) {
72632
- var videoSrc, vidType, $videoSource;
72633
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
72634
- while (1) switch (_context2.prev = _context2.next) {
72635
- case 0:
72636
- _context2.next = 2;
72637
- return preloadMediaBlob(media.url, media.mediaType);
72638
- case 2:
72639
- videoSrc = _context2.sent;
72640
- vidType = videoFileType(getFileExt(media.uri)); // Only add one source per type
72641
- if ($media.querySelectorAll("source[type=\"".concat(vidType, "\"]")).length === 0) {
72642
- $videoSource = document.createElement('source');
72643
- $videoSource.src = videoSrc;
72644
- $videoSource.type = vidType;
72645
- $media.insertBefore($videoSource, $media.lastElementChild);
72646
- }
72647
- return _context2.abrupt("return", $media);
72648
- case 6:
72649
- case "end":
72650
- return _context2.stop();
72651
- }
72652
- }, _callee2);
72653
- }));
72654
- 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;
72655
72640
  }
72656
72641
  function VideoMedia(media, xlr) {
72657
72642
  return {
72658
72643
  init: function init() {
72659
- var $videoMedia = document.getElementById(getMediaId(media));
72660
- if ($videoMedia) {
72661
- var vjsPlayer = videojs.getPlayer($videoMedia);
72662
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('loadstart', function () {
72663
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has started loading data . . ."));
72664
- });
72665
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('loadstart', function () {
72666
- if ($videoMedia.readyState >= 2) {
72667
- console.debug("".concat(capitalizeStr(media.mediaType), " data for media > ").concat(media.id, " has been fully loaded . . ."));
72668
- }
72669
- });
72670
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('canplay', function () {
72671
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " can be played . . ."));
72672
- // Autoplay restarted
72673
- console.debug('autoplay started . . .');
72674
- vjsPlayer.muted(true);
72675
- vjsPlayer.play();
72676
- });
72677
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('playing', function () {
72678
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " is now playing . . ."));
72679
- });
72680
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('error', /*#__PURE__*/function () {
72681
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(err) {
72644
+ var vjsPlayer = media.player;
72645
+ if (vjsPlayer !== undefined) {
72646
+ var playerReportFault = /*#__PURE__*/function () {
72647
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(msg) {
72682
72648
  var playerSW, hasSW;
72683
72649
  return _regeneratorRuntime().wrap(function _callee$(_context) {
72684
72650
  while (1) switch (_context.prev = _context.next) {
72685
72651
  case 0:
72686
- console.debug("Media Error: ".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id));
72687
- if (!(xlr.config.platform === 'chromeOS')) {
72688
- _context.next = 9;
72689
- break;
72690
- }
72691
72652
  // Immediately expire media and report a fault
72692
72653
  playerSW = PwaSW();
72693
- _context.next = 5;
72654
+ _context.next = 3;
72694
72655
  return playerSW.getSW();
72695
- case 5:
72656
+ case 3:
72696
72657
  hasSW = _context.sent;
72697
72658
  if (hasSW) {
72698
72659
  playerSW.postMsg({
72699
72660
  type: 'MEDIA_FAULT',
72700
72661
  code: 5002,
72701
- reason: 'Video file source not supported',
72662
+ reason: msg,
72702
72663
  mediaId: media.id,
72703
72664
  regionId: media.region.id,
72704
72665
  layoutId: media.region.layout.id,
72705
72666
  date: format(new Date(), 'yyyy-MM-dd HH:mm:ss'),
72706
72667
  // Temporary setting
72707
- expires: format(new Date(setExpiry(7)), 'yyyy-MM-dd HH:mm:ss')
72668
+ expires: format(new Date(setExpiry(1)), 'yyyy-MM-dd HH:mm:ss')
72708
72669
  })["finally"](function () {
72709
72670
  // Expire the media and dispose the video
72710
72671
  vjsPlayer.dispose();
72711
72672
  media.emitter.emit('end', media);
72712
72673
  });
72713
72674
  }
72714
- _context.next = 10;
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')) {
72705
+ _context2.next = 4;
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;
72734
+ break;
72735
+ }
72736
+ _context3.next = 4;
72737
+ return playerReportFault('Video file source not supported');
72738
+ case 4:
72739
+ _context3.next = 7;
72715
72740
  break;
72716
- case 9:
72741
+ case 6:
72717
72742
  // End media after 5 seconds
72718
72743
  setTimeout(function () {
72719
72744
  console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended . . ."));
72720
72745
  media.emitter.emit('end', media);
72721
72746
  vjsPlayer.dispose();
72722
72747
  }, 5000);
72723
- case 10:
72748
+ case 7:
72724
72749
  case "end":
72725
- return _context.stop();
72750
+ return _context3.stop();
72726
72751
  }
72727
- }, _callee);
72752
+ }, _callee3);
72728
72753
  }));
72729
72754
  return function (_x3) {
72730
- return _ref.apply(this, arguments);
72755
+ return _ref3.apply(this, arguments);
72731
72756
  };
72732
72757
  }());
72733
- if (media.duration === 0) {
72734
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('durationchange', function () {
72735
- console.debug('Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72736
- });
72737
- vjsPlayer === null || vjsPlayer === void 0 || vjsPlayer.on('ended', function () {
72738
- var _media$emitter;
72739
- console.debug("".concat(capitalizeStr(media.mediaType), " for media > ").concat(media.id, " has ended playing . . ."));
72740
- (_media$emitter = media.emitter) === null || _media$emitter === void 0 || _media$emitter.emit('end', media);
72741
- vjsPlayer.dispose();
72742
- });
72743
- }
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);
72769
+ }
72770
+ console.debug('VIDEOJS: ondurationchange: Showing Media ' + media.id + ' for ' + vjsPlayer.duration() + 's of Region ' + media.region.regionId);
72771
+ });
72744
72772
  }
72745
72773
  }
72746
72774
  };
@@ -72821,10 +72849,11 @@ function Media(region, mediaId, xml, options, xlr) {
72821
72849
  mediaTimer = setInterval(function () {
72822
72850
  mediaTimeCount++;
72823
72851
  if (mediaTimeCount > media.duration) {
72852
+ console.debug('startMediaTimer: emit>end: on media ' + media.id + ' of Region ' + media.region.regionId);
72824
72853
  media.emitter.emit('end', media);
72825
72854
  }
72826
72855
  }, 1000);
72827
- 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);
72828
72857
  };
72829
72858
  emitter.on('start', function (media) {
72830
72859
  if (media.mediaType === 'video') {
@@ -72952,7 +72981,7 @@ function Media(region, mediaId, xml, options, xlr) {
72952
72981
  tmpUrl = composeResourceUrlByPlatform(xlr.config, resourceUrlParams);
72953
72982
  } else if (xlr.config.platform === 'chromeOS') {
72954
72983
  tmpUrl = composeResourceUrl(xlr.config, resourceUrlParams);
72955
- if (self.mediaType === 'image' || self.mediaType === 'video') {
72984
+ if (self.mediaType === 'image' || self.mediaType === 'video' || self.mediaType === 'audio') {
72956
72985
  tmpUrl = composeMediaUrl(resourceUrlParams);
72957
72986
  }
72958
72987
  }
@@ -72979,8 +73008,11 @@ function Media(region, mediaId, xml, options, xlr) {
72979
73008
  $media.style.cssText = $media.style.cssText.concat("background-position: ".concat(align, " ").concat(valign));
72980
73009
  }
72981
73010
  } else if (self.mediaType === 'video') {
72982
- var $videoMedia = $media;
72983
- $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
+ }
72984
73016
  if (Boolean(self.options['scaletype'])) {
72985
73017
  if (self.options.scaletype === 'stretch') {
72986
73018
  $videoMedia.style.objectFit = 'fill';
@@ -72988,8 +73020,10 @@ function Media(region, mediaId, xml, options, xlr) {
72988
73020
  }
72989
73021
  $videoMedia.classList.add('video-js', 'vjs-default-skin');
72990
73022
  if (self.loop) {
73023
+ self.loop = true;
72991
73024
  $videoMedia.loop = true;
72992
73025
  }
73026
+ self.muted = isMuted;
72993
73027
  $media = $videoMedia;
72994
73028
  } else if (self.mediaType === 'audio') {
72995
73029
  var $audioMedia = $media;
@@ -73092,7 +73126,7 @@ function Media(region, mediaId, xml, options, xlr) {
73092
73126
  }
73093
73127
  var showCurrentMedia = /*#__PURE__*/function () {
73094
73128
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
73095
- var $mediaId, $media, isCMS, isMuted;
73129
+ var $mediaId, $media, isCMS;
73096
73130
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
73097
73131
  while (1) switch (_context2.prev = _context2.next) {
73098
73132
  case 0:
@@ -73103,7 +73137,7 @@ function Media(region, mediaId, xml, options, xlr) {
73103
73137
  $media = getNewMedia();
73104
73138
  }
73105
73139
  if (!$media) {
73106
- _context2.next = 44;
73140
+ _context2.next = 40;
73107
73141
  break;
73108
73142
  }
73109
73143
  $media.style.setProperty('display', 'block');
@@ -73132,52 +73166,48 @@ function Media(region, mediaId, xml, options, xlr) {
73132
73166
  _context2.t3 = _context2.t2;
73133
73167
  _context2.t4 = _context2.t1.concat.call(_context2.t1, _context2.t3);
73134
73168
  _context2.t0.setProperty.call(_context2.t0, 'background-image', _context2.t4);
73135
- _context2.next = 43;
73169
+ _context2.next = 39;
73136
73170
  break;
73137
73171
  case 22:
73138
73172
  if (!(self.mediaType === 'video' && self.url !== null)) {
73139
- _context2.next = 31;
73173
+ _context2.next = 27;
73140
73174
  break;
73141
73175
  }
73142
- _context2.next = 25;
73143
- return composeVideoSource($media, self);
73144
- case 25:
73145
- $media = _context2.sent;
73146
- isMuted = false;
73147
- if (Boolean(self.options['mute'])) {
73148
- isMuted = self.options.mute === '1';
73149
- }
73176
+ // Initialize video.js
73150
73177
  videojs($media, {
73151
73178
  controls: false,
73152
73179
  preload: 'auto',
73153
73180
  autoplay: false,
73154
- muted: isMuted,
73155
- errorDisplay: xlr.config.platform !== 'chromeOS'
73181
+ muted: self.muted,
73182
+ errorDisplay: xlr.config.platform !== 'chromeOS',
73183
+ restoreEl: $media,
73184
+ loop: self.loop
73156
73185
  });
73157
- _context2.next = 43;
73186
+ self.player = videojs($media);
73187
+ _context2.next = 39;
73158
73188
  break;
73159
- case 31:
73189
+ case 27:
73160
73190
  if (!(self.mediaType === 'audio' && self.url !== null)) {
73161
- _context2.next = 42;
73191
+ _context2.next = 38;
73162
73192
  break;
73163
73193
  }
73164
73194
  if (!isCMS) {
73165
- _context2.next = 38;
73195
+ _context2.next = 34;
73166
73196
  break;
73167
73197
  }
73168
- _context2.next = 35;
73198
+ _context2.next = 31;
73169
73199
  return preloadMediaBlob(self.url, self.mediaType);
73170
- case 35:
73200
+ case 31:
73171
73201
  _context2.t5 = _context2.sent;
73172
- _context2.next = 39;
73202
+ _context2.next = 35;
73173
73203
  break;
73174
- case 38:
73204
+ case 34:
73175
73205
  _context2.t5 = self.url;
73176
- case 39:
73206
+ case 35:
73177
73207
  $media.src = _context2.t5;
73178
- _context2.next = 43;
73208
+ _context2.next = 39;
73179
73209
  break;
73180
- case 42:
73210
+ case 38:
73181
73211
  if ((self.render === 'html' || self.mediaType === 'webpage') && self.iframe && self.checkIframeStatus) {
73182
73212
  // Set state as false ( for now )
73183
73213
  self.ready = false;
@@ -73193,9 +73223,9 @@ function Media(region, mediaId, xml, options, xlr) {
73193
73223
  // }
73194
73224
  // });
73195
73225
  }
73196
- case 43:
73226
+ case 39:
73197
73227
  self.emitter.emit('start', self);
73198
- case 44:
73228
+ case 40:
73199
73229
  case "end":
73200
73230
  return _context2.stop();
73201
73231
  }
@@ -73320,7 +73350,7 @@ function Region(layout, xml, regionId, options, xlr) {
73320
73350
  console.debug('Region::finished called . . . ', self.id);
73321
73351
  // Mark as complete
73322
73352
  self.complete = true;
73323
- self.layout.regions[regionObject.index] = regionObject;
73353
+ self.layout.regions[regionObject.index] = self;
73324
73354
  self.layout.regionExpired();
73325
73355
  };
73326
73356
  regionObject.prepareMediaObjects = function () {
@@ -73442,7 +73472,7 @@ function Region(layout, xml, regionId, options, xlr) {
73442
73472
  }
73443
73473
  };
73444
73474
  regionObject.playNextMedia = function () {
73445
- var _self$curMedia, _self$curMedia2, _self$curMedia3, _self$curMedia4;
73475
+ var _self$curMedia, _self$curMedia2, _self$curMedia3, _self$curMedia4, _self$curMedia5;
73446
73476
  var self = regionObject;
73447
73477
  /* The current media has finished running */
73448
73478
  if (self.ended) {
@@ -73462,7 +73492,7 @@ function Region(layout, xml, regionId, options, xlr) {
73462
73492
  // When the region has completed and mediaObjects.length = 1
73463
73493
  // and curMedia.loop = false, then put the media on
73464
73494
  // its current state
73465
- 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)) {
73466
73496
  return;
73467
73497
  }
73468
73498
  self.currentMediaIndex = self.currentMediaIndex + 1;