eligius 1.0.5 → 1.0.6

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 { TDiagnosticType } from './types';
2
2
  export declare class Diagnostics {
3
3
  static send(_name: TDiagnosticType, _data: any): void;
4
+ static active: boolean;
4
5
  }
@@ -4,5 +4,5 @@ export interface IDiagnosticsAgent {
4
4
  export interface IDiagnosticsInfo {
5
5
  get agent(): IDiagnosticsAgent;
6
6
  }
7
- export declare type TDiagnosticType = 'eligius-diagnostics-event' | 'eligius-diagnostics-action';
7
+ export declare type TDiagnosticType = 'eligius-diagnostics-factory' | 'eligius-diagnostics-engine' | 'eligius-diagnostics-event' | 'eligius-diagnostics-action' | 'eligius-diagnostics-action-error' | 'eligius-diagnostics-operation';
8
8
  export declare const DEV_TOOLS_KEY = "__ELIGIUS_DEV_TOOLS__";
@@ -7,7 +7,7 @@ var fs = require('fs');
7
7
  var path = require('path');
8
8
  var lottie = require('lottie-web');
9
9
  var $ = require('jquery');
10
- var Mousetrap = require('mousetrap');
10
+ var hotkeys = require('hotkeys-js');
11
11
  var uuid = require('uuid');
12
12
 
13
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -16,15 +16,62 @@ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
16
16
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
17
17
  var lottie__default = /*#__PURE__*/_interopDefaultLegacy(lottie);
18
18
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
19
- var Mousetrap__default = /*#__PURE__*/_interopDefaultLegacy(Mousetrap);
19
+ var hotkeys__default = /*#__PURE__*/_interopDefaultLegacy(hotkeys);
20
+
21
+ function prepareValueForSerialization(value) {
22
+ if (Array.isArray(value)) {
23
+ return value.map(prepareValueForSerialization);
24
+ } else if (typeof value === 'object') {
25
+ return Object.fromEntries(Object.entries(value).map(function (_ref) {
26
+ var name = _ref[0],
27
+ value = _ref[1];
28
+ return [name, prepareValueForSerialization(value)];
29
+ }));
30
+ } else if (typeof value === 'function') {
31
+ return value.toString();
32
+ }
33
+
34
+ return value;
35
+ }
36
+
37
+ var DevToolEventListener = /*#__PURE__*/function () {
38
+ function DevToolEventListener(agent) {
39
+ this.agent = void 0;
40
+ this.agent = agent;
41
+ }
42
+
43
+ var _proto = DevToolEventListener.prototype;
44
+
45
+ _proto.handleEvent = function handleEvent(eventName, eventTopic, args) {
46
+ this.agent.postMessage('eligius-diagnostics-event', {
47
+ eventName: eventName,
48
+ eventTopic: eventTopic,
49
+ args: prepareValueForSerialization(args)
50
+ });
51
+ };
52
+
53
+ return DevToolEventListener;
54
+ }();
55
+
56
+ var Diagnostics = /*#__PURE__*/function () {
57
+ function Diagnostics() {}
58
+
59
+ Diagnostics.send = function send(_name, _data) {
60
+ console.log(_name, _data);
61
+ };
62
+
63
+ return Diagnostics;
64
+ }();
65
+ Diagnostics.active = void 0;
66
+
67
+ var DEV_TOOLS_KEY = '__ELIGIUS_DEV_TOOLS__';
20
68
 
69
+ var copyFunction = typeof structuredClone !== 'undefined' ? structuredClone : function (original) {
70
+ return JSON.parse(JSON.stringify(original));
71
+ };
21
72
  function deepCopy(original) {
22
73
  if (tsIsPresent.isDefined(original)) {
23
- if (typeof structuredClone !== 'undefined') {
24
- return structuredClone(original);
25
- }
26
-
27
- return JSON.parse(JSON.stringify(original));
74
+ return copyFunction(original);
28
75
  }
29
76
 
30
77
  return original;
@@ -48,8 +95,10 @@ var Action = /*#__PURE__*/function () {
48
95
  var _proto = Action.prototype;
49
96
 
50
97
  _proto.start = function start(initOperationData) {
51
- var _this = this;
98
+ var _this$name,
99
+ _this = this;
52
100
 
101
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action', ((_this$name = this.name) != null ? _this$name : 'Action') + " begins executing start operations");
53
102
  var context = {
54
103
  currentIndex: -1,
55
104
  eventbus: this.eventbus
@@ -57,11 +106,20 @@ var Action = /*#__PURE__*/function () {
57
106
  var result = new Promise(function (resolve, reject) {
58
107
  _this.executeOperation(_this.startOperations, 0, resolve, reject, initOperationData, context);
59
108
  })["catch"](function (e) {
109
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action-error', {
110
+ name: name,
111
+ error: e
112
+ });
60
113
  console.error("Error in action start '" + _this.name + "'");
61
114
  console.error(e);
62
115
  throw e;
63
116
  });
64
- return result;
117
+ return !Diagnostics.active ? result : result.then(function (operationsResult) {
118
+ var _this$name2;
119
+
120
+ Diagnostics.send('eligius-diagnostics-action', ((_this$name2 = _this.name) != null ? _this$name2 : 'Action') + " finished executing start operations");
121
+ return operationsResult;
122
+ });
65
123
  };
66
124
 
67
125
  _proto.executeOperation = function executeOperation(operations, idx, resolve, reject, previousOperationData, context) {
@@ -90,6 +148,11 @@ var Action = /*#__PURE__*/function () {
90
148
  var operationInfo = operations[idx];
91
149
  var copy = operationInfo.operationData ? deepCopy(operationInfo.operationData) : {};
92
150
  var mergedOperationData = Object.assign(previousOperationData, copy);
151
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-operation', {
152
+ systemName: operationInfo.systemName,
153
+ operationData: operationInfo.operationData,
154
+ context: context
155
+ });
93
156
  var operationResult = operationInfo.instance.call(context, mergedOperationData);
94
157
 
95
158
  if (isPromise(operationResult)) {
@@ -537,24 +600,30 @@ var EndableAction = /*#__PURE__*/function (_Action) {
537
600
  var _proto = EndableAction.prototype;
538
601
 
539
602
  _proto.end = function end(initOperationData) {
540
- var _this2 = this;
603
+ var _this$name,
604
+ _this2 = this;
541
605
 
542
- if (this.endOperations.length) {
543
- var context = {
544
- currentIndex: -1,
545
- eventbus: this.eventbus
546
- };
547
- var result = new Promise(function (resolve, reject) {
548
- _this2.executeOperation(_this2.endOperations, 0, resolve, reject, initOperationData, context);
549
- })["catch"](function (e) {
550
- console.error("Error in action end '" + _this2.name + "'");
551
- throw e;
552
- });
553
- return result;
606
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action', ((_this$name = this.name) != null ? _this$name : 'Action') + " begins executing end operations");
607
+
608
+ if (!this.endOperations.length) {
609
+ return Promise.resolve(initOperationData);
554
610
  }
555
611
 
556
- return new Promise(function (resolve) {
557
- resolve(initOperationData);
612
+ var context = {
613
+ currentIndex: -1,
614
+ eventbus: this.eventbus
615
+ };
616
+ var result = new Promise(function (resolve, reject) {
617
+ _this2.executeOperation(_this2.endOperations, 0, resolve, reject, initOperationData, context);
618
+ })["catch"](function (e) {
619
+ console.error("Error in action end '" + _this2.name + "'");
620
+ throw e;
621
+ });
622
+ return !Diagnostics.active ? result : result.then(function (operationsResult) {
623
+ var _this2$name;
624
+
625
+ Diagnostics.send('eligius-diagnostics-action', ((_this2$name = _this2.name) != null ? _this2$name : 'Action') + " finished executing start operations");
626
+ return operationsResult;
558
627
  });
559
628
  };
560
629
 
@@ -1006,6 +1075,7 @@ TimelineEventNames.DURATION = 'timeline-duration';
1006
1075
  TimelineEventNames.TIME = 'timeline-time';
1007
1076
  TimelineEventNames.SEEKED = 'timeline-seeked';
1008
1077
  TimelineEventNames.COMPLETE = 'timeline-complete';
1078
+ TimelineEventNames.RESTART = 'timeline-restart';
1009
1079
  TimelineEventNames.PLAY = 'timeline-play';
1010
1080
  TimelineEventNames.STOP = 'timeline-stop';
1011
1081
  TimelineEventNames.PAUSE = 'timeline-pause';
@@ -1964,34 +2034,6 @@ var ctrls = {
1964
2034
  SubtitlesController: SubtitlesController
1965
2035
  };
1966
2036
 
1967
- var DevToolEventListener = /*#__PURE__*/function () {
1968
- function DevToolEventListener(agent) {
1969
- this.agent = void 0;
1970
- this.agent = agent;
1971
- }
1972
-
1973
- var _proto = DevToolEventListener.prototype;
1974
-
1975
- _proto.handleEvent = function handleEvent(eventName, eventTopic, args) {
1976
- this.agent.postMessage('eligius-diagnostics-event', {
1977
- eventName: eventName,
1978
- eventTopic: eventTopic
1979
- });
1980
- };
1981
-
1982
- return DevToolEventListener;
1983
- }();
1984
-
1985
- var Diagnostics = /*#__PURE__*/function () {
1986
- function Diagnostics() {}
1987
-
1988
- Diagnostics.send = function send(_name, _data) {};
1989
-
1990
- return Diagnostics;
1991
- }();
1992
-
1993
- var DEV_TOOLS_KEY = '__ELIGIUS_DEV_TOOLS__';
1994
-
1995
2037
  /**
1996
2038
  * EligiusEngine, this is where the magic happens. The engine is responsible for starting and stopping
1997
2039
  * the given timeline provider and triggering the actions associated with it.
@@ -2841,24 +2883,38 @@ var LanguageManager = /*#__PURE__*/function () {
2841
2883
  }();
2842
2884
 
2843
2885
  var EngineFactory = /*#__PURE__*/function () {
2844
- function EngineFactory(importer, windowRef, eventbus) {
2886
+ function EngineFactory(importer, windowRef, options) {
2887
+ var _options$devtools;
2888
+
2845
2889
  this.resizeTimeout = -1;
2846
2890
  this.actionsLookup = {};
2847
2891
  this.importer = void 0;
2848
2892
  this.eventbus = void 0;
2893
+ this._handleSpaceBound = void 0;
2849
2894
  this.importer = importer;
2850
- this.eventbus = eventbus || new Eventbus();
2895
+ this.eventbus = (options == null ? void 0 : options.eventbus) || new Eventbus();
2896
+ Diagnostics.active = (_options$devtools = options == null ? void 0 : options.devtools) != null ? _options$devtools : false;
2851
2897
 
2852
- this._initializeDevtools(this.eventbus);
2898
+ if (Diagnostics.active) {
2899
+ this._initializeDevtools(this.eventbus);
2900
+ }
2853
2901
 
2854
2902
  this.eventbus.on(TimelineEventNames.REQUEST_INSTANCE, this._requestInstanceHandler.bind(this));
2855
2903
  this.eventbus.on(TimelineEventNames.REQUEST_ACTION, this._requestActionHandler.bind(this));
2856
2904
  this.eventbus.on(TimelineEventNames.REQUEST_FUNCTION, this._requestFunctionHandler.bind(this));
2905
+ this._handleSpaceBound = this._handleSpacePress.bind(this);
2906
+ hotkeys__default["default"]('space', this._handleSpaceBound);
2857
2907
  $__default["default"](windowRef).resize(this._resizeHandler.bind(this));
2858
2908
  }
2859
2909
 
2860
2910
  var _proto = EngineFactory.prototype;
2861
2911
 
2912
+ _proto._handleSpacePress = function _handleSpacePress(keyboardEvent, _hotkeysEvent) {
2913
+ keyboardEvent.preventDefault();
2914
+ this.eventbus.broadcast(TimelineEventNames.PLAY_TOGGLE_REQUEST);
2915
+ return false;
2916
+ };
2917
+
2862
2918
  _proto._initializeDevtools = function _initializeDevtools(eventbus) {
2863
2919
  var diagnosticInfo = window[DEV_TOOLS_KEY];
2864
2920
 
@@ -2870,11 +2926,16 @@ var EngineFactory = /*#__PURE__*/function () {
2870
2926
  Diagnostics.send = function (name, data) {
2871
2927
  agent.postMessage(name, data);
2872
2928
  };
2929
+
2930
+ Diagnostics.send('eligius-diagnostics-factory', 'Diagnostics initialized');
2931
+ } else {
2932
+ console.warn(DEV_TOOLS_KEY + " property not found on window, please install the extension.");
2873
2933
  }
2874
2934
  };
2875
2935
 
2876
2936
  _proto.destroy = function destroy() {
2877
2937
  this.eventbus.clear();
2938
+ hotkeys__default["default"].unbind('space', this._handleSpaceBound);
2878
2939
  };
2879
2940
 
2880
2941
  _proto._resizeHandler = function _resizeHandler() {
@@ -2919,8 +2980,7 @@ var EngineFactory = /*#__PURE__*/function () {
2919
2980
  };
2920
2981
 
2921
2982
  _proto.createEngine = function createEngine(configuration, resolver) {
2922
- var _configuration$eventA,
2923
- _this2 = this;
2983
+ var _configuration$eventA;
2924
2984
 
2925
2985
  var systemName = configuration.engine.systemName;
2926
2986
 
@@ -2948,18 +3008,11 @@ var EngineFactory = /*#__PURE__*/function () {
2948
3008
  labels = configuration.labels;
2949
3009
  var languageManager = new LanguageManager(language, labels, this.eventbus);
2950
3010
  var engineInstance = new EngineClass(resolvedConfiguration, this.eventbus, timelineProviders, languageManager);
2951
- Mousetrap__default["default"].bind('space', function (event) {
2952
- event.preventDefault();
2953
-
2954
- _this2.eventbus.broadcast(TimelineEventNames.PLAY_TOGGLE_REQUEST);
2955
-
2956
- return false;
2957
- });
2958
3011
  return engineInstance;
2959
3012
  };
2960
3013
 
2961
3014
  _proto._createTimelineProviders = function _createTimelineProviders(configuration, eventbus) {
2962
- var _this3 = this;
3015
+ var _this2 = this;
2963
3016
 
2964
3017
  var timelineProviderSettings = configuration.timelineProviderSettings;
2965
3018
  var result = Object.entries(timelineProviderSettings).reduce(function (acc, _ref) {
@@ -2970,7 +3023,7 @@ var EngineFactory = /*#__PURE__*/function () {
2970
3023
  return acc;
2971
3024
  }
2972
3025
 
2973
- var timelineProviderClass = _this3._importSystemEntry(settings.systemName);
3026
+ var timelineProviderClass = _this2._importSystemEntry(settings.systemName);
2974
3027
 
2975
3028
  acc[timelineType] = {
2976
3029
  id: settings.id,
@@ -4467,20 +4520,46 @@ var JwPlayerTimelineProvider = /*#__PURE__*/function () {
4467
4520
  return JwPlayerTimelineProvider;
4468
4521
  }();
4469
4522
 
4523
+ // https://gist.github.com/jakearchibald/cb03f15670817001b1157e62a076fe95
4524
+ function animationInterval(ms, signal, callback) {
4525
+ var _document$timeline$cu, _document, _document$timeline;
4526
+
4527
+ // Prefer currentTime, as it'll better sync animations queued in the
4528
+ // same frame, but if it isn't supported, performance.now() is fine.
4529
+ var start = (_document$timeline$cu = (_document = document) == null ? void 0 : (_document$timeline = _document.timeline) == null ? void 0 : _document$timeline.currentTime) != null ? _document$timeline$cu : performance.now();
4530
+
4531
+ function frame(time) {
4532
+ if (signal.aborted) return;
4533
+ callback(time);
4534
+ scheduleFrame(time);
4535
+ }
4536
+
4537
+ function scheduleFrame(time) {
4538
+ var elapsed = time - start;
4539
+ var roundedElapsed = Math.round(elapsed / ms) * ms;
4540
+ var targetNext = start + roundedElapsed + ms;
4541
+ var delay = targetNext - performance.now();
4542
+ setTimeout(function () {
4543
+ return requestAnimationFrame(frame);
4544
+ }, delay);
4545
+ }
4546
+
4547
+ scheduleFrame(start);
4548
+ }
4549
+
4470
4550
  var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4471
4551
  function RequestAnimationFrameTimelineProvider(eventbus, config) {
4472
4552
  this.eventbus = void 0;
4473
4553
  this.config = void 0;
4474
- this._requestID = -1;
4475
- this._last = 0;
4476
4554
  this._currentPosition = 0;
4477
4555
  this._updateBound = this._update.bind(this);
4478
4556
  this._eventbusListeners = [];
4479
4557
  this._firstFrame = true;
4480
4558
  this._currentPlaylistItem = void 0;
4481
- this._granularity = 1000;
4559
+ this._tickInterval = 1000;
4482
4560
  this._playlist = void 0;
4483
4561
  this._containerElement = void 0;
4562
+ this._abortController = void 0;
4484
4563
  this.playState = 'stopped';
4485
4564
  this.loop = false;
4486
4565
  this.eventbus = eventbus;
@@ -4535,55 +4614,53 @@ var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4535
4614
  this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.DURATION_REQUEST, this.requestDurationHandler.bind(this)));
4536
4615
  };
4537
4616
 
4538
- _proto._update = function _update(now) {
4617
+ _proto._update = function _update(_now) {
4539
4618
  if (this.playState !== 'running') {
4540
4619
  return;
4541
4620
  }
4542
4621
 
4543
- if (!this._last || now - this._last >= this._granularity) {
4544
- if (!this._last && this._firstFrame) {
4545
- this._firstFrame = false;
4546
- this.eventbus.broadcast(TimelineEventNames.FIRST_FRAME);
4547
- }
4622
+ if (this._firstFrame) {
4623
+ this._firstFrame = false;
4624
+ this.eventbus.broadcast(TimelineEventNames.FIRST_FRAME);
4625
+ }
4548
4626
 
4549
- this._last = now;
4550
- this._currentPosition++;
4627
+ this._currentPosition++;
4551
4628
 
4552
- if (this._currentPosition > this._currentPlaylistItem.duration) {
4553
- if (this.loop) {
4554
- this._reset();
4555
- } else {
4556
- this.stop();
4557
- this.eventbus.broadcast(TimelineEventNames.COMPLETE);
4558
- return;
4559
- }
4560
- }
4629
+ if (this._currentPosition > this._currentPlaylistItem.duration) {
4630
+ if (this.loop) {
4631
+ this._resetToStartPosition();
4561
4632
 
4562
- this.eventbus.broadcast(TimelineEventNames.TIME, [{
4563
- position: this._currentPosition
4564
- }]);
4565
- this.eventbus.broadcast(TimelineEventNames.POSITION_UPDATE, [{
4566
- position: this._currentPosition,
4567
- duration: this._currentPlaylistItem.duration
4568
- }]);
4633
+ this.eventbus.broadcast(TimelineEventNames.RESTART);
4634
+ } else {
4635
+ this.stop();
4636
+ this.eventbus.broadcast(TimelineEventNames.COMPLETE);
4637
+ return;
4638
+ }
4569
4639
  }
4570
4640
 
4571
- this._requestID = requestAnimationFrame(this._updateBound);
4641
+ this.eventbus.broadcast(TimelineEventNames.TIME, [{
4642
+ position: this._currentPosition
4643
+ }]);
4644
+ this.eventbus.broadcast(TimelineEventNames.POSITION_UPDATE, [{
4645
+ position: this._currentPosition,
4646
+ duration: this._currentPlaylistItem.duration
4647
+ }]);
4572
4648
  };
4573
4649
 
4574
4650
  _proto._start = function _start() {
4575
- if (this._requestID && this.playState === 'running') {
4651
+ var _this$_abortControlle;
4652
+
4653
+ if (this.playState === 'running') {
4576
4654
  return;
4577
4655
  }
4578
4656
 
4579
4657
  this.playState = 'running';
4580
- this._requestID = requestAnimationFrame(this._updateBound);
4658
+ (_this$_abortControlle = this._abortController) == null ? void 0 : _this$_abortControlle.abort();
4659
+ this._abortController = new AbortController();
4660
+ animationInterval(this._tickInterval, this._abortController.signal, this._updateBound);
4581
4661
  };
4582
4662
 
4583
- _proto._reset = function _reset() {
4584
- this._cancelAnimationFrame();
4585
-
4586
- this._last = 0;
4663
+ _proto._resetToStartPosition = function _resetToStartPosition() {
4587
4664
  this._currentPosition = 0;
4588
4665
  };
4589
4666
 
@@ -4595,12 +4672,18 @@ var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4595
4672
  callBack(this._containerElement);
4596
4673
  };
4597
4674
 
4598
- _proto._cancelAnimationFrame = function _cancelAnimationFrame() {
4599
- if (this._requestID) {
4600
- cancelAnimationFrame(this._requestID);
4601
- this._requestID = -1;
4602
- this._last = 0;
4603
- this._currentPosition = 0;
4675
+ _proto._stopAnimationInterval = function _stopAnimationInterval(resetPosition) {
4676
+ var _this$_abortControlle2;
4677
+
4678
+ if (resetPosition === void 0) {
4679
+ resetPosition = true;
4680
+ }
4681
+
4682
+ (_this$_abortControlle2 = this._abortController) == null ? void 0 : _this$_abortControlle2.abort();
4683
+ this._abortController = undefined;
4684
+
4685
+ if (resetPosition) {
4686
+ this._resetToStartPosition();
4604
4687
  }
4605
4688
  };
4606
4689
 
@@ -4645,13 +4728,15 @@ var RequestAnimationFrameTimelineProvider = /*#__PURE__*/function () {
4645
4728
  };
4646
4729
 
4647
4730
  _proto.stop = function stop() {
4648
- this._cancelAnimationFrame();
4731
+ this._stopAnimationInterval();
4649
4732
 
4650
4733
  this.playState = 'stopped';
4651
4734
  this.eventbus.broadcast(TimelineEventNames.STOP);
4652
4735
  };
4653
4736
 
4654
4737
  _proto.pause = function pause() {
4738
+ this._stopAnimationInterval(false);
4739
+
4655
4740
  this.playState = 'paused';
4656
4741
  this.eventbus.broadcast(TimelineEventNames.PAUSE);
4657
4742
  };