@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.
- package/build/BrowserViewRenderer.d.ts +3 -2
- package/build/BrowserViewRenderer.js +47 -23
- package/build/BrowserWindowRenderer.d.ts +3 -2
- package/build/BrowserWindowRenderer.js +66 -42
- package/build/IFrameRenderer.d.ts +3 -2
- package/build/IFrameRenderer.js +38 -28
- package/build/PlaylistWindowManager.js +14 -11
- package/build/PlaylistWindowManagerState.js +3 -3
- package/build/PresentationWindow.d.ts +9 -2
- package/build/PresentationWindow.js +240 -85
- package/build/PresentationWindow.test.d.ts +1 -0
- package/build/PresentationWindow.test.js +241 -0
- package/build/WindowLoadError.js +3 -1
- package/build/WindowTimeoutError.js +3 -1
- package/build/WindowUnresponsiveError.js +3 -1
- package/build/embeddedApps.js +7 -0
- package/build/embeddedApps.test.js +42 -32
- package/build/index.js +19 -6
- package/build/testUtils.d.ts +43 -0
- package/build/testUtils.js +208 -0
- package/build/types.d.ts +7 -2
- package/package.json +2 -2
- package/src/BrowserViewRenderer.ts +18 -7
- package/src/BrowserWindowRenderer.ts +29 -17
- package/src/IFrameRenderer.ts +27 -10
- package/src/PresentationWindow.test.ts +221 -0
- package/src/PresentationWindow.ts +231 -58
- package/src/embeddedApps.test.ts +39 -20
- package/src/embeddedApps.ts +13 -4
- package/src/testUtils.ts +159 -0
- package/src/types.ts +14 -3
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
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
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.createRenderer = exports.createLogger = exports.createRuleEngineState = exports.createPlaylistWindowManagerState = exports.createApplicationVersion = exports.createPresentationRelationships = exports.createPresentation = exports.createPresentationWindow = void 0;
|
|
66
|
+
var re = __importStar(require("@raydiant/playlist-rule-engine"));
|
|
67
|
+
var PresentationWindow_1 = __importDefault(require("./PresentationWindow"));
|
|
68
|
+
var PlaylistWindowManagerState_1 = __importDefault(require("./PlaylistWindowManagerState"));
|
|
69
|
+
function createPresentationWindow(overrides) {
|
|
70
|
+
var _a, _b, _c, _d, _e, _f;
|
|
71
|
+
if (overrides === void 0) { overrides = {}; }
|
|
72
|
+
return new PresentationWindow_1.default({
|
|
73
|
+
windowId: (_a = overrides.windowId) !== null && _a !== void 0 ? _a : 'test',
|
|
74
|
+
presentation: createPresentation(overrides.presentation),
|
|
75
|
+
applicationVersion: createApplicationVersion(overrides.applicationVersion),
|
|
76
|
+
publishedAt: (_b = overrides.publishedAt) !== null && _b !== void 0 ? _b : 'publishedAt',
|
|
77
|
+
playlistWindowManagerState: (_c = overrides.playlistWindowManagerState) !== null && _c !== void 0 ? _c : createPlaylistWindowManagerState(),
|
|
78
|
+
ruleEngineState: (_d = overrides.ruleEngineState) !== null && _d !== void 0 ? _d : createRuleEngineState(),
|
|
79
|
+
logger: createLogger(),
|
|
80
|
+
workerState: (_e = overrides.workerState) !== null && _e !== void 0 ? _e : {},
|
|
81
|
+
renderer: (_f = overrides.renderer) !== null && _f !== void 0 ? _f : {
|
|
82
|
+
createWindow: function () { },
|
|
83
|
+
loadWindow: function () {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
85
|
+
return [2 /*return*/];
|
|
86
|
+
}); });
|
|
87
|
+
},
|
|
88
|
+
updateWindowBounds: function () { },
|
|
89
|
+
showWindow: function () { },
|
|
90
|
+
hideWindow: function () { },
|
|
91
|
+
removeWindow: function () {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
93
|
+
return [2 /*return*/];
|
|
94
|
+
}); });
|
|
95
|
+
},
|
|
96
|
+
sendMessageString: function () { },
|
|
97
|
+
sendMessageObject: function () { },
|
|
98
|
+
muteWindow: function () { },
|
|
99
|
+
unMuteWindow: function () { },
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
exports.createPresentationWindow = createPresentationWindow;
|
|
104
|
+
function createPresentation(overrides) {
|
|
105
|
+
var _a, _b, _c, _d, _e, _f;
|
|
106
|
+
if (overrides === void 0) { overrides = {}; }
|
|
107
|
+
return {
|
|
108
|
+
id: (_a = overrides.id) !== null && _a !== void 0 ? _a : 'id',
|
|
109
|
+
name: (_b = overrides.name) !== null && _b !== void 0 ? _b : 'name',
|
|
110
|
+
applicationDeploymentId: (_c = overrides.applicationDeploymentId) !== null && _c !== void 0 ? _c : 'applicationDeploymentId',
|
|
111
|
+
themeId: (_d = overrides.themeId) !== null && _d !== void 0 ? _d : null,
|
|
112
|
+
applicationVariables: (_e = overrides.applicationVariables) !== null && _e !== void 0 ? _e : {},
|
|
113
|
+
duration: (_f = overrides.duration) !== null && _f !== void 0 ? _f : 1,
|
|
114
|
+
r: createPresentationRelationships(overrides.r),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
exports.createPresentation = createPresentation;
|
|
118
|
+
function createPresentationRelationships(overrides) {
|
|
119
|
+
var _a, _b;
|
|
120
|
+
if (overrides === void 0) { overrides = {}; }
|
|
121
|
+
return {
|
|
122
|
+
resource: (_a = overrides.resource) !== null && _a !== void 0 ? _a : {
|
|
123
|
+
updatedAt: 'updatedAt',
|
|
124
|
+
createdAt: 'createdAt',
|
|
125
|
+
},
|
|
126
|
+
presentationsPlaylists: (_b = overrides.presentationsPlaylists) !== null && _b !== void 0 ? _b : [],
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
exports.createPresentationRelationships = createPresentationRelationships;
|
|
130
|
+
function createApplicationVersion(overrides) {
|
|
131
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
132
|
+
if (overrides === void 0) { overrides = {}; }
|
|
133
|
+
return {
|
|
134
|
+
id: (_a = overrides.id) !== null && _a !== void 0 ? _a : 'id',
|
|
135
|
+
name: (_b = overrides.name) !== null && _b !== void 0 ? _b : 'name',
|
|
136
|
+
applicationId: (_c = overrides.applicationId) !== null && _c !== void 0 ? _c : 'applicationId',
|
|
137
|
+
embeddedUrlFormat: (_d = overrides.embeddedUrlFormat) !== null && _d !== void 0 ? _d : null,
|
|
138
|
+
configurableDuration: (_e = overrides.configurableDuration) !== null && _e !== void 0 ? _e : false,
|
|
139
|
+
sourceUrl: (_f = overrides.sourceUrl) !== null && _f !== void 0 ? _f : null,
|
|
140
|
+
presentationProperties: (_g = overrides.presentationProperties) !== null && _g !== void 0 ? _g : [],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
exports.createApplicationVersion = createApplicationVersion;
|
|
144
|
+
function createPlaylistWindowManagerState(overrides) {
|
|
145
|
+
var _a, _b, _c, _d;
|
|
146
|
+
if (overrides === void 0) { overrides = {}; }
|
|
147
|
+
return new PlaylistWindowManagerState_1.default({
|
|
148
|
+
presentations: (_a = overrides.presentations) !== null && _a !== void 0 ? _a : {},
|
|
149
|
+
applicationVersions: (_b = overrides.applicationVersions) !== null && _b !== void 0 ? _b : {},
|
|
150
|
+
themes: (_c = overrides.themes) !== null && _c !== void 0 ? _c : {},
|
|
151
|
+
publishedAt: (_d = overrides.publishedAt) !== null && _d !== void 0 ? _d : 'publishedAt',
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
exports.createPlaylistWindowManagerState = createPlaylistWindowManagerState;
|
|
155
|
+
function createRuleEngineState(playlists, presentations, rulesDataStore, isMultitimezoneEnabled) {
|
|
156
|
+
if (playlists === void 0) { playlists = {}; }
|
|
157
|
+
if (presentations === void 0) { presentations = {}; }
|
|
158
|
+
if (rulesDataStore === void 0) { rulesDataStore = {}; }
|
|
159
|
+
if (isMultitimezoneEnabled === void 0) { isMultitimezoneEnabled = false; }
|
|
160
|
+
return new re.State(playlists, presentations, rulesDataStore, isMultitimezoneEnabled);
|
|
161
|
+
}
|
|
162
|
+
exports.createRuleEngineState = createRuleEngineState;
|
|
163
|
+
function createLogger(overrides) {
|
|
164
|
+
var _a, _b, _c, _d;
|
|
165
|
+
if (overrides === void 0) { overrides = {}; }
|
|
166
|
+
var noop = function () { };
|
|
167
|
+
return {
|
|
168
|
+
debug: (_a = overrides.debug) !== null && _a !== void 0 ? _a : noop,
|
|
169
|
+
info: (_b = overrides.info) !== null && _b !== void 0 ? _b : noop,
|
|
170
|
+
warn: (_c = overrides.warn) !== null && _c !== void 0 ? _c : noop,
|
|
171
|
+
error: (_d = overrides.error) !== null && _d !== void 0 ? _d : noop,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
exports.createLogger = createLogger;
|
|
175
|
+
function createRenderer() {
|
|
176
|
+
var createWindowOpts = null;
|
|
177
|
+
return {
|
|
178
|
+
createWindow: jest.fn(function (opts) {
|
|
179
|
+
createWindowOpts = opts;
|
|
180
|
+
}),
|
|
181
|
+
loadWindow: jest.fn(),
|
|
182
|
+
updateWindowBounds: jest.fn(),
|
|
183
|
+
showWindow: jest.fn(),
|
|
184
|
+
hideWindow: jest.fn(),
|
|
185
|
+
removeWindow: jest.fn(),
|
|
186
|
+
sendMessageString: jest.fn(),
|
|
187
|
+
sendMessageObject: jest.fn(),
|
|
188
|
+
muteWindow: jest.fn(),
|
|
189
|
+
unMuteWindow: jest.fn(),
|
|
190
|
+
runReceiveMessageCallback: function (type, payload) {
|
|
191
|
+
if (createWindowOpts === null || createWindowOpts === void 0 ? void 0 : createWindowOpts.receiveMessageCallback) {
|
|
192
|
+
createWindowOpts.receiveMessageCallback(type, payload);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
throw new Error('No receiveMessageCallback defined, make sure to call window.load first');
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
runErrorCallback: function (error) {
|
|
199
|
+
if (createWindowOpts === null || createWindowOpts === void 0 ? void 0 : createWindowOpts.errorCallback) {
|
|
200
|
+
createWindowOpts.errorCallback(error);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
throw new Error('No errorCallback defined, make sure to call window.load first');
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
exports.createRenderer = createRenderer;
|
package/build/types.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export interface ApplicationVersion {
|
|
|
29
29
|
sourceUrl: string | null;
|
|
30
30
|
presentationProperties: Array<{
|
|
31
31
|
name: string;
|
|
32
|
+
type: string;
|
|
32
33
|
encode?: boolean;
|
|
33
34
|
}>;
|
|
34
35
|
}
|
|
@@ -74,6 +75,9 @@ export interface WindowBounds {
|
|
|
74
75
|
export interface WorkerState {
|
|
75
76
|
[key: string]: any;
|
|
76
77
|
}
|
|
78
|
+
export interface PreviewState {
|
|
79
|
+
inputs: Record<string, any>;
|
|
80
|
+
}
|
|
77
81
|
export interface CreateWindowOptions {
|
|
78
82
|
windowId: string;
|
|
79
83
|
parentWindowId?: string;
|
|
@@ -103,7 +107,8 @@ export interface PresentationWindowRenderer {
|
|
|
103
107
|
showWindow(windowId: string, isFocused: boolean): void;
|
|
104
108
|
hideWindow(windowId: string): void;
|
|
105
109
|
removeWindow(windowId: string): Promise<void>;
|
|
106
|
-
|
|
110
|
+
sendMessageString(windowId: string, message: string): void;
|
|
111
|
+
sendMessageObject(windowId: string, type: string, payload?: any): void;
|
|
107
112
|
muteWindow(windowId: string): void;
|
|
108
113
|
unMuteWindow(windowId: string): void;
|
|
109
114
|
}
|
|
@@ -118,7 +123,7 @@ export interface OpenChildWindowOptions {
|
|
|
118
123
|
isMuted: boolean;
|
|
119
124
|
theme?: Theme;
|
|
120
125
|
}
|
|
121
|
-
export
|
|
126
|
+
export type Path = Array<string | number>;
|
|
122
127
|
export interface BuilderState {
|
|
123
128
|
inputs: InputState[];
|
|
124
129
|
profileId?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raydiant/playlist-window-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Window manager for playlist playback.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"electron": "10.1.5",
|
|
26
26
|
"jest": "^24.8.0",
|
|
27
27
|
"ts-jest": "^24.0.2",
|
|
28
|
-
"typescript": "^
|
|
28
|
+
"typescript": "^4.1.2"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -3,7 +3,7 @@ import { BrowserWindow, BrowserView, ipcMain, IpcMainEvent } from 'electron';
|
|
|
3
3
|
import {
|
|
4
4
|
PresentationWindowRenderer,
|
|
5
5
|
CreateWindowOptions,
|
|
6
|
-
WindowBounds
|
|
6
|
+
WindowBounds,
|
|
7
7
|
} from './types';
|
|
8
8
|
|
|
9
9
|
interface BrowserViewRendererWindow {
|
|
@@ -31,13 +31,13 @@ export default class BrowserViewRenderer implements PresentationWindowRenderer {
|
|
|
31
31
|
parentWindowId,
|
|
32
32
|
bounds,
|
|
33
33
|
backgroundColor,
|
|
34
|
-
receiveMessageCallback
|
|
34
|
+
receiveMessageCallback,
|
|
35
35
|
}: CreateWindowOptions) {
|
|
36
36
|
const window = {
|
|
37
37
|
view: new BrowserView({
|
|
38
38
|
webPreferences: {
|
|
39
|
-
preload: path.join(__dirname, 'preload.js')
|
|
40
|
-
}
|
|
39
|
+
preload: path.join(__dirname, 'preload.js'),
|
|
40
|
+
},
|
|
41
41
|
}),
|
|
42
42
|
|
|
43
43
|
bounds: bounds || { ...this.mainWindow.getBounds(), x: 0, y: 0 },
|
|
@@ -50,7 +50,7 @@ export default class BrowserViewRenderer implements PresentationWindowRenderer {
|
|
|
50
50
|
if (receiveMessageCallback) {
|
|
51
51
|
receiveMessageCallback(type, payload);
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
},
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
this.windows[windowId] = window;
|
|
@@ -69,7 +69,7 @@ export default class BrowserViewRenderer implements PresentationWindowRenderer {
|
|
|
69
69
|
if (!parentWindowId) {
|
|
70
70
|
window.view.setAutoResize({
|
|
71
71
|
width: true,
|
|
72
|
-
height: true
|
|
72
|
+
height: true,
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -131,7 +131,7 @@ export default class BrowserViewRenderer implements PresentationWindowRenderer {
|
|
|
131
131
|
delete this.windows[windowId];
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
public
|
|
134
|
+
public sendMessageString(windowId: string, message: string) {
|
|
135
135
|
const window = this.getWindow(windowId);
|
|
136
136
|
if (!window) {
|
|
137
137
|
throw new Error(
|
|
@@ -142,6 +142,17 @@ export default class BrowserViewRenderer implements PresentationWindowRenderer {
|
|
|
142
142
|
window.view.webContents.send('electron-main', message);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
public sendMessageObject(windowId: string, type: string, payload?: any) {
|
|
146
|
+
const window = this.getWindow(windowId);
|
|
147
|
+
if (!window) {
|
|
148
|
+
throw new Error(
|
|
149
|
+
`Failed to send message to window, missing window id '${windowId}'`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
window.view.webContents.send('electron-main', { type, payload });
|
|
154
|
+
}
|
|
155
|
+
|
|
145
156
|
public muteWindow(windowId: string) {
|
|
146
157
|
const window = this.getWindow(windowId);
|
|
147
158
|
if (!window) {
|
|
@@ -7,13 +7,13 @@ import {
|
|
|
7
7
|
Event,
|
|
8
8
|
Details,
|
|
9
9
|
BrowserWindowConstructorOptions,
|
|
10
|
-
BrowserViewConstructorOptions
|
|
10
|
+
BrowserViewConstructorOptions,
|
|
11
11
|
} from 'electron';
|
|
12
12
|
import {
|
|
13
13
|
PresentationWindowRenderer,
|
|
14
14
|
CreateWindowOptions,
|
|
15
15
|
WindowBounds,
|
|
16
|
-
Logger
|
|
16
|
+
Logger,
|
|
17
17
|
} from './types';
|
|
18
18
|
import WindowUnresponsiveError from './WindowUnresponsiveError';
|
|
19
19
|
|
|
@@ -47,7 +47,8 @@ interface BrowserWindowRendererOptions {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export default class BrowserWindowRenderer
|
|
50
|
-
implements PresentationWindowRenderer
|
|
50
|
+
implements PresentationWindowRenderer
|
|
51
|
+
{
|
|
51
52
|
private windows: {
|
|
52
53
|
[windowId: string]: BrowserWindowRendererWindow;
|
|
53
54
|
} = {};
|
|
@@ -62,8 +63,8 @@ export default class BrowserWindowRenderer
|
|
|
62
63
|
frame: this.opts.frame,
|
|
63
64
|
hasShadow: this.opts.hasShadow,
|
|
64
65
|
webPreferences: {
|
|
65
|
-
preload: path.join(__dirname, 'preload.js')
|
|
66
|
-
}
|
|
66
|
+
preload: path.join(__dirname, 'preload.js'),
|
|
67
|
+
},
|
|
67
68
|
});
|
|
68
69
|
|
|
69
70
|
private proxySettings: ProxySettings | null = null;
|
|
@@ -89,7 +90,7 @@ export default class BrowserWindowRenderer
|
|
|
89
90
|
bounds = this.opts.bounds,
|
|
90
91
|
backgroundColor,
|
|
91
92
|
receiveMessageCallback,
|
|
92
|
-
errorCallback
|
|
93
|
+
errorCallback,
|
|
93
94
|
}: CreateWindowOptions) {
|
|
94
95
|
const window: BrowserWindowRendererWindow = {
|
|
95
96
|
parentWindowId,
|
|
@@ -99,8 +100,8 @@ export default class BrowserWindowRenderer
|
|
|
99
100
|
parentWindowId && this.opts.renderChildWindowsAsBrowserViews
|
|
100
101
|
? this.createOrGetPooledBrowserView(windowId, {
|
|
101
102
|
webPreferences: {
|
|
102
|
-
preload: path.join(__dirname, 'preload.js')
|
|
103
|
-
}
|
|
103
|
+
preload: path.join(__dirname, 'preload.js'),
|
|
104
|
+
},
|
|
104
105
|
})
|
|
105
106
|
: this.createOrGetPooledBrowserWindow(windowId, {
|
|
106
107
|
show: false,
|
|
@@ -113,8 +114,8 @@ export default class BrowserWindowRenderer
|
|
|
113
114
|
transparent: backgroundColor === 'transparent',
|
|
114
115
|
hasShadow: this.opts.hasShadow,
|
|
115
116
|
webPreferences: {
|
|
116
|
-
preload: path.join(__dirname, 'preload.js')
|
|
117
|
-
}
|
|
117
|
+
preload: path.join(__dirname, 'preload.js'),
|
|
118
|
+
},
|
|
118
119
|
}),
|
|
119
120
|
// If we are creating a child window and renderChildWindowsAsBrowserViews is false that means
|
|
120
121
|
// we are rendering child windows with BrowserWindow. BrowserWindows are positioned absolutely so
|
|
@@ -125,7 +126,7 @@ export default class BrowserWindowRenderer
|
|
|
125
126
|
? {
|
|
126
127
|
...bounds,
|
|
127
128
|
x: bounds.x + this.opts.bounds.x,
|
|
128
|
-
y: bounds.y + this.opts.bounds.y
|
|
129
|
+
y: bounds.y + this.opts.bounds.y,
|
|
129
130
|
}
|
|
130
131
|
: bounds,
|
|
131
132
|
|
|
@@ -163,7 +164,7 @@ export default class BrowserWindowRenderer
|
|
|
163
164
|
`Window '${windowId}' render process gone`
|
|
164
165
|
)
|
|
165
166
|
);
|
|
166
|
-
}
|
|
167
|
+
},
|
|
167
168
|
};
|
|
168
169
|
|
|
169
170
|
// Attached crash handlers to skip presentation on error.
|
|
@@ -226,7 +227,7 @@ export default class BrowserWindowRenderer
|
|
|
226
227
|
window.view.setBounds({
|
|
227
228
|
...window.bounds,
|
|
228
229
|
x: window.bounds.x + this.opts.bounds.x,
|
|
229
|
-
y: window.bounds.y + this.opts.bounds.y
|
|
230
|
+
y: window.bounds.y + this.opts.bounds.y,
|
|
230
231
|
});
|
|
231
232
|
} else {
|
|
232
233
|
window.view.setBounds(window.bounds);
|
|
@@ -306,7 +307,7 @@ export default class BrowserWindowRenderer
|
|
|
306
307
|
}
|
|
307
308
|
}
|
|
308
309
|
|
|
309
|
-
public
|
|
310
|
+
public sendMessageString(windowId: string, message: string) {
|
|
310
311
|
const window = this.getWindow(windowId);
|
|
311
312
|
if (!window) {
|
|
312
313
|
throw new Error(
|
|
@@ -317,6 +318,17 @@ export default class BrowserWindowRenderer
|
|
|
317
318
|
window.view.webContents.send('electron-main', message);
|
|
318
319
|
}
|
|
319
320
|
|
|
321
|
+
public sendMessageObject(windowId: string, type: string, payload?: any) {
|
|
322
|
+
const window = this.getWindow(windowId);
|
|
323
|
+
if (!window) {
|
|
324
|
+
throw new Error(
|
|
325
|
+
`Failed to send message to window, missing window id '${windowId}'`
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
window.view.webContents.send('electron-main', { type, payload });
|
|
330
|
+
}
|
|
331
|
+
|
|
320
332
|
public muteWindow(windowId: string) {
|
|
321
333
|
const window = this.getWindow(windowId);
|
|
322
334
|
if (!window) {
|
|
@@ -436,7 +448,7 @@ export default class BrowserWindowRenderer
|
|
|
436
448
|
this.logger.info(`Found free browser window from pool`, { windowId });
|
|
437
449
|
} else {
|
|
438
450
|
this.logger.info(`No free browser windows, adding new window to pool`, {
|
|
439
|
-
windowId
|
|
451
|
+
windowId,
|
|
440
452
|
});
|
|
441
453
|
}
|
|
442
454
|
}
|
|
@@ -486,7 +498,7 @@ export default class BrowserWindowRenderer
|
|
|
486
498
|
this.logger.info(`Found free browser view from pool`, { windowId });
|
|
487
499
|
} else {
|
|
488
500
|
this.logger.info(`No free browser views, adding new view to pool`, {
|
|
489
|
-
windowId
|
|
501
|
+
windowId,
|
|
490
502
|
});
|
|
491
503
|
}
|
|
492
504
|
}
|
|
@@ -568,7 +580,7 @@ class WindowPool<T extends BrowserWindow | BrowserView> {
|
|
|
568
580
|
return {
|
|
569
581
|
total: inuse + free,
|
|
570
582
|
inuse,
|
|
571
|
-
free
|
|
583
|
+
free,
|
|
572
584
|
};
|
|
573
585
|
}
|
|
574
586
|
}
|
package/src/IFrameRenderer.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PresentationWindowRenderer,
|
|
3
3
|
CreateWindowOptions,
|
|
4
|
-
WindowBounds
|
|
4
|
+
WindowBounds,
|
|
5
5
|
} from './types';
|
|
6
6
|
|
|
7
7
|
interface IFrameRendererWindow {
|
|
@@ -9,7 +9,7 @@ interface IFrameRendererWindow {
|
|
|
9
9
|
receiveMessageCallback?: (type: string, payload?: any) => void;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const namespace = 'raydiant';
|
|
13
13
|
|
|
14
14
|
export default class IFrameRenderer implements PresentationWindowRenderer {
|
|
15
15
|
private windows: {
|
|
@@ -27,7 +27,7 @@ export default class IFrameRenderer implements PresentationWindowRenderer {
|
|
|
27
27
|
windowId,
|
|
28
28
|
bounds,
|
|
29
29
|
backgroundColor = 'black',
|
|
30
|
-
receiveMessageCallback
|
|
30
|
+
receiveMessageCallback,
|
|
31
31
|
}: CreateWindowOptions) {
|
|
32
32
|
const frame = document.createElement('iframe');
|
|
33
33
|
this.windows[windowId] = { frame, receiveMessageCallback };
|
|
@@ -141,7 +141,7 @@ export default class IFrameRenderer implements PresentationWindowRenderer {
|
|
|
141
141
|
delete this.windows[windowId];
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
public
|
|
144
|
+
public sendMessageString(windowId: string, message: string) {
|
|
145
145
|
const window = this.getWindow(windowId);
|
|
146
146
|
if (!window) {
|
|
147
147
|
throw new Error(
|
|
@@ -155,7 +155,27 @@ export default class IFrameRenderer implements PresentationWindowRenderer {
|
|
|
155
155
|
);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
window.frame.contentWindow.postMessage(`${
|
|
158
|
+
window.frame.contentWindow.postMessage(`${namespace}:${message}`, '*');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public sendMessageObject(windowId: string, type: string, payload?: any) {
|
|
162
|
+
const window = this.getWindow(windowId);
|
|
163
|
+
if (!window) {
|
|
164
|
+
throw new Error(
|
|
165
|
+
`Failed to send message '${type}', missing window id '${windowId}'`
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!window.frame.contentWindow) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
`Failed to send message '${type}', contentWindow missing for '${windowId}'`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
window.frame.contentWindow.postMessage(
|
|
176
|
+
{ namespace, windowId, type, payload },
|
|
177
|
+
'*'
|
|
178
|
+
);
|
|
159
179
|
}
|
|
160
180
|
|
|
161
181
|
public muteWindow(windowId: string) {
|
|
@@ -190,10 +210,7 @@ export default class IFrameRenderer implements PresentationWindowRenderer {
|
|
|
190
210
|
|
|
191
211
|
private globalMessageHandler = (event: MessageEvent) => {
|
|
192
212
|
// Ignore messages that don't start with the message prefix.
|
|
193
|
-
if (
|
|
194
|
-
typeof event.data === 'string' &&
|
|
195
|
-
event.data.startsWith(messagePrefix)
|
|
196
|
-
) {
|
|
213
|
+
if (typeof event.data === 'string' && event.data.startsWith(namespace)) {
|
|
197
214
|
const { windowId, type, payload } = this.deserializeMessage(event.data);
|
|
198
215
|
|
|
199
216
|
if (!windowId || !type) {
|
|
@@ -221,7 +238,7 @@ export default class IFrameRenderer implements PresentationWindowRenderer {
|
|
|
221
238
|
let type = '';
|
|
222
239
|
let payload: unknown;
|
|
223
240
|
|
|
224
|
-
const json = message.
|
|
241
|
+
const json = message.replace('raydiant:', '');
|
|
225
242
|
try {
|
|
226
243
|
// Messages are sent as json in the format of { type: string, payload: unknown }.
|
|
227
244
|
({ windowId, type, payload } = JSON.parse(json));
|