@raydiant/playlist-window-manager 0.20.0 → 0.21.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.
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
4
5
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
6
  function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
@@ -13,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
13
14
  function verb(n) { return function (v) { return step([n, v]); }; }
14
15
  function step(op) {
15
16
  if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
19
  if (y = 0, t) op = [op[0] & 2, t.value];
19
20
  switch (op[0]) {
@@ -35,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
36
  }
36
37
  };
37
38
  Object.defineProperty(exports, "__esModule", { value: true });
38
- var messagePrefix = 'raydiant:';
39
+ var namespace = 'raydiant';
39
40
  var IFrameRenderer = /** @class */ (function () {
40
41
  function IFrameRenderer(container) {
41
42
  var _this = this;
@@ -43,16 +44,15 @@ var IFrameRenderer = /** @class */ (function () {
43
44
  this.windows = {};
44
45
  this.globalMessageHandler = function (event) {
45
46
  // Ignore messages that don't start with the message prefix.
46
- if (typeof event.data === 'string' &&
47
- event.data.startsWith(messagePrefix)) {
47
+ if (typeof event.data === 'string' && event.data.startsWith(namespace)) {
48
48
  var _a = _this.deserializeMessage(event.data), windowId = _a.windowId, type = _a.type, payload = _a.payload;
49
49
  if (!windowId || !type) {
50
- console.warn("Invalid message received from child window '" + event.data + "'");
50
+ console.warn("Invalid message received from child window '".concat(event.data, "'"));
51
51
  return;
52
52
  }
53
53
  var window_1 = _this.getWindow(windowId);
54
54
  if (!window_1) {
55
- throw new Error("Failed add receive message callback to window, window with window id: '" + windowId + "' was not found");
55
+ throw new Error("Failed add receive message callback to window, window with window id: '".concat(windowId, "' was not found"));
56
56
  }
57
57
  if (window_1.receiveMessageCallback) {
58
58
  window_1.receiveMessageCallback(type, payload);
@@ -82,10 +82,10 @@ var IFrameRenderer = /** @class */ (function () {
82
82
  frame.style.border = 'none';
83
83
  // Position will be 0,0 for the main window.
84
84
  if (bounds) {
85
- frame.style.top = bounds.y + "px";
86
- frame.style.left = bounds.x + "px";
87
- frame.style.width = bounds.width + "px";
88
- frame.style.height = bounds.height + "px";
85
+ frame.style.top = "".concat(bounds.y, "px");
86
+ frame.style.left = "".concat(bounds.x, "px");
87
+ frame.style.width = "".concat(bounds.width, "px");
88
+ frame.style.height = "".concat(bounds.height, "px");
89
89
  }
90
90
  else {
91
91
  // If bounds assume fullscreen.
@@ -108,7 +108,7 @@ var IFrameRenderer = /** @class */ (function () {
108
108
  IFrameRenderer.prototype.loadWindow = function (windowId, url) {
109
109
  var window = this.getWindow(windowId);
110
110
  if (!window) {
111
- throw new Error("Failed to update window bounds, missing window id '" + windowId + "'");
111
+ throw new Error("Failed to update window bounds, missing window id '".concat(windowId, "'"));
112
112
  }
113
113
  // Return a promise that resolves then the window has successfully loaded.
114
114
  return new Promise(function (resolve, reject) {
@@ -116,7 +116,7 @@ var IFrameRenderer = /** @class */ (function () {
116
116
  resolve();
117
117
  };
118
118
  window.frame.onerror = function () {
119
- reject(new Error("Error loading window for '" + url + "'"));
119
+ reject(new Error("Error loading window for '".concat(url, "'")));
120
120
  };
121
121
  window.frame.src = url;
122
122
  });
@@ -124,17 +124,17 @@ var IFrameRenderer = /** @class */ (function () {
124
124
  IFrameRenderer.prototype.updateWindowBounds = function (windowId, bounds) {
125
125
  var window = this.getWindow(windowId);
126
126
  if (!window) {
127
- throw new Error("Failed to update window bounds, missing window id '" + windowId + "'");
127
+ throw new Error("Failed to update window bounds, missing window id '".concat(windowId, "'"));
128
128
  }
129
- window.frame.style.top = bounds.y + "px";
130
- window.frame.style.left = bounds.x + "px";
131
- window.frame.style.width = bounds.width + "px";
132
- window.frame.style.height = bounds.height + "px";
129
+ window.frame.style.top = "".concat(bounds.y, "px");
130
+ window.frame.style.left = "".concat(bounds.x, "px");
131
+ window.frame.style.width = "".concat(bounds.width, "px");
132
+ window.frame.style.height = "".concat(bounds.height, "px");
133
133
  };
134
134
  IFrameRenderer.prototype.showWindow = function (windowId, isFocused) {
135
135
  var window = this.getWindow(windowId);
136
136
  if (!window) {
137
- throw new Error("Failed to show window, missing window id '" + windowId + "'");
137
+ throw new Error("Failed to show window, missing window id '".concat(windowId, "'"));
138
138
  }
139
139
  window.frame.style.zIndex = '9999';
140
140
  window.frame.style.visibility = 'visible';
@@ -145,7 +145,7 @@ var IFrameRenderer = /** @class */ (function () {
145
145
  IFrameRenderer.prototype.hideWindow = function (windowId) {
146
146
  var window = this.getWindow(windowId);
147
147
  if (!window) {
148
- throw new Error("Failed to hide window, missing window id '" + windowId + "'");
148
+ throw new Error("Failed to hide window, missing window id '".concat(windowId, "'"));
149
149
  }
150
150
  window.frame.style.zIndex = '0';
151
151
  window.frame.style.visibility = 'hidden';
@@ -156,7 +156,7 @@ var IFrameRenderer = /** @class */ (function () {
156
156
  return __generator(this, function (_a) {
157
157
  window = this.getWindow(windowId);
158
158
  if (!window) {
159
- throw new Error("Failed to remove window, missing window id '" + windowId + "'");
159
+ throw new Error("Failed to remove window, missing window id '".concat(windowId, "'"));
160
160
  }
161
161
  this.container.removeChild(window.frame);
162
162
  delete this.windows[windowId];
@@ -164,20 +164,30 @@ var IFrameRenderer = /** @class */ (function () {
164
164
  });
165
165
  });
166
166
  };
167
- IFrameRenderer.prototype.sendMessage = function (windowId, message) {
167
+ IFrameRenderer.prototype.sendMessageString = function (windowId, message) {
168
168
  var window = this.getWindow(windowId);
169
169
  if (!window) {
170
- throw new Error("Failed to send message '" + message + "', missing window id '" + windowId + "'");
170
+ throw new Error("Failed to send message '".concat(message, "', missing window id '").concat(windowId, "'"));
171
171
  }
172
172
  if (!window.frame.contentWindow) {
173
- throw new Error("Failed to send message '" + message + "', contentWindow missing for '" + windowId + "'");
173
+ throw new Error("Failed to send message '".concat(message, "', contentWindow missing for '").concat(windowId, "'"));
174
174
  }
175
- window.frame.contentWindow.postMessage("" + messagePrefix + message, '*');
175
+ window.frame.contentWindow.postMessage("".concat(namespace, ":").concat(message), '*');
176
+ };
177
+ IFrameRenderer.prototype.sendMessageObject = function (windowId, type, payload) {
178
+ var window = this.getWindow(windowId);
179
+ if (!window) {
180
+ throw new Error("Failed to send message '".concat(type, "', missing window id '").concat(windowId, "'"));
181
+ }
182
+ if (!window.frame.contentWindow) {
183
+ throw new Error("Failed to send message '".concat(type, "', contentWindow missing for '").concat(windowId, "'"));
184
+ }
185
+ window.frame.contentWindow.postMessage({ namespace: namespace, windowId: windowId, type: type, payload: payload }, '*');
176
186
  };
177
187
  IFrameRenderer.prototype.muteWindow = function (windowId) {
178
188
  var window = this.getWindow(windowId);
179
189
  if (!window) {
180
- throw new Error("Failed to mute window, missing window id '" + windowId + "'");
190
+ throw new Error("Failed to mute window, missing window id '".concat(windowId, "'"));
181
191
  }
182
192
  // There is no mute/unmute API for iframes so we rely on the window manager overriding any
183
193
  // mute presentation properties.
@@ -185,7 +195,7 @@ var IFrameRenderer = /** @class */ (function () {
185
195
  IFrameRenderer.prototype.unMuteWindow = function (windowId) {
186
196
  var window = this.getWindow(windowId);
187
197
  if (!window) {
188
- throw new Error("Failed to unmute window, missing window id '" + windowId + "'");
198
+ throw new Error("Failed to unmute window, missing window id '".concat(windowId, "'"));
189
199
  }
190
200
  // There is no mute/unmute API for iframes so we rely on the window manager overriding any
191
201
  // mute presentation properties.
@@ -201,7 +211,7 @@ var IFrameRenderer = /** @class */ (function () {
201
211
  var windowId = '';
202
212
  var type = '';
203
213
  var payload;
204
- var json = message.substring(messagePrefix.length);
214
+ var json = message.replace('raydiant:', '');
205
215
  try {
206
216
  // Messages are sent as json in the format of { type: string, payload: unknown }.
207
217
  (_a = JSON.parse(json), windowId = _a.windowId, type = _a.type, payload = _a.payload);
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -24,10 +26,11 @@ var __assign = (this && this.__assign) || function () {
24
26
  return __assign.apply(this, arguments);
25
27
  };
26
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
30
  return new (P || (P = Promise))(function (resolve, reject) {
28
31
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
32
  function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
34
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
35
  });
33
36
  };
@@ -37,7 +40,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
40
  function verb(n) { return function (v) { return step([n, v]); }; }
38
41
  function step(op) {
39
42
  if (f) throw new TypeError("Generator is already executing.");
40
- while (_) try {
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
44
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
45
  if (y = 0, t) op = [op[0] & 2, t.value];
43
46
  switch (op[0]) {
@@ -130,7 +133,7 @@ var PlaylistWindowManager = /** @class */ (function (_super) {
130
133
  // Throttle presentation complete handler if we have not throttled already.
131
134
  if (this.currentPresentationCompleteTimeout === null) {
132
135
  delay = minTimeBetweenCompletes - timeSinceLastComplete + 1;
133
- logger.warn("Throttling presentation complete handler for " + delay + "ms because it was called again in less than " + minTimeBetweenCompletes + "ms");
136
+ logger.warn("Throttling presentation complete handler for ".concat(delay, "ms because it was called again in less than ").concat(minTimeBetweenCompletes, "ms"));
134
137
  this.currentPresentationCompleteTimeout = setTimeout(function () {
135
138
  _this.currentPresentationCompleteTimeout = null;
136
139
  _this.handleCurrentPresentationComplete();
@@ -287,7 +290,7 @@ var PlaylistWindowManager = /** @class */ (function (_super) {
287
290
  }
288
291
  preview = this.ruleEngine.previewNext();
289
292
  if (!this.shouldPreload(preview.presentationId)) return [3 /*break*/, 3];
290
- logger.info("Preview check replacing preloaded presentation '" + this.nextPresentationId() + "' with new presentation '" + preview.presentationId + "'");
293
+ logger.info("Preview check replacing preloaded presentation '".concat(this.nextPresentationId(), "' with new presentation '").concat(preview.presentationId, "'"));
291
294
  return [4 /*yield*/, this.removeNextWindow()];
292
295
  case 1:
293
296
  _a.sent();
@@ -298,7 +301,7 @@ var PlaylistWindowManager = /** @class */ (function (_super) {
298
301
  _a.label = 3;
299
302
  case 3:
300
303
  if (preview.shouldInterrupt) {
301
- logger.info("Interrupting current presentation with '" + preview.presentationId + "'");
304
+ logger.info("Interrupting current presentation with '".concat(preview.presentationId, "'"));
302
305
  this.registerInterrupt();
303
306
  }
304
307
  return [2 /*return*/];
@@ -472,7 +475,7 @@ var PlaylistWindowManager = /** @class */ (function (_super) {
472
475
  var logger = this.options.logger;
473
476
  logger.debug('Dynamic Rule engine state change event received!');
474
477
  if (this.ruleEngine) {
475
- logger.debug("OLD Rule Data Store: " + JSON.stringify(this.ruleEngine.state) + " \n NEW Rule Data Store: " + JSON.stringify(newRulesDataStoreObj));
478
+ logger.debug("OLD Rule Data Store: ".concat(JSON.stringify(this.ruleEngine.state), " \n NEW Rule Data Store: ").concat(JSON.stringify(newRulesDataStoreObj)));
476
479
  this.ruleEngine.state.rulesDataStore = newRulesDataStoreObj;
477
480
  }
478
481
  else {
@@ -654,7 +657,7 @@ var PlaylistWindowManager = /** @class */ (function (_super) {
654
657
  }
655
658
  var presentation = this.state.getPresentation(presentationId);
656
659
  var applicationVersion = this.state.getApplicationVersion(presentation.applicationDeploymentId);
657
- var windowId = uuid_1.v4();
660
+ var windowId = (0, uuid_1.v4)();
658
661
  return new PresentationWindow_1.default({
659
662
  windowManager: this,
660
663
  renderer: this.renderer,
@@ -935,7 +938,7 @@ var PlaylistWindowManager = /** @class */ (function (_super) {
935
938
  warnIfPreloadMismatch) {
936
939
  // TODO: Handle the case when the next presentation isn't the preloaded window.
937
940
  // This can happen when we support dynamic rule engine state.
938
- logger.warn("The next presentation id '" + nextPresentationId + "' doesnt match preloaded presentation id '" + this.nextPresentationId() + "'");
941
+ logger.warn("The next presentation id '".concat(nextPresentationId, "' doesnt match preloaded presentation id '").concat(this.nextPresentationId(), "'"));
939
942
  }
940
943
  return { next: next, preview: preview };
941
944
  };
@@ -980,10 +983,10 @@ var PlaylistWindowManager = /** @class */ (function (_super) {
980
983
  PlaylistWindowManager.prototype.emitWindowEvent = function (label, event, window, data) {
981
984
  var logger = this.options.logger;
982
985
  if (window) {
983
- this.emit(event, __assign({}, window.metadata(), { data: data }));
986
+ this.emit(event, __assign(__assign({}, window.metadata()), { data: data }));
984
987
  }
985
988
  else {
986
- logger.warn("Attempted to emit " + label + " window event but window not set");
989
+ logger.warn("Attempted to emit ".concat(label, " window event but window not set"));
987
990
  }
988
991
  };
989
992
  PlaylistWindowManager.prototype.emitCurrentWindowEvent = function (event, data) {
@@ -25,7 +25,7 @@ var PlaylistWindowManagerState = /** @class */ (function () {
25
25
  PlaylistWindowManagerState.prototype.getPresentation = function (presentationId) {
26
26
  var presentation = this.options.presentations[presentationId];
27
27
  if (!presentation) {
28
- throw new Error("Failed to create window, missing presentation for '" + presentationId + "'");
28
+ throw new Error("Failed to create window, missing presentation for '".concat(presentationId, "'"));
29
29
  }
30
30
  return presentation;
31
31
  };
@@ -35,7 +35,7 @@ var PlaylistWindowManagerState = /** @class */ (function () {
35
35
  PlaylistWindowManagerState.prototype.getApplicationVersion = function (applicationVersionId) {
36
36
  var applicationVersion = this.options.applicationVersions[applicationVersionId];
37
37
  if (!applicationVersion) {
38
- throw new Error("Failed to create window, missing application version for " + applicationVersionId);
38
+ throw new Error("Failed to create window, missing application version for ".concat(applicationVersionId));
39
39
  }
40
40
  return applicationVersion;
41
41
  };
@@ -45,7 +45,7 @@ var PlaylistWindowManagerState = /** @class */ (function () {
45
45
  PlaylistWindowManagerState.prototype.getTheme = function (themeId) {
46
46
  var theme = this.options.themes[themeId];
47
47
  if (!theme) {
48
- throw new Error("Failed to create window, missing theme for '" + themeId + "'");
48
+ throw new Error("Failed to create window, missing theme for '".concat(themeId, "'"));
49
49
  }
50
50
  return theme;
51
51
  };
@@ -60,6 +60,10 @@ export default class PresentationWindow {
60
60
  private workerState;
61
61
  private workerSubscriptions;
62
62
  private runtimeSubscriptions;
63
+ private previewSubscriptions;
64
+ private previewState;
65
+ private createObjectURLResolvers;
66
+ private createObjectURLTimeouts;
63
67
  constructor(options: PresentationWindowOptions);
64
68
  load(): Promise<void>;
65
69
  show(isFocused?: boolean): void;
@@ -87,6 +91,7 @@ export default class PresentationWindow {
87
91
  setForceMute(forceMute: boolean): void;
88
92
  reload(): Promise<void>;
89
93
  runGetProperties(builderState?: BuilderState): void;
94
+ createObjectURL(blob: Blob): Promise<string>;
90
95
  private isEmbeddedApp;
91
96
  private allChildWindowManagersReady;
92
97
  private checkIsReadyCallback;
@@ -95,7 +100,8 @@ export default class PresentationWindow {
95
100
  private loadLegacyApp;
96
101
  private createAndLoadWindow;
97
102
  private loadWindow;
98
- private sendMessage;
103
+ private sendMessageString;
104
+ private sendMessageObject;
99
105
  private waitForPesentationReady;
100
106
  private buildTheme;
101
107
  private sendRenderMessage;
@@ -126,10 +132,11 @@ export default class PresentationWindow {
126
132
  publishedAt: string;
127
133
  playlistId: string | undefined;
128
134
  playlistName: string | undefined;
129
- rule: RE.RuleOperatorType | RE.RuleGroupType | RE.RuleScheduleType | null | undefined;
135
+ rule: RE.Rule | null | undefined;
130
136
  };
131
137
  runWorkerSubscriptions(state: WorkerState): void;
132
138
  private createRuleEngine;
133
139
  private isValidOpenChildWindowPayload;
134
140
  private shouldMute;
141
+ private createObjectURLForEmbeddedApp;
135
142
  }