@interopio/browser-platform 3.0.1
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/browser.platform.d.ts +455 -0
- package/changelog.md +69 -0
- package/dist/browser.platform.es.js +46074 -0
- package/dist/browser.platform.es.js.map +1 -0
- package/dist/browser.platform.umd.js +46082 -0
- package/dist/browser.platform.umd.js.map +1 -0
- package/license.md +21 -0
- package/package.json +78 -0
- package/readme.md +9 -0
- package/rollup.config.js +45 -0
- package/src/common/constants.ts +46 -0
- package/src/common/defaultConfig.ts +56 -0
- package/src/common/gateway.d.ts +32 -0
- package/src/common/types.ts +222 -0
- package/src/connection/gateway.ts +132 -0
- package/src/connection/no-gateway.ts +1 -0
- package/src/connection/portsBridge.ts +441 -0
- package/src/connection/preferred.ts +247 -0
- package/src/controllers/domains.ts +156 -0
- package/src/controllers/glue.ts +604 -0
- package/src/controllers/interception.ts +53 -0
- package/src/controllers/license.ts +50 -0
- package/src/controllers/main.ts +256 -0
- package/src/controllers/plugins.ts +121 -0
- package/src/controllers/serviceWorker.ts +193 -0
- package/src/controllers/state.ts +84 -0
- package/src/controllers/system.ts +99 -0
- package/src/controllers/transactions.ts +80 -0
- package/src/factory.ts +40 -0
- package/src/fallbacks/browser.ts +47 -0
- package/src/fallbacks/dekstop.ts +21 -0
- package/src/index.ts +18 -0
- package/src/libs/applications/appStore/directory.ts +235 -0
- package/src/libs/applications/appStore/remoteWatcher.ts +112 -0
- package/src/libs/applications/controller.ts +469 -0
- package/src/libs/applications/decoders.ts +98 -0
- package/src/libs/applications/defaults.ts +6 -0
- package/src/libs/applications/types.ts +98 -0
- package/src/libs/channels/controller.ts +109 -0
- package/src/libs/channels/decoders.ts +19 -0
- package/src/libs/extension/controller.ts +120 -0
- package/src/libs/extension/decoders.ts +18 -0
- package/src/libs/extension/types.ts +11 -0
- package/src/libs/intents/constants.ts +9 -0
- package/src/libs/intents/controller.ts +500 -0
- package/src/libs/intents/decoders.ts +96 -0
- package/src/libs/intents/resolverHelper.ts +264 -0
- package/src/libs/intents/types.ts +119 -0
- package/src/libs/layouts/constants.ts +3 -0
- package/src/libs/layouts/controller.ts +476 -0
- package/src/libs/layouts/decoders.ts +132 -0
- package/src/libs/layouts/global/builder.ts +400 -0
- package/src/libs/layouts/global/resetter.ts +116 -0
- package/src/libs/layouts/global/restorer.ts +217 -0
- package/src/libs/layouts/global/validator.ts +169 -0
- package/src/libs/layouts/idbStore.ts +63 -0
- package/src/libs/layouts/types.ts +133 -0
- package/src/libs/manager/controller.ts +175 -0
- package/src/libs/manager/decoders.ts +6 -0
- package/src/libs/manager/defaults.ts +5 -0
- package/src/libs/manager/identity.ts +92 -0
- package/src/libs/manager/session.ts +195 -0
- package/src/libs/manager/types.ts +51 -0
- package/src/libs/notifications/controller.ts +447 -0
- package/src/libs/notifications/decoders.ts +166 -0
- package/src/libs/notifications/types.ts +49 -0
- package/src/libs/notifications/utils.ts +7 -0
- package/src/libs/search/controller.ts +232 -0
- package/src/libs/search/decoders.ts +6 -0
- package/src/libs/search/repositories/applications.ts +62 -0
- package/src/libs/search/repositories/layouts.ts +48 -0
- package/src/libs/search/repositories/workspaces.ts +47 -0
- package/src/libs/search/types.ts +9 -0
- package/src/libs/themes/constants.ts +9 -0
- package/src/libs/themes/controller.ts +153 -0
- package/src/libs/themes/decoders.ts +28 -0
- package/src/libs/themes/types.ts +28 -0
- package/src/libs/windows/controller.ts +498 -0
- package/src/libs/windows/decoders.ts +64 -0
- package/src/libs/windows/types.ts +59 -0
- package/src/libs/workspaces/controller.ts +922 -0
- package/src/libs/workspaces/decoders.ts +868 -0
- package/src/libs/workspaces/defaultConfig.ts +11 -0
- package/src/libs/workspaces/frames.ts +239 -0
- package/src/libs/workspaces/hibernationWatcher.ts +231 -0
- package/src/libs/workspaces/types.ts +506 -0
- package/src/platform.ts +156 -0
- package/src/shared/decoders.ts +479 -0
- package/src/shared/fetchTimeout.ts +25 -0
- package/src/shared/ioc.ts +580 -0
- package/src/shared/logger.ts +19 -0
- package/src/shared/promisePlus.ts +62 -0
- package/src/shared/sequelizer.ts +48 -0
- package/src/shared/utils.ts +86 -0
- package/src/storage/local.ts +111 -0
- package/src/storage/session.ts +436 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
2
|
+
import { ClientAPI } from "@glue42/server-api/dist/client";
|
|
3
|
+
import { SaveUserLayoutRequest } from "@glue42/server-api/dist/messages/user";
|
|
4
|
+
import { ClientOptions } from "@glue42/server-api/dist/client-api/options";
|
|
5
|
+
import { BridgeOperation, InternalPlatformConfig, LibController, OperationCheckConfig, OperationCheckResult } from "../../common/types";
|
|
6
|
+
import logger from "../../shared/logger";
|
|
7
|
+
import { operationCheckConfigDecoder, operationCheckResultDecoder } from "../../shared/decoders";
|
|
8
|
+
import { IOConnectBrowserPlatform } from "../../../browser.platform";
|
|
9
|
+
import { ManagerOperationsTypes } from "./types";
|
|
10
|
+
import { managerOperationDecoder } from "./decoders";
|
|
11
|
+
import { Identity } from "./identity";
|
|
12
|
+
import { Session } from "./session";
|
|
13
|
+
import { LayoutsController } from "../layouts/controller";
|
|
14
|
+
import { LayoutEvent } from "../layouts/types";
|
|
15
|
+
import { extractErrorMsg } from "../../shared/utils";
|
|
16
|
+
|
|
17
|
+
export class ManagerController implements LibController {
|
|
18
|
+
|
|
19
|
+
private started = false;
|
|
20
|
+
public name = "Glue42 Server Client";
|
|
21
|
+
private config: IOConnectBrowserPlatform.Manager.Config | undefined;
|
|
22
|
+
private unloadCallback: () => void;
|
|
23
|
+
private unsubLayouts?: () => void;
|
|
24
|
+
private client!: ClientAPI;
|
|
25
|
+
|
|
26
|
+
private operations: { [key in ManagerOperationsTypes]: BridgeOperation } = {
|
|
27
|
+
operationCheck: { name: "operationCheck", dataDecoder: operationCheckConfigDecoder, resultDecoder: operationCheckResultDecoder, execute: this.handleOperationCheck.bind(this) }
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
constructor(
|
|
31
|
+
private readonly layoutsController: LayoutsController,
|
|
32
|
+
private readonly identity: Identity,
|
|
33
|
+
private readonly session: Session,
|
|
34
|
+
private readonly buildClient: (clientOptions: ClientOptions) => ClientAPI,
|
|
35
|
+
) {
|
|
36
|
+
this.unloadCallback = this.handleUnload.bind(this);
|
|
37
|
+
window.addEventListener("beforeunload", this.unloadCallback);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private get logger(): IOConnectBrowser.Logger.API | undefined {
|
|
41
|
+
return logger.get("manager.controller");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public handlePlatformShutdown(): void {
|
|
45
|
+
this.started = false;
|
|
46
|
+
|
|
47
|
+
window.removeEventListener("beforeunload", this.unloadCallback);
|
|
48
|
+
|
|
49
|
+
this.handleUnload();
|
|
50
|
+
|
|
51
|
+
if (this.unsubLayouts) {
|
|
52
|
+
this.unsubLayouts();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public async configurePostStart(): Promise<void> {
|
|
57
|
+
if (!this.config) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const username = this.config.auth.username ?? this.config.auth.basic?.username;
|
|
62
|
+
|
|
63
|
+
if (!username) {
|
|
64
|
+
throw new Error("Cannot connect to the Glue42 Server, because no username was provided. Please provide a username in auth.username or auth.basic.username");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const clientOptions: ClientOptions = {
|
|
68
|
+
baseUrl: this.config.url,
|
|
69
|
+
auth: this.config.auth,
|
|
70
|
+
headers: this.config.headers
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
this.client = this.buildClient(clientOptions);
|
|
74
|
+
|
|
75
|
+
this.logger?.trace("The client API is ready.");
|
|
76
|
+
|
|
77
|
+
const machine = await this.identity.getMachineInfo(username);
|
|
78
|
+
const glueInfo = this.identity.getGlueInfo();
|
|
79
|
+
|
|
80
|
+
this.logger?.trace(`Opening a session for machine: ${JSON.stringify(machine)} and glue: ${JSON.stringify(glueInfo)}`);
|
|
81
|
+
|
|
82
|
+
await this.session.openSession(this.client, machine, glueInfo, this.config);
|
|
83
|
+
|
|
84
|
+
this.unsubLayouts = this.layoutsController.onUserLayoutEvent(this.handleLayoutEvent.bind(this));
|
|
85
|
+
|
|
86
|
+
this.logger?.info(`Module ${this.name} started`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public async start(config: InternalPlatformConfig): Promise<void> {
|
|
90
|
+
|
|
91
|
+
if (!config.manager) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.started = true;
|
|
96
|
+
|
|
97
|
+
this.config = config.manager;
|
|
98
|
+
|
|
99
|
+
this.logger?.info("Starting the Manager controller.");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public async handleControl(controlMessage: IOConnectBrowserPlatform.ControlMessage): Promise<any> {
|
|
103
|
+
if (!this.started) {
|
|
104
|
+
new Error("Cannot handle this manager control message, because the controller has not been started");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const notificationsData = controlMessage.data;
|
|
108
|
+
|
|
109
|
+
const commandId = controlMessage.commandId;
|
|
110
|
+
|
|
111
|
+
const operationValidation = managerOperationDecoder.run(controlMessage.operation);
|
|
112
|
+
|
|
113
|
+
if (!operationValidation.ok) {
|
|
114
|
+
throw new Error(`This manager request cannot be completed, because the operation name did not pass validation: ${JSON.stringify(operationValidation.error)}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const operationName: ManagerOperationsTypes = operationValidation.result;
|
|
118
|
+
|
|
119
|
+
const incomingValidation = this.operations[operationName].dataDecoder?.run(notificationsData);
|
|
120
|
+
|
|
121
|
+
if (incomingValidation && !incomingValidation.ok) {
|
|
122
|
+
throw new Error(`Manager request for ${operationName} rejected, because the provided arguments did not pass the validation: ${JSON.stringify(incomingValidation.error)}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.logger?.debug(`[${commandId}] ${operationName} command is valid with data: ${JSON.stringify(notificationsData)}`);
|
|
126
|
+
|
|
127
|
+
const result = await this.operations[operationName].execute(notificationsData, commandId);
|
|
128
|
+
|
|
129
|
+
const resultValidation = this.operations[operationName].resultDecoder?.run(result);
|
|
130
|
+
|
|
131
|
+
if (resultValidation && !resultValidation.ok) {
|
|
132
|
+
throw new Error(`Manager request for ${operationName} could not be completed, because the operation result did not pass the validation: ${JSON.stringify(resultValidation.error)}`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.logger?.trace(`[${commandId}] ${operationName} command was executed successfully`);
|
|
136
|
+
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private async handleOperationCheck(config: OperationCheckConfig): Promise<OperationCheckResult> {
|
|
141
|
+
const operations = Object.keys(this.operations);
|
|
142
|
+
|
|
143
|
+
const isSupported = operations.some((operation) => operation.toLowerCase() === config.operation.toLowerCase());
|
|
144
|
+
|
|
145
|
+
return { isSupported };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private async handleLayoutEvent(data: { operation: LayoutEvent, layout: IOConnectBrowser.Layouts.Layout }): Promise<void> {
|
|
149
|
+
if (data.operation === "layoutRemoved") {
|
|
150
|
+
await this.client.deleteUserLayout(data.layout.name).catch((err) => this.logger?.warn(extractErrorMsg(err)));
|
|
151
|
+
|
|
152
|
+
this.logger?.trace(`Deleted layout ${data.layout.name}`);
|
|
153
|
+
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const saveRequest: SaveUserLayoutRequest = {
|
|
158
|
+
type: data.layout.type,
|
|
159
|
+
name: data.layout.name,
|
|
160
|
+
definition: JSON.stringify(data.layout),
|
|
161
|
+
default: false
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
await this.client.saveLayout(saveRequest).catch((err) => this.logger?.warn(extractErrorMsg(err)));
|
|
165
|
+
|
|
166
|
+
this.logger?.trace(`Saved layout ${data.layout.name}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private handleUnload(): void {
|
|
170
|
+
if (!this.client) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
this.client.unload();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { version } from "../../../package.json";
|
|
2
|
+
import { GlueInfo, Machine } from "./types";
|
|
3
|
+
import { GlueController } from "../../controllers/glue";
|
|
4
|
+
import { PluginsController } from "../../controllers/plugins";
|
|
5
|
+
|
|
6
|
+
export class Identity {
|
|
7
|
+
constructor(
|
|
8
|
+
private readonly uaParser: UAParser,
|
|
9
|
+
private readonly glueController: GlueController,
|
|
10
|
+
private readonly pluginsController: PluginsController,
|
|
11
|
+
private readonly workspacesFrameUrl?: string
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
public async getMachineInfo(username: string): Promise<Machine> {
|
|
15
|
+
const info = this.uaParser.getResult();
|
|
16
|
+
|
|
17
|
+
const os = {
|
|
18
|
+
name: info.os.name || "",
|
|
19
|
+
version: info.os.version || "",
|
|
20
|
+
arch: info.cpu.architecture || ""
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const browser = {
|
|
24
|
+
name: info.browser.name,
|
|
25
|
+
version: info.browser.version,
|
|
26
|
+
engine: info.engine.name
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const mobileDevice = info.device?.type === "mobile" ? {
|
|
30
|
+
vendor: info.device.vendor,
|
|
31
|
+
model: info.device.model
|
|
32
|
+
} : undefined;
|
|
33
|
+
|
|
34
|
+
const displays = await this.getDisplays();
|
|
35
|
+
|
|
36
|
+
return { user: username, name: "", os, browser, mobileDevice, displays };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public getGlueInfo(): GlueInfo {
|
|
40
|
+
return {
|
|
41
|
+
version: "",
|
|
42
|
+
build: "",
|
|
43
|
+
region: "",
|
|
44
|
+
env: "",
|
|
45
|
+
core: {
|
|
46
|
+
web: {
|
|
47
|
+
version: this.glueController.clientGlue.version
|
|
48
|
+
},
|
|
49
|
+
platform: {
|
|
50
|
+
version: this.glueController.platformVersion,
|
|
51
|
+
plugins: this.pluginsController.registeredPlugins
|
|
52
|
+
},
|
|
53
|
+
plus: { version }
|
|
54
|
+
},
|
|
55
|
+
workspaces: this.glueController.isWorkspacesEnabled ? {
|
|
56
|
+
version: this.glueController.clientGlue.workspaces?.version as string,
|
|
57
|
+
frameUrl: this.workspacesFrameUrl
|
|
58
|
+
} : undefined
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private async getDisplays(): Promise<any[]> {
|
|
63
|
+
// disabling a few rules is necessary, because at this time the DOM typings where not updated with the latest window-placement permission
|
|
64
|
+
const { state } = await (navigator as any).permissions.query({ name: "window-placement" });
|
|
65
|
+
|
|
66
|
+
if (state !== "granted") {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const details = await (window as any).getScreenDetails();
|
|
71
|
+
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
73
|
+
return details.screens.map((screen: any) => {
|
|
74
|
+
return {
|
|
75
|
+
bounds: {
|
|
76
|
+
x: screen.left,
|
|
77
|
+
y: screen.top,
|
|
78
|
+
width: screen.width,
|
|
79
|
+
height: screen.height
|
|
80
|
+
},
|
|
81
|
+
workingArea: {
|
|
82
|
+
x: screen.availLeft,
|
|
83
|
+
y: screen.availTop,
|
|
84
|
+
width: screen.availWidth,
|
|
85
|
+
height: screen.availHeight
|
|
86
|
+
},
|
|
87
|
+
dpi: screen.devicePixelRatio,
|
|
88
|
+
isPrimary: screen.isPrimary
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { ApplicationConfig, RefreshResponseData, Token, UserLayoutDefinition } from "@glue42/server-api";
|
|
2
|
+
import { ClientAPI } from "@glue42/server-api/dist/client";
|
|
3
|
+
import logger from "../../shared/logger";
|
|
4
|
+
import { GlueController } from "../../controllers/glue";
|
|
5
|
+
import { IOConnectBrowserPlatform } from "../../../browser.platform";
|
|
6
|
+
import { GlueInfo, LayoutParseResult, Machine } from "./types";
|
|
7
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
8
|
+
import { defaultDataRefreshIntervalMS, defaultTokenRefreshIntervalMS } from "./defaults";
|
|
9
|
+
import { extractErrorMsg } from "../../shared/utils";
|
|
10
|
+
import { LayoutsController } from "../layouts/controller";
|
|
11
|
+
import { glueLayoutDecoder } from "../../shared/decoders";
|
|
12
|
+
|
|
13
|
+
// keeps and updates the snapshot
|
|
14
|
+
export class Session {
|
|
15
|
+
|
|
16
|
+
private token!: Token;
|
|
17
|
+
private client!: ClientAPI;
|
|
18
|
+
private lastApps?: RefreshResponseData<ApplicationConfig>;
|
|
19
|
+
private lastLayouts?: RefreshResponseData<UserLayoutDefinition>;
|
|
20
|
+
private sessionInitiated = false;
|
|
21
|
+
private serverConfig?: IOConnectBrowserPlatform.Manager.Config;
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
private readonly glueController: GlueController,
|
|
25
|
+
private readonly layoutsController: LayoutsController
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
private get logger(): IOConnectBrowser.Logger.API | undefined {
|
|
29
|
+
return logger.get("manager.session");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public async openSession(client: ClientAPI, machine: Machine, glueInfo: GlueInfo, config: IOConnectBrowserPlatform.Manager.Config): Promise<void> {
|
|
33
|
+
if (this.sessionInitiated) {
|
|
34
|
+
throw new Error("A server session has already been initiated");
|
|
35
|
+
}
|
|
36
|
+
this.serverConfig = config;
|
|
37
|
+
|
|
38
|
+
this.client = client;
|
|
39
|
+
|
|
40
|
+
this.sessionInitiated = true;
|
|
41
|
+
|
|
42
|
+
const session = await this.client.openSession(machine, glueInfo);
|
|
43
|
+
|
|
44
|
+
this.logger?.trace("The client session has been opened successfully");
|
|
45
|
+
|
|
46
|
+
this.token = session.token;
|
|
47
|
+
|
|
48
|
+
await this.updateApplications(session.data?.applications);
|
|
49
|
+
await this.updateLayouts(session.data?.layouts);
|
|
50
|
+
|
|
51
|
+
this.refreshData().catch((error) => {
|
|
52
|
+
this.logger?.warn(`Error while fetching server snapshot: ${JSON.stringify(error)}`);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
this.refreshToken().catch((error) => {
|
|
56
|
+
this.logger?.warn(`Error while refreshing the server token: ${JSON.stringify(error)}`);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public async closeSession(): Promise<void> {
|
|
61
|
+
this.sessionInitiated = false;
|
|
62
|
+
await this.client.closeSession();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private async refreshData(): Promise<void> {
|
|
66
|
+
|
|
67
|
+
if (!this.sessionInitiated) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
await this.waitInterval(this.serverConfig?.fetchIntervalMS || defaultDataRefreshIntervalMS);
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
|
|
75
|
+
this.logger?.trace("Sending a fresh snapshot request");
|
|
76
|
+
|
|
77
|
+
const response = await this.client.refreshData({
|
|
78
|
+
applications: {
|
|
79
|
+
include: true,
|
|
80
|
+
latestDataInfo: this.lastApps?.info
|
|
81
|
+
},
|
|
82
|
+
layouts: {
|
|
83
|
+
include: true,
|
|
84
|
+
latestDataInfo: this.lastLayouts?.info
|
|
85
|
+
},
|
|
86
|
+
commands: {
|
|
87
|
+
include: false
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
this.logger?.trace("Got a snapshot response, processing the applications and layouts");
|
|
92
|
+
|
|
93
|
+
await this.updateApplications(response.applications);
|
|
94
|
+
await this.updateLayouts(response.layouts);
|
|
95
|
+
|
|
96
|
+
} catch (error: any) {
|
|
97
|
+
|
|
98
|
+
const stringError = typeof error === "string" ? error : JSON.stringify(error.message);
|
|
99
|
+
|
|
100
|
+
this.logger?.warn(`An error occurred while refreshing the server snapshot: ${stringError}`);
|
|
101
|
+
} finally {
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
103
|
+
this.refreshData();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private async refreshToken(): Promise<void> {
|
|
108
|
+
|
|
109
|
+
if (!this.sessionInitiated) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
await this.waitInterval(this.serverConfig?.tokenRefreshIntervalMS || defaultTokenRefreshIntervalMS);
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
|
|
117
|
+
this.logger?.trace("Sending a fresh token refresh request");
|
|
118
|
+
|
|
119
|
+
const response = await this.client.refreshToken();
|
|
120
|
+
|
|
121
|
+
this.token = response;
|
|
122
|
+
|
|
123
|
+
this.logger?.trace("Server token refreshed successfully");
|
|
124
|
+
|
|
125
|
+
} catch (error: any) {
|
|
126
|
+
|
|
127
|
+
const stringError = typeof error === "string" ? error : JSON.stringify(error.message);
|
|
128
|
+
|
|
129
|
+
this.logger?.warn(`An error occurred while refreshing the server token: ${stringError}`);
|
|
130
|
+
} finally {
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
132
|
+
this.refreshToken();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private waitInterval(waitMS: number): Promise<void> {
|
|
137
|
+
return new Promise((resolve) => setTimeout(resolve, waitMS));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private async updateApplications(applications?: RefreshResponseData<ApplicationConfig>): Promise<void> {
|
|
141
|
+
if (!applications || !applications.hasChanges) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this.lastApps = applications;
|
|
146
|
+
await this.glueController.processServerApplicationsData(applications);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private async updateLayouts(layouts?: RefreshResponseData<UserLayoutDefinition>): Promise<void> {
|
|
150
|
+
if (!layouts || !layouts.hasChanges) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
this.lastLayouts = layouts;
|
|
155
|
+
await this.processServerLayoutsData(layouts);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private async processServerLayoutsData(layouts: RefreshResponseData<UserLayoutDefinition>): Promise<void> {
|
|
159
|
+
if (!layouts || !layouts.data) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// some times the server will send the definition as a string, so we need to parse it. It all depends on how they were imported into the server
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
165
|
+
const extractedLayouts = layouts.data.map<IOConnectBrowser.Layouts.Layout>((userLayoutDef) => typeof userLayoutDef.definition === "string" ? JSON.parse(userLayoutDef.definition) : userLayoutDef.definition);
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const sanitizesLayouts = this.sanitizeLayouts(extractedLayouts);
|
|
169
|
+
|
|
170
|
+
const layoutsToImport = extractedLayouts.filter((layout) => sanitizesLayouts.valid.some((validLayout) => validLayout.name === layout.name));
|
|
171
|
+
|
|
172
|
+
await this.layoutsController.handleImport({ layouts: layoutsToImport, mode: "merge", isManagerOperation: true }, "ManagerOperation");
|
|
173
|
+
|
|
174
|
+
} catch (error: any) {
|
|
175
|
+
const stringError = extractErrorMsg(error);
|
|
176
|
+
this.logger?.warn(`An error importing layouts: ${stringError}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private sanitizeLayouts(layouts: IOConnectBrowser.Layouts.Layout[]): LayoutParseResult {
|
|
181
|
+
return layouts.reduce<LayoutParseResult>((soFar, layout) => {
|
|
182
|
+
|
|
183
|
+
const decodeResult = glueLayoutDecoder.run(layout);
|
|
184
|
+
|
|
185
|
+
if (decodeResult.ok) {
|
|
186
|
+
soFar.valid.push(layout);
|
|
187
|
+
} else {
|
|
188
|
+
this.logger?.warn(`A layout with name: ${layout.name} was not imported, because of error: ${JSON.stringify(decodeResult.error)}`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return soFar;
|
|
192
|
+
|
|
193
|
+
}, { valid: [] });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
2
|
+
|
|
3
|
+
export type ManagerOperationsTypes = "operationCheck";
|
|
4
|
+
|
|
5
|
+
export interface Machine {
|
|
6
|
+
user: string;
|
|
7
|
+
name: string;
|
|
8
|
+
os: {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
arch: string;
|
|
12
|
+
};
|
|
13
|
+
browser?: {
|
|
14
|
+
name?: string;
|
|
15
|
+
version?: string;
|
|
16
|
+
engine?: string;
|
|
17
|
+
}
|
|
18
|
+
mobileDevice?: {
|
|
19
|
+
vendor?: string;
|
|
20
|
+
model?: string;
|
|
21
|
+
}
|
|
22
|
+
displays: any[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface GlueInfo {
|
|
26
|
+
version: string;
|
|
27
|
+
build: string;
|
|
28
|
+
region: string;
|
|
29
|
+
env: string;
|
|
30
|
+
core?: {
|
|
31
|
+
web: {
|
|
32
|
+
version: string;
|
|
33
|
+
};
|
|
34
|
+
platform: {
|
|
35
|
+
version: string;
|
|
36
|
+
plugins: Array<{ name: string, version: string }>;
|
|
37
|
+
};
|
|
38
|
+
plus: {
|
|
39
|
+
version: string
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
workspaces?: {
|
|
43
|
+
version: string;
|
|
44
|
+
frameUrl?: string;
|
|
45
|
+
frameApp?: string;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface LayoutParseResult {
|
|
50
|
+
valid: IOConnectBrowser.Layouts.Layout[];
|
|
51
|
+
}
|