@raydiant/playlist-window-manager 0.17.0 → 0.18.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/IFrameRenderer.js
CHANGED
|
@@ -35,34 +35,28 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
var messagePrefix = 'raydiant:';
|
|
38
39
|
var IFrameRenderer = /** @class */ (function () {
|
|
39
40
|
function IFrameRenderer(container) {
|
|
40
41
|
var _this = this;
|
|
41
42
|
this.container = container;
|
|
42
43
|
this.windows = {};
|
|
43
44
|
this.globalMessageHandler = function (event) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
var window = _this.getWindow(windowId);
|
|
61
|
-
if (!window) {
|
|
62
|
-
throw new Error("Failed add receive message callback to window, window with window id: '" + windowId + "' was not found");
|
|
63
|
-
}
|
|
64
|
-
if (window.receiveMessageCallback) {
|
|
65
|
-
window.receiveMessageCallback(type, payload);
|
|
45
|
+
// Ignore messages that don't start with the message prefix.
|
|
46
|
+
if (typeof event.data === 'string' &&
|
|
47
|
+
event.data.startsWith(messagePrefix)) {
|
|
48
|
+
var _a = _this.deserializeMessage(event.data), windowId = _a.windowId, type = _a.type, payload = _a.payload;
|
|
49
|
+
if (!windowId || !type) {
|
|
50
|
+
console.warn("Invalid message received from child window '" + event.data + "'");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
var window_1 = _this.getWindow(windowId);
|
|
54
|
+
if (!window_1) {
|
|
55
|
+
throw new Error("Failed add receive message callback to window, window with window id: '" + windowId + "' was not found");
|
|
56
|
+
}
|
|
57
|
+
if (window_1.receiveMessageCallback) {
|
|
58
|
+
window_1.receiveMessageCallback(type, payload);
|
|
59
|
+
}
|
|
66
60
|
}
|
|
67
61
|
};
|
|
68
62
|
// Post message is a single channel for all window so we need to
|
|
@@ -178,7 +172,7 @@ var IFrameRenderer = /** @class */ (function () {
|
|
|
178
172
|
if (!window.frame.contentWindow) {
|
|
179
173
|
throw new Error("Failed to send message '" + message + "', contentWindow missing for '" + windowId + "'");
|
|
180
174
|
}
|
|
181
|
-
window.frame.contentWindow.postMessage(message, '*');
|
|
175
|
+
window.frame.contentWindow.postMessage("" + messagePrefix + message, '*');
|
|
182
176
|
};
|
|
183
177
|
IFrameRenderer.prototype.muteWindow = function (windowId) {
|
|
184
178
|
var window = this.getWindow(windowId);
|
|
@@ -202,6 +196,21 @@ var IFrameRenderer = /** @class */ (function () {
|
|
|
202
196
|
IFrameRenderer.prototype.getWindow = function (windowId) {
|
|
203
197
|
return this.windows[windowId];
|
|
204
198
|
};
|
|
199
|
+
IFrameRenderer.prototype.deserializeMessage = function (message) {
|
|
200
|
+
var _a;
|
|
201
|
+
var windowId = '';
|
|
202
|
+
var type = '';
|
|
203
|
+
var payload;
|
|
204
|
+
var json = message.substring(messagePrefix.length);
|
|
205
|
+
try {
|
|
206
|
+
// Messages are sent as json in the format of { type: string, payload: unknown }.
|
|
207
|
+
(_a = JSON.parse(json), windowId = _a.windowId, type = _a.type, payload = _a.payload);
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
// Not a valid message, return empty type and payload.
|
|
211
|
+
}
|
|
212
|
+
return { windowId: windowId, type: type, payload: payload };
|
|
213
|
+
};
|
|
205
214
|
return IFrameRenderer;
|
|
206
215
|
}());
|
|
207
216
|
exports.default = IFrameRenderer;
|
|
@@ -63,7 +63,7 @@ var PlaylistWindowManager_1 = __importDefault(require("./PlaylistWindowManager")
|
|
|
63
63
|
var WindowTimeoutError_1 = __importDefault(require("./WindowTimeoutError"));
|
|
64
64
|
var WindowLoadError_1 = __importDefault(require("./WindowLoadError"));
|
|
65
65
|
// TODO: Automatically inject latest version when building in CI.
|
|
66
|
-
var defaultAppRendererUrl = 'https://apps.raydiant.com/
|
|
66
|
+
var defaultAppRendererUrl = 'https://apps.raydiant.com/3.0.0/index.html';
|
|
67
67
|
var isValidNumber = function (value) {
|
|
68
68
|
return typeof value === 'number' && !isNaN(value);
|
|
69
69
|
};
|
package/package.json
CHANGED
package/src/IFrameRenderer.ts
CHANGED
|
@@ -9,6 +9,8 @@ interface IFrameRendererWindow {
|
|
|
9
9
|
receiveMessageCallback?: (type: string, payload?: any) => void;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
const messagePrefix = 'raydiant:';
|
|
13
|
+
|
|
12
14
|
export default class IFrameRenderer implements PresentationWindowRenderer {
|
|
13
15
|
private windows: {
|
|
14
16
|
[windowId: string]: IFrameRendererWindow;
|
|
@@ -153,7 +155,7 @@ export default class IFrameRenderer implements PresentationWindowRenderer {
|
|
|
153
155
|
);
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
window.frame.contentWindow.postMessage(message
|
|
158
|
+
window.frame.contentWindow.postMessage(`${messagePrefix}${message}`, '*');
|
|
157
159
|
}
|
|
158
160
|
|
|
159
161
|
public muteWindow(windowId: string) {
|
|
@@ -187,36 +189,46 @@ export default class IFrameRenderer implements PresentationWindowRenderer {
|
|
|
187
189
|
}
|
|
188
190
|
|
|
189
191
|
private globalMessageHandler = (event: MessageEvent) => {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
event.data
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
|
|
192
|
+
// Ignore messages that don't start with the message prefix.
|
|
193
|
+
if (
|
|
194
|
+
typeof event.data === 'string' &&
|
|
195
|
+
event.data.startsWith(messagePrefix)
|
|
196
|
+
) {
|
|
197
|
+
const { windowId, type, payload } = this.deserializeMessage(event.data);
|
|
198
|
+
|
|
199
|
+
if (!windowId || !type) {
|
|
200
|
+
console.warn(
|
|
201
|
+
`Invalid message received from child window '${event.data}'`
|
|
202
|
+
);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const window = this.getWindow(windowId);
|
|
207
|
+
if (!window) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`Failed add receive message callback to window, window with window id: '${windowId}' was not found`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (window.receiveMessageCallback) {
|
|
214
|
+
window.receiveMessageCallback(type, payload);
|
|
215
|
+
}
|
|
203
216
|
}
|
|
217
|
+
};
|
|
204
218
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
219
|
+
private deserializeMessage(message: string) {
|
|
220
|
+
let windowId = '';
|
|
221
|
+
let type = '';
|
|
222
|
+
let payload: unknown;
|
|
210
223
|
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
224
|
+
const json = message.substring(messagePrefix.length);
|
|
225
|
+
try {
|
|
226
|
+
// Messages are sent as json in the format of { type: string, payload: unknown }.
|
|
227
|
+
({ windowId, type, payload } = JSON.parse(json));
|
|
228
|
+
} catch (err) {
|
|
229
|
+
// Not a valid message, return empty type and payload.
|
|
216
230
|
}
|
|
217
231
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
};
|
|
232
|
+
return { windowId, type, payload };
|
|
233
|
+
}
|
|
222
234
|
}
|
|
@@ -51,7 +51,7 @@ export interface PresentationWindowOptions {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// TODO: Automatically inject latest version when building in CI.
|
|
54
|
-
const defaultAppRendererUrl = 'https://apps.raydiant.com/
|
|
54
|
+
const defaultAppRendererUrl = 'https://apps.raydiant.com/3.0.0/index.html';
|
|
55
55
|
|
|
56
56
|
const isValidNumber = (value: any) =>
|
|
57
57
|
typeof value === 'number' && !isNaN(value);
|