@raydiant/playlist-window-manager 0.14.26 → 0.15.0
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.
- package/build/PlaylistWindowManager.d.ts +2 -0
- package/build/PlaylistWindowManager.js +73 -31
- package/build/PresentationWindow.d.ts +1 -0
- package/build/PresentationWindow.js +6 -0
- package/build/embeddedApps.js +1 -1
- package/build/embeddedApps.test.js +5 -0
- package/package.json +2 -2
- package/src/PlaylistWindowManager.ts +64 -21
- package/src/PresentationWindow.ts +9 -0
- package/src/embeddedApps.test.ts +11 -0
- package/src/embeddedApps.ts +1 -1
|
@@ -57,6 +57,7 @@ export default class PlaylistWindowManager extends EventEmitter {
|
|
|
57
57
|
setRuleEngine(ruleEngine: RE.RuleEngine): Promise<void>;
|
|
58
58
|
getState(): PlaylistWindowManagerState | null;
|
|
59
59
|
setState(state: PlaylistWindowManagerState): void;
|
|
60
|
+
reinitializeRuleEngineState(newRulesDataStoreObj: RE.RulesDataStore): void;
|
|
60
61
|
reinitialize(state: PlaylistWindowManagerState, ruleEngine: RE.RuleEngine, shouldInterruptPlayback: boolean): Promise<void>;
|
|
61
62
|
private registerInterrupt;
|
|
62
63
|
endCurrentPresentation(): void;
|
|
@@ -89,6 +90,7 @@ export default class PlaylistWindowManager extends EventEmitter {
|
|
|
89
90
|
private handleCurrentPresentationComplete;
|
|
90
91
|
private handleCurrentPresentationError;
|
|
91
92
|
private handleNextPresentationError;
|
|
93
|
+
private checkPreviewAction;
|
|
92
94
|
private startPreviewCheck;
|
|
93
95
|
private stopInterruptCheck;
|
|
94
96
|
private getTheme;
|
|
@@ -270,6 +270,35 @@ var PlaylistWindowManager = /** @class */ (function (_super) {
|
|
|
270
270
|
}
|
|
271
271
|
});
|
|
272
272
|
}); };
|
|
273
|
+
_this.checkPreviewAction = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
274
|
+
var logger, preview;
|
|
275
|
+
return __generator(this, function (_a) {
|
|
276
|
+
switch (_a.label) {
|
|
277
|
+
case 0:
|
|
278
|
+
logger = this.options.logger;
|
|
279
|
+
if (!this.ruleEngine) {
|
|
280
|
+
return [2 /*return*/];
|
|
281
|
+
}
|
|
282
|
+
preview = this.ruleEngine.previewNext();
|
|
283
|
+
if (!this.shouldPreload(preview.presentationId)) return [3 /*break*/, 3];
|
|
284
|
+
logger.info("Preview check replacing preloaded presentation '" + this.nextPresentationId() + "' with new presentation '" + preview.presentationId + "'");
|
|
285
|
+
return [4 /*yield*/, this.removeNextWindow()];
|
|
286
|
+
case 1:
|
|
287
|
+
_a.sent();
|
|
288
|
+
this.nextPresentation = preview;
|
|
289
|
+
return [4 /*yield*/, this.preloadNextWindow()];
|
|
290
|
+
case 2:
|
|
291
|
+
_a.sent();
|
|
292
|
+
_a.label = 3;
|
|
293
|
+
case 3:
|
|
294
|
+
if (preview.shouldInterrupt) {
|
|
295
|
+
logger.info("Interrupting current presentation with '" + preview.presentationId + "'");
|
|
296
|
+
this.registerInterrupt();
|
|
297
|
+
}
|
|
298
|
+
return [2 /*return*/];
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}); };
|
|
273
302
|
_this.ruleEngine = options.ruleEngine;
|
|
274
303
|
_this.state = options.state;
|
|
275
304
|
_this.bounds = options.bounds;
|
|
@@ -430,6 +459,39 @@ var PlaylistWindowManager = /** @class */ (function (_super) {
|
|
|
430
459
|
PlaylistWindowManager.prototype.setState = function (state) {
|
|
431
460
|
this.state = state;
|
|
432
461
|
};
|
|
462
|
+
// For setting dynamic tags data from workers and reevaluate rules for playlists
|
|
463
|
+
// input: newRulesDataStoreObj: {'workers': {'ai': {'percentMales': 30}}}
|
|
464
|
+
PlaylistWindowManager.prototype.reinitializeRuleEngineState = function (newRulesDataStoreObj) {
|
|
465
|
+
var _this = this;
|
|
466
|
+
var logger = this.options.logger;
|
|
467
|
+
logger.info('Dynamic Rule engine state change event received!');
|
|
468
|
+
if (this.ruleEngine) {
|
|
469
|
+
logger.info("Existing Rule Data Store: ", this.ruleEngine.state);
|
|
470
|
+
logger.info("New Rule Data Store data received: ", newRulesDataStoreObj);
|
|
471
|
+
this.ruleEngine.state.rulesDataStore = newRulesDataStoreObj;
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
logger.warn("No Rule engine found for reinitiazling the state!");
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
// re-evaluate the next presentations depending upon the new rule engine state
|
|
478
|
+
var checkOverridePresentation = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
479
|
+
return __generator(this, function (_a) {
|
|
480
|
+
if (this.ruleEngine) {
|
|
481
|
+
this.checkPreviewAction();
|
|
482
|
+
// calling reinitialize Rule engine state for inner playlist windows (for MZ)
|
|
483
|
+
if (this.currentWindow) {
|
|
484
|
+
this.currentWindow.reinitializePresentationWindowRuleEngineState(newRulesDataStoreObj);
|
|
485
|
+
}
|
|
486
|
+
if (this.nextWindow) {
|
|
487
|
+
this.nextWindow.reinitializePresentationWindowRuleEngineState(newRulesDataStoreObj);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return [2 /*return*/];
|
|
491
|
+
});
|
|
492
|
+
}); };
|
|
493
|
+
checkOverridePresentation();
|
|
494
|
+
};
|
|
433
495
|
// Replace state and rule engine, and reinitialize the window manager.
|
|
434
496
|
PlaylistWindowManager.prototype.reinitialize = function (state, ruleEngine, shouldInterruptPlayback) {
|
|
435
497
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -860,39 +922,19 @@ var PlaylistWindowManager = /** @class */ (function (_super) {
|
|
|
860
922
|
PlaylistWindowManager.prototype.startPreviewCheck = function () {
|
|
861
923
|
var _this = this;
|
|
862
924
|
var checkPreview = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
863
|
-
var
|
|
925
|
+
var now, nextMinute, timeUntilNextMinute;
|
|
864
926
|
return __generator(this, function (_a) {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
logger = this.options.logger;
|
|
868
|
-
if (!this.ruleEngine) return [3 /*break*/, 4];
|
|
869
|
-
preview = this.ruleEngine.previewNext();
|
|
870
|
-
if (!this.shouldPreload(preview.presentationId)) return [3 /*break*/, 3];
|
|
871
|
-
logger.info("Preview check replacing preloaded presentation '" + this.nextPresentationId() + "' with new presentation '" + preview.presentationId + "'");
|
|
872
|
-
return [4 /*yield*/, this.removeNextWindow()];
|
|
873
|
-
case 1:
|
|
874
|
-
_a.sent();
|
|
875
|
-
this.nextPresentation = preview;
|
|
876
|
-
return [4 /*yield*/, this.preloadNextWindow()];
|
|
877
|
-
case 2:
|
|
878
|
-
_a.sent();
|
|
879
|
-
_a.label = 3;
|
|
880
|
-
case 3:
|
|
881
|
-
if (preview.shouldInterrupt) {
|
|
882
|
-
logger.info("Interrupting current presentation with '" + preview.presentationId + "'");
|
|
883
|
-
this.registerInterrupt();
|
|
884
|
-
}
|
|
885
|
-
_a.label = 4;
|
|
886
|
-
case 4:
|
|
887
|
-
now = new Date();
|
|
888
|
-
nextMinute = new Date();
|
|
889
|
-
nextMinute.setMilliseconds(0);
|
|
890
|
-
nextMinute.setSeconds(1);
|
|
891
|
-
nextMinute.setMinutes(now.getMinutes() + 1);
|
|
892
|
-
timeUntilNextMinute = +nextMinute - +now;
|
|
893
|
-
this.interruptCheckTimeout = setTimeout(checkPreview, timeUntilNextMinute);
|
|
894
|
-
return [2 /*return*/];
|
|
927
|
+
if (this.ruleEngine) {
|
|
928
|
+
this.checkPreviewAction();
|
|
895
929
|
}
|
|
930
|
+
now = new Date();
|
|
931
|
+
nextMinute = new Date();
|
|
932
|
+
nextMinute.setMilliseconds(0);
|
|
933
|
+
nextMinute.setSeconds(1);
|
|
934
|
+
nextMinute.setMinutes(now.getMinutes() + 1);
|
|
935
|
+
timeUntilNextMinute = +nextMinute - +now;
|
|
936
|
+
this.interruptCheckTimeout = setTimeout(checkPreview, timeUntilNextMinute);
|
|
937
|
+
return [2 /*return*/];
|
|
896
938
|
});
|
|
897
939
|
}); };
|
|
898
940
|
checkPreview();
|
|
@@ -60,6 +60,7 @@ export default class PresentationWindow {
|
|
|
60
60
|
show(isFocused?: boolean): void;
|
|
61
61
|
hide(): void;
|
|
62
62
|
remove(): Promise<void>;
|
|
63
|
+
reinitializePresentationWindowRuleEngineState(newRulesDataStoreObj: RE.RulesDataStore): void;
|
|
63
64
|
play(): void;
|
|
64
65
|
pause(): void;
|
|
65
66
|
resume(): void;
|
|
@@ -255,6 +255,12 @@ var PresentationWindow = /** @class */ (function () {
|
|
|
255
255
|
});
|
|
256
256
|
});
|
|
257
257
|
};
|
|
258
|
+
// Method to modify the rule engine state for the inner playlist windows (called from outer playlist window manager)
|
|
259
|
+
PresentationWindow.prototype.reinitializePresentationWindowRuleEngineState = function (newRulesDataStoreObj) {
|
|
260
|
+
Object.values(this.windowManagers).forEach(function (wm) {
|
|
261
|
+
wm.reinitializeRuleEngineState(newRulesDataStoreObj);
|
|
262
|
+
});
|
|
263
|
+
};
|
|
258
264
|
PresentationWindow.prototype.play = function () {
|
|
259
265
|
var _this = this;
|
|
260
266
|
var _a = this.options, applicationVersion = _a.applicationVersion, presentation = _a.presentation;
|
package/build/embeddedApps.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
function createEmbeddedApp(presentation, applicationVersion) {
|
|
4
4
|
// build matches
|
|
5
|
-
var parameterRegex = /(:([\w]+))(.?$|[^\w])/gm;
|
|
5
|
+
var parameterRegex = /(:([\w-]+))(.?$|[^\w-])/gm;
|
|
6
6
|
var matches = [];
|
|
7
7
|
var match = null;
|
|
8
8
|
do {
|
|
@@ -43,6 +43,11 @@ test('Replaces variable with underscore', function () {
|
|
|
43
43
|
embeddedUrlFormat: 'https://example.com/:foo_1'
|
|
44
44
|
}))).toBe('https://example.com/bar');
|
|
45
45
|
});
|
|
46
|
+
test('Replaces variable with hyphen', function () {
|
|
47
|
+
expect(embeddedApps_1.default(createPresentation({ applicationVariables: { 'foo-1': 'bar' } }), createApplicationVersion({
|
|
48
|
+
embeddedUrlFormat: 'https://example.com/:foo-1'
|
|
49
|
+
}))).toBe('https://example.com/bar');
|
|
50
|
+
});
|
|
46
51
|
test('Does not replace variable that is a number', function () {
|
|
47
52
|
expect(embeddedApps_1.default(createPresentation({ applicationVariables: { foo: 'bar' } }), createApplicationVersion({
|
|
48
53
|
embeddedUrlFormat: 'http://localhost:8080?foo=:foo'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raydiant/playlist-window-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Window manager for playlist playback.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"fast-deep-equal": "^3.1.3",
|
|
15
|
-
"@raydiant/playlist-rule-engine": "3.
|
|
15
|
+
"@raydiant/playlist-rule-engine": "3.2.0",
|
|
16
16
|
"raydiant-kit": "4.7.3",
|
|
17
17
|
"uuid": "^8.3.0",
|
|
18
18
|
"eventemitter3": "^4.0.7"
|
|
@@ -265,6 +265,43 @@ export default class PlaylistWindowManager extends EventEmitter {
|
|
|
265
265
|
this.state = state;
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
// For setting dynamic tags data from workers and reevaluate rules for playlists
|
|
269
|
+
// input: newRulesDataStoreObj: {'workers': {'ai': {'percentMales': 30}}}
|
|
270
|
+
public reinitializeRuleEngineState(newRulesDataStoreObj: RE.RulesDataStore) {
|
|
271
|
+
const { logger } = this.options;
|
|
272
|
+
|
|
273
|
+
logger.info('Dynamic Rule engine state change event received!');
|
|
274
|
+
if (this.ruleEngine) {
|
|
275
|
+
logger.info(`Existing Rule Data Store: `, this.ruleEngine.state);
|
|
276
|
+
logger.info(`New Rule Data Store data received: `, newRulesDataStoreObj);
|
|
277
|
+
this.ruleEngine.state.rulesDataStore = newRulesDataStoreObj;
|
|
278
|
+
} else {
|
|
279
|
+
logger.warn(`No Rule engine found for reinitiazling the state!`);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// re-evaluate the next presentations depending upon the new rule engine state
|
|
284
|
+
const checkOverridePresentation = async () => {
|
|
285
|
+
if (this.ruleEngine) {
|
|
286
|
+
this.checkPreviewAction();
|
|
287
|
+
|
|
288
|
+
// calling reinitialize Rule engine state for inner playlist windows (for MZ)
|
|
289
|
+
if (this.currentWindow) {
|
|
290
|
+
this.currentWindow.reinitializePresentationWindowRuleEngineState(
|
|
291
|
+
newRulesDataStoreObj
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (this.nextWindow) {
|
|
296
|
+
this.nextWindow.reinitializePresentationWindowRuleEngineState(
|
|
297
|
+
newRulesDataStoreObj
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
checkOverridePresentation();
|
|
303
|
+
}
|
|
304
|
+
|
|
268
305
|
// Replace state and rule engine, and reinitialize the window manager.
|
|
269
306
|
public async reinitialize(
|
|
270
307
|
state: PlaylistWindowManagerState,
|
|
@@ -854,30 +891,36 @@ export default class PlaylistWindowManager extends EventEmitter {
|
|
|
854
891
|
}
|
|
855
892
|
};
|
|
856
893
|
|
|
857
|
-
private
|
|
858
|
-
const
|
|
859
|
-
|
|
894
|
+
private checkPreviewAction = async () => {
|
|
895
|
+
const { logger } = this.options;
|
|
896
|
+
if (!this.ruleEngine) {
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
const preview = this.ruleEngine.previewNext();
|
|
860
900
|
|
|
861
|
-
|
|
862
|
-
|
|
901
|
+
if (this.shouldPreload(preview.presentationId)) {
|
|
902
|
+
logger.info(
|
|
903
|
+
`Preview check replacing preloaded presentation '${this.nextPresentationId()}' with new presentation '${
|
|
904
|
+
preview.presentationId
|
|
905
|
+
}'`
|
|
906
|
+
);
|
|
907
|
+
await this.removeNextWindow();
|
|
908
|
+
this.nextPresentation = preview;
|
|
909
|
+
await this.preloadNextWindow();
|
|
910
|
+
}
|
|
863
911
|
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
this.nextPresentation = preview;
|
|
872
|
-
await this.preloadNextWindow();
|
|
873
|
-
}
|
|
912
|
+
if (preview.shouldInterrupt) {
|
|
913
|
+
logger.info(
|
|
914
|
+
`Interrupting current presentation with '${preview.presentationId}'`
|
|
915
|
+
);
|
|
916
|
+
this.registerInterrupt();
|
|
917
|
+
}
|
|
918
|
+
};
|
|
874
919
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
this.registerInterrupt();
|
|
880
|
-
}
|
|
920
|
+
private startPreviewCheck() {
|
|
921
|
+
const checkPreview = async () => {
|
|
922
|
+
if (this.ruleEngine) {
|
|
923
|
+
this.checkPreviewAction();
|
|
881
924
|
}
|
|
882
925
|
|
|
883
926
|
// Check the preview again on the next minute.
|
|
@@ -180,6 +180,15 @@ export default class PresentationWindow {
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
// Method to modify the rule engine state for the inner playlist windows (called from outer playlist window manager)
|
|
184
|
+
public reinitializePresentationWindowRuleEngineState(
|
|
185
|
+
newRulesDataStoreObj: RE.RulesDataStore
|
|
186
|
+
) {
|
|
187
|
+
Object.values(this.windowManagers).forEach(wm => {
|
|
188
|
+
wm.reinitializeRuleEngineState(newRulesDataStoreObj);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
183
192
|
public play(): void {
|
|
184
193
|
const { applicationVersion, presentation } = this.options;
|
|
185
194
|
|
package/src/embeddedApps.test.ts
CHANGED
|
@@ -77,6 +77,17 @@ test('Replaces variable with underscore', () => {
|
|
|
77
77
|
).toBe('https://example.com/bar');
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
test('Replaces variable with hyphen', () => {
|
|
81
|
+
expect(
|
|
82
|
+
createEmbeddedApp(
|
|
83
|
+
createPresentation({ applicationVariables: { 'foo-1': 'bar' } }),
|
|
84
|
+
createApplicationVersion({
|
|
85
|
+
embeddedUrlFormat: 'https://example.com/:foo-1'
|
|
86
|
+
})
|
|
87
|
+
)
|
|
88
|
+
).toBe('https://example.com/bar');
|
|
89
|
+
});
|
|
90
|
+
|
|
80
91
|
test('Does not replace variable that is a number', () => {
|
|
81
92
|
expect(
|
|
82
93
|
createEmbeddedApp(
|
package/src/embeddedApps.ts
CHANGED