eligius 1.0.6 → 1.0.8

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,165 +1,11 @@
1
+ import $ from 'jquery';
1
2
  import { isDefined } from 'ts-is-present';
2
3
  import fs from 'fs';
3
4
  import path from 'path';
4
5
  import lottie from 'lottie-web';
5
- import $ from 'jquery';
6
6
  import hotkeys from 'hotkeys-js';
7
7
  import { v4 } from 'uuid';
8
8
 
9
- function prepareValueForSerialization(value) {
10
- if (Array.isArray(value)) {
11
- return value.map(prepareValueForSerialization);
12
- } else if (typeof value === 'object') {
13
- return Object.fromEntries(Object.entries(value).map(function (_ref) {
14
- var name = _ref[0],
15
- value = _ref[1];
16
- return [name, prepareValueForSerialization(value)];
17
- }));
18
- } else if (typeof value === 'function') {
19
- return value.toString();
20
- }
21
-
22
- return value;
23
- }
24
-
25
- var DevToolEventListener = /*#__PURE__*/function () {
26
- function DevToolEventListener(agent) {
27
- this.agent = void 0;
28
- this.agent = agent;
29
- }
30
-
31
- var _proto = DevToolEventListener.prototype;
32
-
33
- _proto.handleEvent = function handleEvent(eventName, eventTopic, args) {
34
- this.agent.postMessage('eligius-diagnostics-event', {
35
- eventName: eventName,
36
- eventTopic: eventTopic,
37
- args: prepareValueForSerialization(args)
38
- });
39
- };
40
-
41
- return DevToolEventListener;
42
- }();
43
-
44
- var Diagnostics = /*#__PURE__*/function () {
45
- function Diagnostics() {}
46
-
47
- Diagnostics.send = function send(_name, _data) {
48
- console.log(_name, _data);
49
- };
50
-
51
- return Diagnostics;
52
- }();
53
- Diagnostics.active = void 0;
54
-
55
- var DEV_TOOLS_KEY = '__ELIGIUS_DEV_TOOLS__';
56
-
57
- var copyFunction = typeof structuredClone !== 'undefined' ? structuredClone : function (original) {
58
- return JSON.parse(JSON.stringify(original));
59
- };
60
- function deepCopy(original) {
61
- if (isDefined(original)) {
62
- return copyFunction(original);
63
- }
64
-
65
- return original;
66
- }
67
-
68
- function isPromise(obj) {
69
- return typeof obj === 'object' && typeof obj.then === 'function';
70
- }
71
-
72
- var Action = /*#__PURE__*/function () {
73
- function Action(name, startOperations, eventbus) {
74
- this.name = void 0;
75
- this.startOperations = void 0;
76
- this.eventbus = void 0;
77
- this.id = '';
78
- this.name = name;
79
- this.startOperations = startOperations;
80
- this.eventbus = eventbus;
81
- }
82
-
83
- var _proto = Action.prototype;
84
-
85
- _proto.start = function start(initOperationData) {
86
- var _this$name,
87
- _this = this;
88
-
89
- Diagnostics.active && Diagnostics.send('eligius-diagnostics-action', ((_this$name = this.name) != null ? _this$name : 'Action') + " begins executing start operations");
90
- var context = {
91
- currentIndex: -1,
92
- eventbus: this.eventbus
93
- };
94
- var result = new Promise(function (resolve, reject) {
95
- _this.executeOperation(_this.startOperations, 0, resolve, reject, initOperationData, context);
96
- })["catch"](function (e) {
97
- Diagnostics.active && Diagnostics.send('eligius-diagnostics-action-error', {
98
- name: name,
99
- error: e
100
- });
101
- console.error("Error in action start '" + _this.name + "'");
102
- console.error(e);
103
- throw e;
104
- });
105
- return !Diagnostics.active ? result : result.then(function (operationsResult) {
106
- var _this$name2;
107
-
108
- Diagnostics.send('eligius-diagnostics-action', ((_this$name2 = _this.name) != null ? _this$name2 : 'Action') + " finished executing start operations");
109
- return operationsResult;
110
- });
111
- };
112
-
113
- _proto.executeOperation = function executeOperation(operations, idx, resolve, reject, previousOperationData, context) {
114
- var _this2 = this;
115
-
116
- if (previousOperationData === void 0) {
117
- previousOperationData = {};
118
- }
119
-
120
- if (context.newIndex !== undefined) {
121
- idx = context.newIndex;
122
- delete context.newIndex;
123
- }
124
-
125
- context.currentIndex = idx;
126
-
127
- if (context.skipNextOperation) {
128
- if (idx < operations.length) {
129
- this.executeOperation(operations, ++idx, resolve, reject, previousOperationData, context);
130
- } else {
131
- resolve(previousOperationData);
132
- }
133
- }
134
-
135
- if (idx < operations.length) {
136
- var operationInfo = operations[idx];
137
- var copy = operationInfo.operationData ? deepCopy(operationInfo.operationData) : {};
138
- var mergedOperationData = Object.assign(previousOperationData, copy);
139
- Diagnostics.active && Diagnostics.send('eligius-diagnostics-operation', {
140
- systemName: operationInfo.systemName,
141
- operationData: operationInfo.operationData,
142
- context: context
143
- });
144
- var operationResult = operationInfo.instance.call(context, mergedOperationData);
145
-
146
- if (isPromise(operationResult)) {
147
- operationResult.then(function (resultOperationData) {
148
- _this2.executeOperation(operations, ++idx, resolve, reject, resultOperationData, context);
149
- })["catch"](function (error) {
150
- reject(error);
151
- });
152
- } else {
153
- this.executeOperation(operations, ++idx, resolve, reject, operationResult, context);
154
- }
155
- } else {
156
- resolve(previousOperationData);
157
- }
158
- };
159
-
160
- return Action;
161
- }();
162
-
163
9
  function _regeneratorRuntime() {
164
10
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
165
11
 
@@ -573,6 +419,179 @@ function _setPrototypeOf(o, p) {
573
419
  return _setPrototypeOf(o, p);
574
420
  }
575
421
 
422
+ function prepareValueForSerialization(value) {
423
+ if (Array.isArray(value)) {
424
+ return value.map(prepareValueForSerialization);
425
+ } else if (value instanceof $) {
426
+ return 'jQuery object';
427
+ } else if (typeof value === 'object') {
428
+ return Object.fromEntries(Object.entries(value).map(function (_ref) {
429
+ var propName = _ref[0],
430
+ propValue = _ref[1];
431
+ return [propName, prepareValueForSerialization(propValue)];
432
+ }));
433
+ } else if (typeof value === 'function') {
434
+ var funcString = value.toString();
435
+ var paranIndex = funcString.indexOf('{');
436
+
437
+ if (paranIndex > -1) {
438
+ return funcString.substring(0, funcString.indexOf('{') + 1);
439
+ }
440
+
441
+ return funcString;
442
+ }
443
+
444
+ return value;
445
+ }
446
+
447
+ var DevToolEventListener = /*#__PURE__*/function () {
448
+ function DevToolEventListener(agent) {
449
+ this.agent = void 0;
450
+ this.agent = agent;
451
+ }
452
+
453
+ var _proto = DevToolEventListener.prototype;
454
+
455
+ _proto.handleEvent = function handleEvent(eventName, eventTopic, args) {
456
+ var message = {
457
+ eventName: eventName,
458
+ eventTopic: eventTopic,
459
+ args: prepareValueForSerialization(args)
460
+ };
461
+
462
+ try {
463
+ this.agent.postMessage('eligius-diagnostics-event', message);
464
+ } catch (e) {
465
+ console.error('postmessage failed');
466
+ console.error(e);
467
+ console.log('message', message);
468
+ }
469
+ };
470
+
471
+ return DevToolEventListener;
472
+ }();
473
+
474
+ var Diagnostics = /*#__PURE__*/function () {
475
+ function Diagnostics() {}
476
+
477
+ Diagnostics.send = function send(_name, _data) {
478
+ console.log(_name, _data);
479
+ };
480
+
481
+ return Diagnostics;
482
+ }();
483
+ Diagnostics.active = void 0;
484
+
485
+ var DEV_TOOLS_KEY = '__ELIGIUS_DEV_TOOLS__';
486
+
487
+ var copyFunction = typeof structuredClone !== 'undefined' ? structuredClone : function (original) {
488
+ return JSON.parse(JSON.stringify(original));
489
+ };
490
+ function deepCopy(original) {
491
+ if (isDefined(original)) {
492
+ return copyFunction(original);
493
+ }
494
+
495
+ return original;
496
+ }
497
+
498
+ function isPromise(obj) {
499
+ return typeof obj === 'object' && typeof obj.then === 'function';
500
+ }
501
+
502
+ var Action = /*#__PURE__*/function () {
503
+ function Action(name, startOperations, eventbus) {
504
+ this.name = void 0;
505
+ this.startOperations = void 0;
506
+ this.eventbus = void 0;
507
+ this.id = '';
508
+ this.name = name;
509
+ this.startOperations = startOperations;
510
+ this.eventbus = eventbus;
511
+ }
512
+
513
+ var _proto = Action.prototype;
514
+
515
+ _proto.start = function start(initOperationData) {
516
+ var _this$name,
517
+ _this = this;
518
+
519
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action', ((_this$name = this.name) != null ? _this$name : 'Action') + " begins executing start operations");
520
+ var context = {
521
+ currentIndex: -1,
522
+ eventbus: this.eventbus
523
+ };
524
+ var result = new Promise(function (resolve, reject) {
525
+ _this.executeOperation(_this.startOperations, 0, resolve, reject, initOperationData, context);
526
+ })["catch"](function (e) {
527
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action-error', {
528
+ name: name,
529
+ error: e
530
+ });
531
+ console.error("Error in action start '" + _this.name + "'");
532
+ console.error(e);
533
+ throw e;
534
+ });
535
+ return !Diagnostics.active ? result : result.then(function (operationsResult) {
536
+ var _this$name2;
537
+
538
+ Diagnostics.send('eligius-diagnostics-action', ((_this$name2 = _this.name) != null ? _this$name2 : 'Action') + " finished executing start operations");
539
+ return operationsResult;
540
+ });
541
+ };
542
+
543
+ _proto.executeOperation = function executeOperation(operations, idx, resolve, reject, previousOperationData, context) {
544
+ var _this2 = this;
545
+
546
+ if (previousOperationData === void 0) {
547
+ previousOperationData = {};
548
+ }
549
+
550
+ if (context.newIndex !== undefined) {
551
+ idx = context.newIndex;
552
+ delete context.newIndex;
553
+ }
554
+
555
+ context.currentIndex = idx;
556
+
557
+ if (context.skipNextOperation) {
558
+ if (idx < operations.length) {
559
+ this.executeOperation(operations, ++idx, resolve, reject, previousOperationData, context);
560
+ } else {
561
+ resolve(previousOperationData);
562
+ }
563
+ }
564
+
565
+ if (idx < operations.length) {
566
+ var operationInfo = operations[idx];
567
+ var copy = operationInfo.operationData ? deepCopy(operationInfo.operationData) : {};
568
+ var mergedOperationData = Object.assign(previousOperationData, copy);
569
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-operation', {
570
+ systemName: operationInfo.systemName,
571
+ operationData: mergedOperationData,
572
+ context: _extends({}, context, {
573
+ eventbus: undefined
574
+ })
575
+ });
576
+ var operationResult = operationInfo.instance.call(context, mergedOperationData);
577
+
578
+ if (isPromise(operationResult)) {
579
+ operationResult.then(function (promisedOperationResult) {
580
+ _this2.executeOperation(operations, ++idx, resolve, reject, promisedOperationResult, context);
581
+ })["catch"](function (error) {
582
+ reject(error);
583
+ });
584
+ } else {
585
+ this.executeOperation(operations, ++idx, resolve, reject, operationResult, context);
586
+ }
587
+ } else {
588
+ resolve(previousOperationData);
589
+ }
590
+ };
591
+
592
+ return Action;
593
+ }();
594
+
576
595
  var EndableAction = /*#__PURE__*/function (_Action) {
577
596
  _inheritsLoose(EndableAction, _Action);
578
597
 
@@ -2029,38 +2048,36 @@ var ctrls = {
2029
2048
  */
2030
2049
 
2031
2050
  var EligiusEngine = /*#__PURE__*/function () {
2032
- function EligiusEngine(configuration, eventbus, timelineProviders, _languageManager) {
2051
+ function EligiusEngine(configuration, eventbus, timelineProviders, languageManager) {
2033
2052
  this.configuration = void 0;
2034
2053
  this.eventbus = void 0;
2035
2054
  this.timelineProviders = void 0;
2036
- this._languageManager = void 0;
2055
+ this.languageManager = void 0;
2037
2056
  this._timeLineActionsLookup = {};
2038
- this._eventbusListeners = [];
2057
+ this._eventbusRemovers = [];
2039
2058
  this._currentTimelineUri = '';
2040
2059
  this._activeTimelineProvider = undefined;
2041
2060
  this._lastPosition = -1;
2042
2061
  this.configuration = configuration;
2043
2062
  this.eventbus = eventbus;
2044
2063
  this.timelineProviders = timelineProviders;
2045
- this._languageManager = _languageManager;
2064
+ this.languageManager = languageManager;
2046
2065
  }
2047
2066
 
2048
2067
  var _proto = EligiusEngine.prototype;
2049
2068
 
2050
2069
  _proto.init = function init() {
2070
+ var _timelines$0$uri;
2071
+
2051
2072
  this._createLayoutTemplate();
2052
2073
 
2053
2074
  this._addInitialisationListeners();
2054
2075
 
2055
2076
  var timelines = this.configuration.timelines;
2056
- this._currentTimelineUri = timelines && timelines.length ? timelines[0].uri : '';
2077
+ this._currentTimelineUri = (_timelines$0$uri = timelines == null ? void 0 : timelines[0].uri) != null ? _timelines$0$uri : '';
2057
2078
 
2058
2079
  this._createTimelineLookup();
2059
2080
 
2060
- this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.TIME, this._onTimeHandler.bind(this, Math.floor)));
2061
-
2062
- this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.SEEK, this._onSeekHandler.bind(this, Math.floor)));
2063
-
2064
2081
  return this._initializeTimelineProvider();
2065
2082
  };
2066
2083
 
@@ -2178,9 +2195,10 @@ var EligiusEngine = /*#__PURE__*/function () {
2178
2195
  return this._cleanUp();
2179
2196
 
2180
2197
  case 2:
2198
+ this.languageManager.destroy();
2181
2199
  this._activeTimelineProvider = undefined;
2182
2200
 
2183
- this._eventbusListeners.forEach(function (remover) {
2201
+ this._eventbusRemovers.forEach(function (remover) {
2184
2202
  return remover();
2185
2203
  });
2186
2204
 
@@ -2194,7 +2212,7 @@ var EligiusEngine = /*#__PURE__*/function () {
2194
2212
  container = $(containerSelector);
2195
2213
  container.empty();
2196
2214
 
2197
- case 8:
2215
+ case 9:
2198
2216
  case "end":
2199
2217
  return _context3.stop();
2200
2218
  }
@@ -2209,20 +2227,28 @@ var EligiusEngine = /*#__PURE__*/function () {
2209
2227
  return destroy;
2210
2228
  }();
2211
2229
 
2230
+ _proto._addEventListener = function _addEventListener(eventName, eventHandler, eventTopic) {
2231
+ this._eventbusRemovers.push(this.eventbus.on(eventName, eventHandler, eventTopic));
2232
+ };
2233
+
2212
2234
  _proto._addInitialisationListeners = function _addInitialisationListeners() {
2213
- this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.REQUEST_ENGINE_ROOT, this._handleRequestEngineRoot.bind(this, this.configuration.containerSelector)));
2235
+ this._addEventListener(TimelineEventNames.REQUEST_ENGINE_ROOT, this._handleRequestEngineRoot.bind(this, this.configuration.containerSelector));
2236
+
2237
+ this._addEventListener(TimelineEventNames.REQUEST_TIMELINE_URI, this._handleRequestTimelineUri.bind(this));
2214
2238
 
2215
- this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.REQUEST_TIMELINE_URI, this._handleRequestTimelineUri.bind(this)));
2239
+ this._addEventListener(TimelineEventNames.REQUEST_CURRENT_TIMELINE_POSITION, this._handleRequestTimelinePosition.bind(this, Math.floor));
2216
2240
 
2217
- this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.REQUEST_CURRENT_TIMELINE_POSITION, this._handleRequestTimelinePosition.bind(this, Math.floor)));
2241
+ this._addEventListener(TimelineEventNames.REQUEST_TIMELINE_CLEANUP, this._handleTimelineComplete.bind(this));
2218
2242
 
2219
- this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.REQUEST_TIMELINE_CLEANUP, this._handleTimelineComplete.bind(this)));
2243
+ this._addEventListener(TimelineEventNames.EXECUTE_TIMELINEACTION, this._handleExecuteTimelineAction.bind(this));
2220
2244
 
2221
- this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.EXECUTE_TIMELINEACTION, this._handleExecuteTimelineAction.bind(this)));
2245
+ this._addEventListener(TimelineEventNames.RESIZE_TIMELINEACTION, this._resizeTimelineAction.bind(this));
2222
2246
 
2223
- this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.RESIZE_TIMELINEACTION, this._resizeTimelineAction.bind(this)));
2247
+ this._addEventListener(TimelineEventNames.REQUEST_CURRENT_TIMELINE, this._requestCurrentTimeline.bind(this));
2224
2248
 
2225
- this._eventbusListeners.push(this.eventbus.on(TimelineEventNames.REQUEST_CURRENT_TIMELINE, this._requestCurrentTimeline.bind(this)));
2249
+ this._addEventListener(TimelineEventNames.TIME, this._onTimeHandler.bind(this, Math.floor));
2250
+
2251
+ this._addEventListener(TimelineEventNames.SEEK, this._onSeekHandler.bind(this, Math.floor));
2226
2252
  };
2227
2253
 
2228
2254
  _proto._createTimelineLookup = function _createTimelineLookup() {
@@ -2683,6 +2709,9 @@ var Eventbus = /*#__PURE__*/function () {
2683
2709
  };
2684
2710
 
2685
2711
  this.on(eventName, eventHandlerDecorator, eventTopic);
2712
+ return function () {
2713
+ _this2.off(eventName, eventHandlerDecorator, eventTopic);
2714
+ };
2686
2715
  };
2687
2716
 
2688
2717
  _proto.off = function off(eventName, eventHandler, eventTopic) {
@@ -2706,13 +2735,29 @@ var Eventbus = /*#__PURE__*/function () {
2706
2735
  };
2707
2736
 
2708
2737
  _proto.registerEventlistener = function registerEventlistener(eventbusListener) {
2738
+ var _this3 = this;
2739
+
2709
2740
  this.eventListeners.push(eventbusListener);
2741
+ return function () {
2742
+ var index = _this3.eventListeners.indexOf(eventbusListener);
2743
+
2744
+ if (index > -1) {
2745
+ _this3.eventListeners.splice(index, 1);
2746
+ }
2747
+ };
2710
2748
  };
2711
2749
 
2712
2750
  _proto.registerInterceptor = function registerInterceptor(eventName, interceptor, eventTopic) {
2713
2751
  var interceptors = this._getEventInterceptors(eventName, eventTopic);
2714
2752
 
2715
2753
  interceptors.push(interceptor);
2754
+ return function () {
2755
+ var index = interceptors.indexOf(interceptor);
2756
+
2757
+ if (index > -1) {
2758
+ interceptors.splice(index, 1);
2759
+ }
2760
+ };
2716
2761
  };
2717
2762
 
2718
2763
  _proto._callHandlers = function _callHandlers(eventName, eventTopic, args) {
@@ -2776,40 +2821,38 @@ var LanguageManager = /*#__PURE__*/function () {
2776
2821
  function LanguageManager(_currentLanguage, labels, _eventbus) {
2777
2822
  this._currentLanguage = void 0;
2778
2823
  this._eventbus = void 0;
2779
- this._labelLookup = {};
2780
- this._eventbusListeners = [];
2824
+ this._labelLookup = void 0;
2825
+ this._eventbusRemovers = [];
2781
2826
  this._currentLanguage = _currentLanguage;
2782
2827
  this._eventbus = _eventbus;
2783
2828
 
2784
- if (!_currentLanguage || !_currentLanguage.length) {
2785
- throw new Error('language ctor arg cannot be null or have zero length');
2786
- }
2787
-
2788
- if (!labels) {
2789
- throw new Error('labels ctor arg cannot be null');
2790
- }
2791
-
2792
- if (!_eventbus) {
2793
- throw new Error('eventbus ctor arg cannot be null');
2829
+ if (!_currentLanguage) {
2830
+ throw new Error('language ctor arg cannot have zero length');
2794
2831
  }
2795
2832
 
2796
2833
  this._setRootElementLang(_currentLanguage);
2797
2834
 
2798
- this._createLabelLookup(labels);
2835
+ this._labelLookup = this._createLabelLookup(labels);
2799
2836
 
2800
2837
  this._addEventbusListeners(_eventbus);
2801
2838
  }
2802
2839
 
2803
2840
  var _proto = LanguageManager.prototype;
2804
2841
 
2842
+ _proto.destroy = function destroy() {
2843
+ this._eventbusRemovers.forEach(function (x) {
2844
+ return x();
2845
+ });
2846
+ };
2847
+
2805
2848
  _proto._addEventbusListeners = function _addEventbusListeners(eventbus) {
2806
- this._eventbusListeners.push(eventbus.on(TimelineEventNames.REQUEST_LABEL_COLLECTION, this._handleRequestLabelCollection.bind(this)));
2849
+ this._eventbusRemovers.push(eventbus.on(TimelineEventNames.REQUEST_LABEL_COLLECTION, this._handleRequestLabelCollection.bind(this)));
2807
2850
 
2808
- this._eventbusListeners.push(eventbus.on(TimelineEventNames.REQUEST_LABEL_COLLECTIONS, this._handleRequestLabelCollections.bind(this)));
2851
+ this._eventbusRemovers.push(eventbus.on(TimelineEventNames.REQUEST_LABEL_COLLECTIONS, this._handleRequestLabelCollections.bind(this)));
2809
2852
 
2810
- this._eventbusListeners.push(eventbus.on(TimelineEventNames.REQUEST_CURRENT_LANGUAGE, this._handleRequestCurrentLanguage.bind(this)));
2853
+ this._eventbusRemovers.push(eventbus.on(TimelineEventNames.REQUEST_CURRENT_LANGUAGE, this._handleRequestCurrentLanguage.bind(this)));
2811
2854
 
2812
- this._eventbusListeners.push(eventbus.on(TimelineEventNames.LANGUAGE_CHANGE, this._handleLanguageChange.bind(this)));
2855
+ this._eventbusRemovers.push(eventbus.on(TimelineEventNames.LANGUAGE_CHANGE, this._handleLanguageChange.bind(this)));
2813
2856
  };
2814
2857
 
2815
2858
  _proto._handleRequestCurrentLanguage = function _handleRequestCurrentLanguage(resultCallback) {
@@ -2860,11 +2903,10 @@ var LanguageManager = /*#__PURE__*/function () {
2860
2903
  };
2861
2904
 
2862
2905
  _proto._createLabelLookup = function _createLabelLookup(labels) {
2863
- var _this3 = this;
2864
-
2865
- labels.forEach(function (label) {
2866
- _this3._labelLookup[label.id] = label.labels;
2867
- });
2906
+ return labels.reduce(function (acc, label) {
2907
+ acc[label.id] = label.labels;
2908
+ return acc;
2909
+ }, {});
2868
2910
  };
2869
2911
 
2870
2912
  return LanguageManager;
@@ -2872,80 +2914,136 @@ var LanguageManager = /*#__PURE__*/function () {
2872
2914
 
2873
2915
  var EngineFactory = /*#__PURE__*/function () {
2874
2916
  function EngineFactory(importer, windowRef, options) {
2875
- var _options$devtools;
2917
+ var _options$eventbus, _options$devtools;
2876
2918
 
2877
- this.resizeTimeout = -1;
2878
- this.actionsLookup = {};
2879
- this.importer = void 0;
2880
- this.eventbus = void 0;
2881
- this._handleSpaceBound = void 0;
2882
- this.importer = importer;
2883
- this.eventbus = (options == null ? void 0 : options.eventbus) || new Eventbus();
2919
+ this._actionsLookup = {};
2920
+ this._eventbus = void 0;
2921
+ this._eventRemovers = [];
2922
+ this._importer = void 0;
2923
+ this._resizeTimeout = -1;
2924
+ this._importer = importer;
2925
+ this._eventbus = (_options$eventbus = options == null ? void 0 : options.eventbus) != null ? _options$eventbus : new Eventbus();
2884
2926
  Diagnostics.active = (_options$devtools = options == null ? void 0 : options.devtools) != null ? _options$devtools : false;
2885
2927
 
2886
2928
  if (Diagnostics.active) {
2887
- this._initializeDevtools(this.eventbus);
2929
+ this._initializeDevtools(this._eventbus);
2888
2930
  }
2889
2931
 
2890
- this.eventbus.on(TimelineEventNames.REQUEST_INSTANCE, this._requestInstanceHandler.bind(this));
2891
- this.eventbus.on(TimelineEventNames.REQUEST_ACTION, this._requestActionHandler.bind(this));
2892
- this.eventbus.on(TimelineEventNames.REQUEST_FUNCTION, this._requestFunctionHandler.bind(this));
2893
- this._handleSpaceBound = this._handleSpacePress.bind(this);
2894
- hotkeys('space', this._handleSpaceBound);
2895
- $(windowRef).resize(this._resizeHandler.bind(this));
2932
+ this._eventRemovers.push(this._eventbus.on(TimelineEventNames.REQUEST_INSTANCE, this._requestInstanceHandler.bind(this)));
2933
+
2934
+ this._eventRemovers.push(this._eventbus.on(TimelineEventNames.REQUEST_ACTION, this._requestActionHandler.bind(this)));
2935
+
2936
+ this._eventRemovers.push(this._eventbus.on(TimelineEventNames.REQUEST_FUNCTION, this._requestFunctionHandler.bind(this)));
2937
+
2938
+ var handleSpaceBound = this._handleSpacePress.bind(this);
2939
+
2940
+ hotkeys('space', handleSpaceBound);
2941
+
2942
+ this._eventRemovers.push(function () {
2943
+ return hotkeys.unbind('space', handleSpaceBound);
2944
+ });
2945
+
2946
+ var resizeBound = this._resizeHandler.bind(this);
2947
+
2948
+ var jqWin = $(windowRef);
2949
+ jqWin.on('resize', resizeBound);
2950
+
2951
+ this._eventRemovers.push(function () {
2952
+ return jqWin.off('resize', resizeBound);
2953
+ });
2896
2954
  }
2897
2955
 
2898
2956
  var _proto = EngineFactory.prototype;
2899
2957
 
2900
2958
  _proto._handleSpacePress = function _handleSpacePress(keyboardEvent, _hotkeysEvent) {
2901
2959
  keyboardEvent.preventDefault();
2902
- this.eventbus.broadcast(TimelineEventNames.PLAY_TOGGLE_REQUEST);
2960
+
2961
+ this._eventbus.broadcast(TimelineEventNames.PLAY_TOGGLE_REQUEST);
2962
+
2903
2963
  return false;
2904
2964
  };
2905
2965
 
2906
2966
  _proto._initializeDevtools = function _initializeDevtools(eventbus) {
2967
+ var _this = this;
2968
+
2907
2969
  var diagnosticInfo = window[DEV_TOOLS_KEY];
2908
2970
 
2909
2971
  if (diagnosticInfo) {
2910
2972
  var agent = diagnosticInfo.agent;
2911
- var eventbusListener = new DevToolEventListener(agent);
2912
- eventbus.registerEventlistener(eventbusListener);
2913
2973
 
2914
- Diagnostics.send = function (name, data) {
2915
- agent.postMessage(name, data);
2974
+ this._eventRemovers.push(eventbus.registerEventlistener(new DevToolEventListener(agent)));
2975
+
2976
+ this._eventRemovers.push(agent.subscribe(function (message) {
2977
+ if (message.type === 'playcontrol') {
2978
+ switch (message.data.kind) {
2979
+ case 'play':
2980
+ _this._eventbus.broadcast(TimelineEventNames.PLAY_REQUEST);
2981
+
2982
+ break;
2983
+
2984
+ case 'stop':
2985
+ _this._eventbus.broadcast(TimelineEventNames.STOP_REQUEST);
2986
+
2987
+ break;
2988
+
2989
+ case 'pause':
2990
+ _this._eventbus.broadcast(TimelineEventNames.PAUSE_REQUEST);
2991
+
2992
+ break;
2993
+
2994
+ case 'seek':
2995
+ _this._eventbus.broadcast(TimelineEventNames.SEEK_REQUEST, [message.data.args]);
2996
+
2997
+ break;
2998
+ }
2999
+ }
3000
+ }));
3001
+
3002
+ Diagnostics.send = function (name, messageData) {
3003
+ var message = prepareValueForSerialization(messageData);
3004
+
3005
+ try {
3006
+ agent.postMessage(name, message);
3007
+ } catch (e) {
3008
+ console.error('postmessage failed');
3009
+ console.error(e);
3010
+ console.log('message', message);
3011
+ }
2916
3012
  };
2917
3013
 
2918
3014
  Diagnostics.send('eligius-diagnostics-factory', 'Diagnostics initialized');
2919
3015
  } else {
2920
- console.warn(DEV_TOOLS_KEY + " property not found on window, please install the extension.");
3016
+ console.warn(DEV_TOOLS_KEY + " property not found on window, please install the Eligius Devtools extension.");
2921
3017
  }
2922
3018
  };
2923
3019
 
2924
3020
  _proto.destroy = function destroy() {
2925
- this.eventbus.clear();
2926
- hotkeys.unbind('space', this._handleSpaceBound);
3021
+ this._eventRemovers.forEach(function (x) {
3022
+ return x();
3023
+ });
2927
3024
  };
2928
3025
 
2929
3026
  _proto._resizeHandler = function _resizeHandler() {
2930
- var _this = this;
3027
+ var _this2 = this;
2931
3028
 
2932
- if (this.resizeTimeout) {
2933
- clearTimeout(this.resizeTimeout);
3029
+ if (this._resizeTimeout) {
3030
+ clearTimeout(this._resizeTimeout);
3031
+ this._resizeTimeout = -1;
2934
3032
  }
2935
3033
 
2936
- this.resizeTimeout = setTimeout(function () {
2937
- _this.eventbus.broadcast(TimelineEventNames.RESIZE);
3034
+ this._resizeTimeout = setTimeout(function () {
3035
+ _this2._eventbus.broadcast(TimelineEventNames.RESIZE);
2938
3036
  }, 200);
2939
3037
  };
2940
3038
 
2941
3039
  _proto._importSystemEntryWithEventbusDependency = function _importSystemEntryWithEventbusDependency(systemName) {
2942
3040
  var ctor = this._importSystemEntry(systemName);
2943
3041
 
2944
- return new ctor(this.eventbus);
3042
+ return new ctor(this._eventbus);
2945
3043
  };
2946
3044
 
2947
3045
  _proto._importSystemEntry = function _importSystemEntry(systemName) {
2948
- return this.importer["import"](systemName)[systemName];
3046
+ return this._importer["import"](systemName)[systemName];
2949
3047
  };
2950
3048
 
2951
3049
  _proto._requestInstanceHandler = function _requestInstanceHandler(systemName, resultCallback) {
@@ -2957,7 +3055,7 @@ var EngineFactory = /*#__PURE__*/function () {
2957
3055
  };
2958
3056
 
2959
3057
  _proto._requestActionHandler = function _requestActionHandler(systemName, resultCallback) {
2960
- var action = this.actionsLookup[systemName];
3058
+ var action = this._actionsLookup[systemName];
2961
3059
 
2962
3060
  if (action) {
2963
3061
  resultCallback(action);
@@ -2978,29 +3076,31 @@ var EngineFactory = /*#__PURE__*/function () {
2978
3076
 
2979
3077
  if ((_configuration$eventA = configuration.eventActions) != null && _configuration$eventA.length) {
2980
3078
  actionRegistryListener = new ActionRegistryEventbusListener();
2981
- this.eventbus.registerEventlistener(actionRegistryListener);
3079
+
3080
+ this._eventRemovers.push(this._eventbus.registerEventlistener(actionRegistryListener));
2982
3081
  }
2983
3082
 
2984
- this.eventbus.registerInterceptor(TimelineEventNames.REQUEST_TIMELINE_URI, new RequestVideoUriInterceptor(this.eventbus));
2985
- resolver = resolver || new ConfigurationResolver(this.importer, this.eventbus);
3083
+ this._eventRemovers.push(this._eventbus.registerInterceptor(TimelineEventNames.REQUEST_TIMELINE_URI, new RequestVideoUriInterceptor(this._eventbus)));
3084
+
3085
+ resolver = resolver || new ConfigurationResolver(this._importer, this._eventbus);
2986
3086
 
2987
3087
  var _resolver$process = resolver.process(configuration, actionRegistryListener),
2988
3088
  actionLookup = _resolver$process[0],
2989
3089
  resolvedConfiguration = _resolver$process[1];
2990
3090
 
2991
- this.actionsLookup = actionLookup;
3091
+ this._actionsLookup = actionLookup;
2992
3092
 
2993
- var timelineProviders = this._createTimelineProviders(resolvedConfiguration, this.eventbus);
3093
+ var timelineProviders = this._createTimelineProviders(resolvedConfiguration, this._eventbus);
2994
3094
 
2995
3095
  var language = configuration.language,
2996
3096
  labels = configuration.labels;
2997
- var languageManager = new LanguageManager(language, labels, this.eventbus);
2998
- var engineInstance = new EngineClass(resolvedConfiguration, this.eventbus, timelineProviders, languageManager);
3097
+ var languageManager = new LanguageManager(language, labels, this._eventbus);
3098
+ var engineInstance = new EngineClass(resolvedConfiguration, this._eventbus, timelineProviders, languageManager);
2999
3099
  return engineInstance;
3000
3100
  };
3001
3101
 
3002
3102
  _proto._createTimelineProviders = function _createTimelineProviders(configuration, eventbus) {
3003
- var _this2 = this;
3103
+ var _this3 = this;
3004
3104
 
3005
3105
  var timelineProviderSettings = configuration.timelineProviderSettings;
3006
3106
  var result = Object.entries(timelineProviderSettings).reduce(function (acc, _ref) {
@@ -3011,7 +3111,7 @@ var EngineFactory = /*#__PURE__*/function () {
3011
3111
  return acc;
3012
3112
  }
3013
3113
 
3014
- var timelineProviderClass = _this2._importSystemEntry(settings.systemName);
3114
+ var timelineProviderClass = _this3._importSystemEntry(settings.systemName);
3015
3115
 
3016
3116
  acc[timelineType] = {
3017
3117
  id: settings.id,