@module-federation/dts-plugin 0.2.7 → 0.3.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/dist/CHANGELOG.md +23 -0
- package/dist/{DTSManagerOptions-c0728719.d.ts → DTSManagerOptions-7109e8ac.d.ts} +1 -0
- package/dist/{DtsWorker-90454949.d.ts → DtsWorker-17de6ba4.d.ts} +2 -5
- package/dist/core.d.mts +8 -4
- package/dist/core.d.ts +8 -4
- package/dist/core.js +78 -41
- package/dist/dynamic-remote-type-hints-plugin.js +5 -7
- package/dist/esm/{chunk-MQRIERJP.js → chunk-6DND574L.js} +7 -15
- package/dist/esm/chunk-DEW2PNCR.js +283 -0
- package/dist/esm/chunk-HKRTV6ZH.js +900 -0
- package/dist/esm/{chunk-ZLQBXHXA.js → chunk-SFEGBRA3.js} +331 -1426
- package/dist/esm/{chunk-G7ONFBMA.js → chunk-XKCIYRDL.js} +1 -1
- package/dist/esm/core.js +11 -11
- package/dist/esm/dynamic-remote-type-hints-plugin.js +2 -2
- package/dist/esm/fork-dev-worker.js +11 -7
- package/dist/esm/fork-generate-dts.js +3 -2
- package/dist/esm/index.js +21 -18
- package/dist/esm/start-broker.js +2 -2
- package/dist/fork-dev-worker.d.mts +1 -1
- package/dist/fork-dev-worker.d.ts +1 -1
- package/dist/fork-dev-worker.js +74 -39
- package/dist/fork-generate-dts.d.mts +2 -2
- package/dist/fork-generate-dts.d.ts +2 -2
- package/dist/fork-generate-dts.js +146 -290
- package/dist/iife/launch-web-client.js +5 -7
- package/dist/index.js +89 -52
- package/dist/package.json +1 -1
- package/dist/start-broker.js +28 -344
- package/package.json +5 -5
|
@@ -0,0 +1,900 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ActionKind,
|
|
3
|
+
DEFAULT_WEB_SOCKET_PORT,
|
|
4
|
+
Message,
|
|
5
|
+
UpdateKind,
|
|
6
|
+
UpdateMode,
|
|
7
|
+
WEB_SOCKET_CONNECT_MAGIC_ID,
|
|
8
|
+
__async,
|
|
9
|
+
__name,
|
|
10
|
+
__publicField
|
|
11
|
+
} from "./chunk-6DND574L.js";
|
|
12
|
+
|
|
13
|
+
// packages/dts-plugin/src/server/utils/log.ts
|
|
14
|
+
import { logger } from "@module-federation/sdk";
|
|
15
|
+
import * as log4js from "log4js";
|
|
16
|
+
import chalk from "chalk";
|
|
17
|
+
function fileLog(msg, module, level) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
if (!((_a = process == null ? void 0 : process.env) == null ? void 0 : _a["FEDERATION_DEBUG"])) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
log4js.configure({
|
|
23
|
+
appenders: {
|
|
24
|
+
[module]: {
|
|
25
|
+
type: "file",
|
|
26
|
+
filename: ".mf/typesGenerate.log"
|
|
27
|
+
},
|
|
28
|
+
default: {
|
|
29
|
+
type: "file",
|
|
30
|
+
filename: ".mf/typesGenerate.log"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
categories: {
|
|
34
|
+
[module]: {
|
|
35
|
+
appenders: [
|
|
36
|
+
module
|
|
37
|
+
],
|
|
38
|
+
level: "error"
|
|
39
|
+
},
|
|
40
|
+
default: {
|
|
41
|
+
appenders: [
|
|
42
|
+
"default"
|
|
43
|
+
],
|
|
44
|
+
level: "trace"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const logger4 = log4js.getLogger(module);
|
|
49
|
+
logger4.level = "debug";
|
|
50
|
+
(_b = logger4[level]) == null ? void 0 : _b.call(logger4, msg);
|
|
51
|
+
}
|
|
52
|
+
__name(fileLog, "fileLog");
|
|
53
|
+
function error(error2, action, from) {
|
|
54
|
+
const err = error2 instanceof Error ? error2 : new Error(`${action} error`);
|
|
55
|
+
fileLog(`[${action}] error: ${err}`, from, "fatal");
|
|
56
|
+
return err.toString();
|
|
57
|
+
}
|
|
58
|
+
__name(error, "error");
|
|
59
|
+
|
|
60
|
+
// packages/dts-plugin/src/server/utils/getIPV4.ts
|
|
61
|
+
import os from "os";
|
|
62
|
+
var localIpv4 = "127.0.0.1";
|
|
63
|
+
var getIpv4Interfaces = /* @__PURE__ */ __name(() => {
|
|
64
|
+
try {
|
|
65
|
+
const interfaces = os.networkInterfaces();
|
|
66
|
+
const ipv4Interfaces = [];
|
|
67
|
+
Object.values(interfaces).forEach((detail) => {
|
|
68
|
+
detail == null ? void 0 : detail.forEach((detail2) => {
|
|
69
|
+
const familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
|
|
70
|
+
if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
|
|
71
|
+
ipv4Interfaces.push(detail2);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
return ipv4Interfaces;
|
|
76
|
+
} catch (_err) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
}, "getIpv4Interfaces");
|
|
80
|
+
var getIPV4 = /* @__PURE__ */ __name(() => {
|
|
81
|
+
const ipv4Interfaces = getIpv4Interfaces();
|
|
82
|
+
const ipv4Interface = ipv4Interfaces[0] || {
|
|
83
|
+
address: localIpv4
|
|
84
|
+
};
|
|
85
|
+
return ipv4Interface.address;
|
|
86
|
+
}, "getIPV4");
|
|
87
|
+
|
|
88
|
+
// packages/dts-plugin/src/server/utils/index.ts
|
|
89
|
+
import net from "net";
|
|
90
|
+
import { SEPARATOR } from "@module-federation/sdk";
|
|
91
|
+
|
|
92
|
+
// packages/dts-plugin/src/server/utils/logTransform.ts
|
|
93
|
+
import chalk2 from "chalk";
|
|
94
|
+
|
|
95
|
+
// packages/dts-plugin/src/server/message/Log/Log.ts
|
|
96
|
+
var LogLevel;
|
|
97
|
+
(function(LogLevel2) {
|
|
98
|
+
LogLevel2["LOG"] = "LOG";
|
|
99
|
+
LogLevel2["WARN"] = "WARN";
|
|
100
|
+
LogLevel2["ERROR"] = "ERROR";
|
|
101
|
+
})(LogLevel || (LogLevel = {}));
|
|
102
|
+
var LogKind;
|
|
103
|
+
(function(LogKind2) {
|
|
104
|
+
LogKind2["BrokerExitLog"] = "BrokerExitLog";
|
|
105
|
+
LogKind2["PublisherRegisteredLog"] = "PublisherRegisteredLog";
|
|
106
|
+
})(LogKind || (LogKind = {}));
|
|
107
|
+
var _Log = class _Log extends Message {
|
|
108
|
+
constructor(level, kind, ignoreVerbose = false) {
|
|
109
|
+
super("Log", kind);
|
|
110
|
+
__publicField(this, "level");
|
|
111
|
+
__publicField(this, "ignoreVerbose", false);
|
|
112
|
+
this.level = level;
|
|
113
|
+
this.ignoreVerbose = ignoreVerbose;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
__name(_Log, "Log");
|
|
117
|
+
var Log = _Log;
|
|
118
|
+
|
|
119
|
+
// packages/dts-plugin/src/server/message/Log/BrokerExitLog.ts
|
|
120
|
+
var _BrokerExitLog = class _BrokerExitLog extends Log {
|
|
121
|
+
constructor() {
|
|
122
|
+
super(LogLevel.LOG, LogKind.BrokerExitLog);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
__name(_BrokerExitLog, "BrokerExitLog");
|
|
126
|
+
var BrokerExitLog = _BrokerExitLog;
|
|
127
|
+
|
|
128
|
+
// packages/dts-plugin/src/server/utils/index.ts
|
|
129
|
+
function getIdentifier(options) {
|
|
130
|
+
const { ip, name } = options;
|
|
131
|
+
return `mf ${SEPARATOR}${name}${ip ? `${SEPARATOR}${ip}` : ""}`;
|
|
132
|
+
}
|
|
133
|
+
__name(getIdentifier, "getIdentifier");
|
|
134
|
+
function fib(n) {
|
|
135
|
+
let i = 2;
|
|
136
|
+
const res = [
|
|
137
|
+
0,
|
|
138
|
+
1,
|
|
139
|
+
1
|
|
140
|
+
];
|
|
141
|
+
while (i <= n) {
|
|
142
|
+
res[i] = res[i - 1] + res[i - 2];
|
|
143
|
+
i++;
|
|
144
|
+
}
|
|
145
|
+
return res[n];
|
|
146
|
+
}
|
|
147
|
+
__name(fib, "fib");
|
|
148
|
+
function getFreePort() {
|
|
149
|
+
return new Promise((resolve, reject) => {
|
|
150
|
+
const server = net.createServer();
|
|
151
|
+
server.unref();
|
|
152
|
+
server.on("error", reject);
|
|
153
|
+
server.listen(0, () => {
|
|
154
|
+
const { port } = server.address();
|
|
155
|
+
server.close(() => {
|
|
156
|
+
resolve(port);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
__name(getFreePort, "getFreePort");
|
|
162
|
+
|
|
163
|
+
// packages/dts-plugin/src/server/broker/Broker.ts
|
|
164
|
+
import { createServer } from "http";
|
|
165
|
+
import WebSocket from "isomorphic-ws";
|
|
166
|
+
import schedule from "node-schedule";
|
|
167
|
+
import { parse } from "url";
|
|
168
|
+
|
|
169
|
+
// packages/dts-plugin/src/server/message/API/API.ts
|
|
170
|
+
var APIKind;
|
|
171
|
+
(function(APIKind2) {
|
|
172
|
+
APIKind2["UPDATE_SUBSCRIBER"] = "UPDATE_SUBSCRIBER";
|
|
173
|
+
APIKind2["RELOAD_WEB_CLIENT"] = "RELOAD_WEB_CLIENT";
|
|
174
|
+
APIKind2["FETCH_TYPES"] = "FETCH_TYPES";
|
|
175
|
+
})(APIKind || (APIKind = {}));
|
|
176
|
+
var _API = class _API extends Message {
|
|
177
|
+
constructor(content, kind) {
|
|
178
|
+
super("API", kind);
|
|
179
|
+
__publicField(this, "code");
|
|
180
|
+
__publicField(this, "payload");
|
|
181
|
+
const { code, payload } = content;
|
|
182
|
+
this.code = code;
|
|
183
|
+
this.payload = payload;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
__name(_API, "API");
|
|
187
|
+
var API = _API;
|
|
188
|
+
|
|
189
|
+
// packages/dts-plugin/src/server/message/API/UpdateSubscriber.ts
|
|
190
|
+
var _UpdateSubscriberAPI = class _UpdateSubscriberAPI extends API {
|
|
191
|
+
constructor(payload) {
|
|
192
|
+
super({
|
|
193
|
+
code: 0,
|
|
194
|
+
payload
|
|
195
|
+
}, APIKind.UPDATE_SUBSCRIBER);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
__name(_UpdateSubscriberAPI, "UpdateSubscriberAPI");
|
|
199
|
+
var UpdateSubscriberAPI = _UpdateSubscriberAPI;
|
|
200
|
+
|
|
201
|
+
// packages/dts-plugin/src/server/message/API/ReloadWebClient.ts
|
|
202
|
+
var _ReloadWebClientAPI = class _ReloadWebClientAPI extends API {
|
|
203
|
+
constructor(payload) {
|
|
204
|
+
super({
|
|
205
|
+
code: 0,
|
|
206
|
+
payload
|
|
207
|
+
}, APIKind.RELOAD_WEB_CLIENT);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
__name(_ReloadWebClientAPI, "ReloadWebClientAPI");
|
|
211
|
+
var ReloadWebClientAPI = _ReloadWebClientAPI;
|
|
212
|
+
|
|
213
|
+
// packages/dts-plugin/src/server/message/API/FetchTypes.ts
|
|
214
|
+
var _FetchTypesAPI = class _FetchTypesAPI extends API {
|
|
215
|
+
constructor(payload) {
|
|
216
|
+
super({
|
|
217
|
+
code: 0,
|
|
218
|
+
payload
|
|
219
|
+
}, APIKind.FETCH_TYPES);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
__name(_FetchTypesAPI, "FetchTypesAPI");
|
|
223
|
+
var FetchTypesAPI = _FetchTypesAPI;
|
|
224
|
+
|
|
225
|
+
// packages/dts-plugin/src/server/Publisher.ts
|
|
226
|
+
var _Publisher = class _Publisher {
|
|
227
|
+
constructor(ctx) {
|
|
228
|
+
__publicField(this, "_ip");
|
|
229
|
+
__publicField(this, "_name");
|
|
230
|
+
__publicField(this, "_remoteTypeTarPath");
|
|
231
|
+
__publicField(this, "_subscribers");
|
|
232
|
+
__publicField(this, "_ws");
|
|
233
|
+
__publicField(this, "dynamicRemoteMap");
|
|
234
|
+
this._name = ctx.name;
|
|
235
|
+
this._ip = ctx.ip;
|
|
236
|
+
this._remoteTypeTarPath = ctx.remoteTypeTarPath;
|
|
237
|
+
this._subscribers = /* @__PURE__ */ new Map();
|
|
238
|
+
this._ws = ctx.ws;
|
|
239
|
+
this.dynamicRemoteMap = /* @__PURE__ */ new Map();
|
|
240
|
+
}
|
|
241
|
+
get identifier() {
|
|
242
|
+
return getIdentifier({
|
|
243
|
+
name: this._name,
|
|
244
|
+
ip: this._ip
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
get name() {
|
|
248
|
+
return this._name;
|
|
249
|
+
}
|
|
250
|
+
get ip() {
|
|
251
|
+
return this._ip;
|
|
252
|
+
}
|
|
253
|
+
get remoteTypeTarPath() {
|
|
254
|
+
return this._remoteTypeTarPath;
|
|
255
|
+
}
|
|
256
|
+
get hasSubscribes() {
|
|
257
|
+
return Boolean(this._subscribers.size);
|
|
258
|
+
}
|
|
259
|
+
get subscribers() {
|
|
260
|
+
return this._subscribers;
|
|
261
|
+
}
|
|
262
|
+
addSubscriber(identifier, subscriber) {
|
|
263
|
+
fileLog(`${this.name} set subscriber: ${identifier}`, "Publisher", "info");
|
|
264
|
+
this._subscribers.set(identifier, subscriber);
|
|
265
|
+
}
|
|
266
|
+
removeSubscriber(identifier) {
|
|
267
|
+
if (this._subscribers.has(identifier)) {
|
|
268
|
+
fileLog(`${this.name} removeSubscriber: ${identifier}`, "Publisher", "warn");
|
|
269
|
+
this._subscribers.delete(identifier);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
notifySubscriber(subscriberIdentifier, options) {
|
|
273
|
+
const subscriber = this._subscribers.get(subscriberIdentifier);
|
|
274
|
+
if (!subscriber) {
|
|
275
|
+
fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${subscriberIdentifier}, does not exits`, "Publisher", "error");
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const api = new UpdateSubscriberAPI(options);
|
|
279
|
+
subscriber.send(JSON.stringify(api));
|
|
280
|
+
fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${JSON.stringify(subscriberIdentifier)}, message: ${JSON.stringify(api)}`, "Publisher", "info");
|
|
281
|
+
}
|
|
282
|
+
fetchRemoteTypes(options) {
|
|
283
|
+
fileLog(`[fetchRemoteTypes] ${this.name} fetchRemoteTypes, options: ${JSON.stringify(options)}, ws: ${Boolean(this._ws)}`, "Publisher", "info");
|
|
284
|
+
if (!this._ws) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const api = new FetchTypesAPI(options);
|
|
288
|
+
this._ws.send(JSON.stringify(api));
|
|
289
|
+
}
|
|
290
|
+
notifySubscribers(options) {
|
|
291
|
+
const api = new UpdateSubscriberAPI(options);
|
|
292
|
+
this.broadcast(api);
|
|
293
|
+
}
|
|
294
|
+
broadcast(message) {
|
|
295
|
+
if (this.hasSubscribes) {
|
|
296
|
+
this._subscribers.forEach((subscriber, key) => {
|
|
297
|
+
fileLog(`[BroadCast] ${this.name} notifySubscriber: ${key}, PID: ${process.pid}, message: ${JSON.stringify(message)}`, "Publisher", "info");
|
|
298
|
+
subscriber.send(JSON.stringify(message));
|
|
299
|
+
});
|
|
300
|
+
} else {
|
|
301
|
+
fileLog(`[BroadCast] ${this.name}'s subscribe is empty`, "Publisher", "warn");
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
close() {
|
|
305
|
+
this._ws = void 0;
|
|
306
|
+
this._subscribers.forEach((_subscriber, identifier) => {
|
|
307
|
+
fileLog(`[BroadCast] close ${this.name} remove: ${identifier}`, "Publisher", "warn");
|
|
308
|
+
this.removeSubscriber(identifier);
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
__name(_Publisher, "Publisher");
|
|
313
|
+
var Publisher = _Publisher;
|
|
314
|
+
|
|
315
|
+
// packages/dts-plugin/src/server/broker/Broker.ts
|
|
316
|
+
var _Broker = class _Broker {
|
|
317
|
+
constructor() {
|
|
318
|
+
__publicField(this, "_publisherMap", /* @__PURE__ */ new Map());
|
|
319
|
+
__publicField(this, "_webClientMap", /* @__PURE__ */ new Map());
|
|
320
|
+
__publicField(this, "_webSocketServer");
|
|
321
|
+
__publicField(this, "_secureWebSocketServer");
|
|
322
|
+
__publicField(this, "_tmpSubscriberShelter", /* @__PURE__ */ new Map());
|
|
323
|
+
__publicField(this, "_scheduleJob", null);
|
|
324
|
+
this._setSchedule();
|
|
325
|
+
this._startWsServer();
|
|
326
|
+
this._stopWhenSIGTERMOrSIGINT();
|
|
327
|
+
this._handleUnexpectedExit();
|
|
328
|
+
}
|
|
329
|
+
get hasPublishers() {
|
|
330
|
+
return Boolean(this._publisherMap.size);
|
|
331
|
+
}
|
|
332
|
+
_startWsServer() {
|
|
333
|
+
return __async(this, null, function* () {
|
|
334
|
+
const wsHandler = /* @__PURE__ */ __name((ws, req) => {
|
|
335
|
+
const { url: reqUrl = "" } = req;
|
|
336
|
+
const { query } = parse(reqUrl, true);
|
|
337
|
+
const { WEB_SOCKET_CONNECT_MAGIC_ID: WEB_SOCKET_CONNECT_MAGIC_ID2 } = query;
|
|
338
|
+
if (WEB_SOCKET_CONNECT_MAGIC_ID2 === _Broker.WEB_SOCKET_CONNECT_MAGIC_ID) {
|
|
339
|
+
ws.on("message", (message) => {
|
|
340
|
+
try {
|
|
341
|
+
const text = message.toString();
|
|
342
|
+
const action = JSON.parse(text);
|
|
343
|
+
fileLog(`${action == null ? void 0 : action.kind} action received `, "Broker", "info");
|
|
344
|
+
this._takeAction(action, ws);
|
|
345
|
+
} catch (error2) {
|
|
346
|
+
fileLog(`parse action message error: ${error2}`, "Broker", "error");
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
ws.on("error", (e) => {
|
|
350
|
+
fileLog(`parse action message error: ${e}`, "Broker", "error");
|
|
351
|
+
});
|
|
352
|
+
} else {
|
|
353
|
+
ws.send("Invalid CONNECT ID.");
|
|
354
|
+
fileLog("Invalid CONNECT ID.", "Broker", "warn");
|
|
355
|
+
ws.close();
|
|
356
|
+
}
|
|
357
|
+
}, "wsHandler");
|
|
358
|
+
const server = createServer();
|
|
359
|
+
this._webSocketServer = new WebSocket.Server({
|
|
360
|
+
noServer: true
|
|
361
|
+
});
|
|
362
|
+
this._webSocketServer.on("error", (err) => {
|
|
363
|
+
fileLog(`ws error:
|
|
364
|
+
${err.message}
|
|
365
|
+
${err.stack}`, "Broker", "error");
|
|
366
|
+
});
|
|
367
|
+
this._webSocketServer.on("listening", () => {
|
|
368
|
+
fileLog(`WebSocket server is listening on port ${_Broker.DEFAULT_WEB_SOCKET_PORT}`, "Broker", "info");
|
|
369
|
+
});
|
|
370
|
+
this._webSocketServer.on("connection", wsHandler);
|
|
371
|
+
this._webSocketServer.on("close", (code) => {
|
|
372
|
+
fileLog(`WebSocket Server Close with Code ${code}`, "Broker", "warn");
|
|
373
|
+
this._webSocketServer && this._webSocketServer.close();
|
|
374
|
+
this._webSocketServer = void 0;
|
|
375
|
+
});
|
|
376
|
+
server.on("upgrade", (req, socket, head) => {
|
|
377
|
+
var _a;
|
|
378
|
+
if (req.url) {
|
|
379
|
+
const { pathname } = parse(req.url);
|
|
380
|
+
if (pathname === "/") {
|
|
381
|
+
(_a = this._webSocketServer) == null ? void 0 : _a.handleUpgrade(req, socket, head, (ws) => {
|
|
382
|
+
var _a2;
|
|
383
|
+
(_a2 = this._webSocketServer) == null ? void 0 : _a2.emit("connection", ws, req);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
server.listen(_Broker.DEFAULT_WEB_SOCKET_PORT);
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
_takeAction(action, client) {
|
|
392
|
+
return __async(this, null, function* () {
|
|
393
|
+
const { kind, payload } = action;
|
|
394
|
+
if (kind === ActionKind.ADD_PUBLISHER) {
|
|
395
|
+
yield this._addPublisher(payload, client);
|
|
396
|
+
}
|
|
397
|
+
if (kind === ActionKind.UPDATE_PUBLISHER) {
|
|
398
|
+
yield this._updatePublisher(payload, client);
|
|
399
|
+
}
|
|
400
|
+
if (kind === ActionKind.ADD_SUBSCRIBER) {
|
|
401
|
+
yield this._addSubscriber(payload, client);
|
|
402
|
+
}
|
|
403
|
+
if (kind === ActionKind.EXIT_SUBSCRIBER) {
|
|
404
|
+
yield this._removeSubscriber(payload, client);
|
|
405
|
+
}
|
|
406
|
+
if (kind === ActionKind.EXIT_PUBLISHER) {
|
|
407
|
+
yield this._removePublisher(payload, client);
|
|
408
|
+
}
|
|
409
|
+
if (kind === ActionKind.ADD_WEB_CLIENT) {
|
|
410
|
+
yield this._addWebClient(payload, client);
|
|
411
|
+
}
|
|
412
|
+
if (kind === ActionKind.NOTIFY_WEB_CLIENT) {
|
|
413
|
+
yield this._notifyWebClient(payload, client);
|
|
414
|
+
}
|
|
415
|
+
if (kind === ActionKind.FETCH_TYPES) {
|
|
416
|
+
yield this._fetchTypes(payload, client);
|
|
417
|
+
}
|
|
418
|
+
if (kind === ActionKind.ADD_DYNAMIC_REMOTE) {
|
|
419
|
+
this._addDynamicRemote(payload);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
_addPublisher(context, client) {
|
|
424
|
+
return __async(this, null, function* () {
|
|
425
|
+
const { name, ip, remoteTypeTarPath } = context != null ? context : {};
|
|
426
|
+
const identifier = getIdentifier({
|
|
427
|
+
name,
|
|
428
|
+
ip
|
|
429
|
+
});
|
|
430
|
+
if (this._publisherMap.has(identifier)) {
|
|
431
|
+
fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} has been added, this action will be ignored`, "Broker", "warn");
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
try {
|
|
435
|
+
const publisher = new Publisher({
|
|
436
|
+
name,
|
|
437
|
+
ip,
|
|
438
|
+
remoteTypeTarPath,
|
|
439
|
+
ws: client
|
|
440
|
+
});
|
|
441
|
+
this._publisherMap.set(identifier, publisher);
|
|
442
|
+
fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} Adding Publisher Succeed`, "Broker", "info");
|
|
443
|
+
const tmpSubScribers = this._getTmpSubScribers(identifier);
|
|
444
|
+
if (tmpSubScribers) {
|
|
445
|
+
fileLog(`[${ActionKind.ADD_PUBLISHER}] consumeTmpSubscriber set ${publisher.name}\u2019s subscribers `, "Broker", "info");
|
|
446
|
+
this._consumeTmpSubScribers(publisher, tmpSubScribers);
|
|
447
|
+
this._clearTmpSubScriberRelation(identifier);
|
|
448
|
+
}
|
|
449
|
+
} catch (err) {
|
|
450
|
+
const msg = error(err, ActionKind.ADD_PUBLISHER, "Broker");
|
|
451
|
+
client.send(msg);
|
|
452
|
+
client.close();
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
_updatePublisher(context, client) {
|
|
457
|
+
return __async(this, null, function* () {
|
|
458
|
+
const { name, updateMode, updateKind, updateSourcePaths, remoteTypeTarPath, ip } = context != null ? context : {};
|
|
459
|
+
const identifier = getIdentifier({
|
|
460
|
+
name,
|
|
461
|
+
ip
|
|
462
|
+
});
|
|
463
|
+
if (!this._publisherMap.has(identifier)) {
|
|
464
|
+
fileLog(`[${ActionKind.UPDATE_PUBLISHER}] ${identifier} has not been started, this action will be ignored
|
|
465
|
+
this._publisherMap: ${JSON.stringify(this._publisherMap.entries())}
|
|
466
|
+
`, "Broker", "warn");
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
try {
|
|
470
|
+
const publisher = this._publisherMap.get(identifier);
|
|
471
|
+
fileLog(
|
|
472
|
+
// eslint-disable-next-line max-len
|
|
473
|
+
`[${ActionKind.UPDATE_PUBLISHER}] ${identifier} update, and notify subscribers to update`,
|
|
474
|
+
"Broker",
|
|
475
|
+
"info"
|
|
476
|
+
);
|
|
477
|
+
if (publisher) {
|
|
478
|
+
publisher.notifySubscribers({
|
|
479
|
+
remoteTypeTarPath,
|
|
480
|
+
name,
|
|
481
|
+
updateMode,
|
|
482
|
+
updateKind,
|
|
483
|
+
updateSourcePaths: updateSourcePaths || []
|
|
484
|
+
});
|
|
485
|
+
this._publisherMap.forEach((p) => {
|
|
486
|
+
if (p.name === publisher.name) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
const dynamicRemoteInfo = p.dynamicRemoteMap.get(identifier);
|
|
490
|
+
if (dynamicRemoteInfo) {
|
|
491
|
+
fileLog(
|
|
492
|
+
// eslint-disable-next-line max-len
|
|
493
|
+
`dynamicRemoteInfo: ${JSON.stringify(dynamicRemoteInfo)}, identifier:${identifier} publish: ${p.name}`,
|
|
494
|
+
"Broker",
|
|
495
|
+
"info"
|
|
496
|
+
);
|
|
497
|
+
p.fetchRemoteTypes({
|
|
498
|
+
remoteInfo: dynamicRemoteInfo,
|
|
499
|
+
once: false
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
} catch (err) {
|
|
505
|
+
const msg = error(err, ActionKind.UPDATE_PUBLISHER, "Broker");
|
|
506
|
+
client.send(msg);
|
|
507
|
+
client.close();
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
_fetchTypes(context, _client) {
|
|
512
|
+
return __async(this, null, function* () {
|
|
513
|
+
const { name, ip, remoteInfo } = context != null ? context : {};
|
|
514
|
+
const identifier = getIdentifier({
|
|
515
|
+
name,
|
|
516
|
+
ip
|
|
517
|
+
});
|
|
518
|
+
try {
|
|
519
|
+
const publisher = this._publisherMap.get(identifier);
|
|
520
|
+
fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types`, "Broker", "info");
|
|
521
|
+
if (publisher) {
|
|
522
|
+
publisher.fetchRemoteTypes({
|
|
523
|
+
remoteInfo,
|
|
524
|
+
once: true
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
} catch (err) {
|
|
528
|
+
fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types fail , error info: ${err}`, "Broker", "error");
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
_addDynamicRemote(context) {
|
|
533
|
+
const { name, ip, remoteInfo, remoteIp } = context != null ? context : {};
|
|
534
|
+
const identifier = getIdentifier({
|
|
535
|
+
name,
|
|
536
|
+
ip
|
|
537
|
+
});
|
|
538
|
+
const publisher = this._publisherMap.get(identifier);
|
|
539
|
+
const remoteId = getIdentifier({
|
|
540
|
+
name: remoteInfo.name,
|
|
541
|
+
ip: remoteIp
|
|
542
|
+
});
|
|
543
|
+
fileLog(`[${ActionKind.ADD_DYNAMIC_REMOTE}] identifier:${identifier},publisher: ${publisher.name}, remoteId:${remoteId}`, "Broker", "error");
|
|
544
|
+
if (!publisher || publisher.dynamicRemoteMap.has(remoteId)) {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
publisher.dynamicRemoteMap.set(remoteId, remoteInfo);
|
|
548
|
+
}
|
|
549
|
+
// app1 consumes provider1,provider2. Dependencies at this time: publishers: [provider1, provider2], subscriberName: app1
|
|
550
|
+
// provider1 is app1's remote
|
|
551
|
+
_addSubscriber(context, client) {
|
|
552
|
+
return __async(this, null, function* () {
|
|
553
|
+
const { publishers, name: subscriberName } = context != null ? context : {};
|
|
554
|
+
publishers.forEach((publisher) => {
|
|
555
|
+
const { name, ip } = publisher;
|
|
556
|
+
const identifier = getIdentifier({
|
|
557
|
+
name,
|
|
558
|
+
ip
|
|
559
|
+
});
|
|
560
|
+
if (!this._publisherMap.has(identifier)) {
|
|
561
|
+
fileLog(`[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has not been started, ${subscriberName} will add the relation to tmp shelter`, "Broker", "warn");
|
|
562
|
+
this._addTmpSubScriberRelation({
|
|
563
|
+
name: getIdentifier({
|
|
564
|
+
name: context.name,
|
|
565
|
+
ip: context.ip
|
|
566
|
+
}),
|
|
567
|
+
client
|
|
568
|
+
}, publisher);
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
try {
|
|
572
|
+
const registeredPublisher = this._publisherMap.get(identifier);
|
|
573
|
+
if (registeredPublisher) {
|
|
574
|
+
registeredPublisher.addSubscriber(getIdentifier({
|
|
575
|
+
name: subscriberName,
|
|
576
|
+
ip: context.ip
|
|
577
|
+
}), client);
|
|
578
|
+
fileLog(
|
|
579
|
+
// eslint-disable-next-line @ies/eden/max-calls-in-template
|
|
580
|
+
`[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has been started, Adding Subscriber ${subscriberName} Succeed, this.__publisherMap are: ${JSON.stringify(Array.from(this._publisherMap.entries()))}`,
|
|
581
|
+
"Broker",
|
|
582
|
+
"info"
|
|
583
|
+
);
|
|
584
|
+
registeredPublisher.notifySubscriber(getIdentifier({
|
|
585
|
+
name: subscriberName,
|
|
586
|
+
ip: context.ip
|
|
587
|
+
}), {
|
|
588
|
+
updateKind: UpdateKind.UPDATE_TYPE,
|
|
589
|
+
updateMode: UpdateMode.PASSIVE,
|
|
590
|
+
updateSourcePaths: [
|
|
591
|
+
registeredPublisher.name
|
|
592
|
+
],
|
|
593
|
+
remoteTypeTarPath: registeredPublisher.remoteTypeTarPath,
|
|
594
|
+
name: registeredPublisher.name
|
|
595
|
+
});
|
|
596
|
+
fileLog(
|
|
597
|
+
// eslint-disable-next-line @ies/eden/max-calls-in-template
|
|
598
|
+
`[${ActionKind.ADD_SUBSCRIBER}]: notifySubscriber Subscriber ${subscriberName}, updateMode: "PASSIVE", updateSourcePaths: ${registeredPublisher.name}`,
|
|
599
|
+
"Broker",
|
|
600
|
+
"info"
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
} catch (err) {
|
|
604
|
+
const msg = error(err, ActionKind.ADD_SUBSCRIBER, "Broker");
|
|
605
|
+
client.send(msg);
|
|
606
|
+
client.close();
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
// Trigger while consumer exit
|
|
612
|
+
_removeSubscriber(context, client) {
|
|
613
|
+
return __async(this, null, function* () {
|
|
614
|
+
const { publishers } = context != null ? context : {};
|
|
615
|
+
const subscriberIdentifier = getIdentifier({
|
|
616
|
+
name: context == null ? void 0 : context.name,
|
|
617
|
+
ip: context == null ? void 0 : context.ip
|
|
618
|
+
});
|
|
619
|
+
publishers.forEach((publisher) => {
|
|
620
|
+
const { name, ip } = publisher;
|
|
621
|
+
const identifier = getIdentifier({
|
|
622
|
+
name,
|
|
623
|
+
ip
|
|
624
|
+
});
|
|
625
|
+
const registeredPublisher = this._publisherMap.get(identifier);
|
|
626
|
+
if (!registeredPublisher) {
|
|
627
|
+
fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} does not exit `, "Broker", "warn");
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
try {
|
|
631
|
+
fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} will exit `, "Broker", "INFO");
|
|
632
|
+
registeredPublisher.removeSubscriber(subscriberIdentifier);
|
|
633
|
+
this._clearTmpSubScriberRelation(identifier);
|
|
634
|
+
if (!registeredPublisher.hasSubscribes) {
|
|
635
|
+
this._publisherMap.delete(identifier);
|
|
636
|
+
}
|
|
637
|
+
if (!this.hasPublishers) {
|
|
638
|
+
this.exit();
|
|
639
|
+
}
|
|
640
|
+
} catch (err) {
|
|
641
|
+
const msg = error(err, ActionKind.EXIT_SUBSCRIBER, "Broker");
|
|
642
|
+
client.send(msg);
|
|
643
|
+
client.close();
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
_removePublisher(context, client) {
|
|
649
|
+
return __async(this, null, function* () {
|
|
650
|
+
const { name, ip } = context != null ? context : {};
|
|
651
|
+
const identifier = getIdentifier({
|
|
652
|
+
name,
|
|
653
|
+
ip
|
|
654
|
+
});
|
|
655
|
+
const publisher = this._publisherMap.get(identifier);
|
|
656
|
+
if (!publisher) {
|
|
657
|
+
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier}} has not been added, this action will be ingored`, "Broker", "warn");
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
try {
|
|
661
|
+
const { subscribers } = publisher;
|
|
662
|
+
subscribers.forEach((subscriber, subscriberIdentifier) => {
|
|
663
|
+
this._addTmpSubScriberRelation({
|
|
664
|
+
name: subscriberIdentifier,
|
|
665
|
+
client: subscriber
|
|
666
|
+
}, {
|
|
667
|
+
name: publisher.name,
|
|
668
|
+
ip: publisher.ip
|
|
669
|
+
});
|
|
670
|
+
fileLog(
|
|
671
|
+
// eslint-disable-next-line max-len
|
|
672
|
+
`[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removing , subscriber: ${subscriberIdentifier} will be add tmpSubScriberRelation`,
|
|
673
|
+
"Broker",
|
|
674
|
+
"info"
|
|
675
|
+
);
|
|
676
|
+
});
|
|
677
|
+
this._publisherMap.delete(identifier);
|
|
678
|
+
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removed `, "Broker", "info");
|
|
679
|
+
if (!this.hasPublishers) {
|
|
680
|
+
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: _publisherMap is empty, all server will exit `, "Broker", "warn");
|
|
681
|
+
this.exit();
|
|
682
|
+
}
|
|
683
|
+
} catch (err) {
|
|
684
|
+
const msg = error(err, ActionKind.EXIT_PUBLISHER, "Broker");
|
|
685
|
+
client.send(msg);
|
|
686
|
+
client.close();
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
_addWebClient(context, client) {
|
|
691
|
+
return __async(this, null, function* () {
|
|
692
|
+
const { name } = context != null ? context : {};
|
|
693
|
+
const identifier = getIdentifier({
|
|
694
|
+
name
|
|
695
|
+
});
|
|
696
|
+
if (this._webClientMap.has(identifier)) {
|
|
697
|
+
fileLog(`${identifier}} has been added, this action will override prev WebClient`, "Broker", "warn");
|
|
698
|
+
}
|
|
699
|
+
try {
|
|
700
|
+
this._webClientMap.set(identifier, client);
|
|
701
|
+
fileLog(`${identifier} adding WebClient Succeed`, "Broker", "info");
|
|
702
|
+
} catch (err) {
|
|
703
|
+
const msg = error(err, ActionKind.ADD_WEB_CLIENT, "Broker");
|
|
704
|
+
client.send(msg);
|
|
705
|
+
client.close();
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
_notifyWebClient(context, client) {
|
|
710
|
+
return __async(this, null, function* () {
|
|
711
|
+
const { name, updateMode } = context != null ? context : {};
|
|
712
|
+
const identifier = getIdentifier({
|
|
713
|
+
name
|
|
714
|
+
});
|
|
715
|
+
const webClient = this._webClientMap.get(identifier);
|
|
716
|
+
if (!webClient) {
|
|
717
|
+
fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] ${identifier} has not been added, this action will be ignored`, "Broker", "warn");
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
try {
|
|
721
|
+
const api = new ReloadWebClientAPI({
|
|
722
|
+
name,
|
|
723
|
+
updateMode
|
|
724
|
+
});
|
|
725
|
+
webClient.send(JSON.stringify(api));
|
|
726
|
+
fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] Notify ${name} WebClient Succeed`, "Broker", "info");
|
|
727
|
+
} catch (err) {
|
|
728
|
+
const msg = error(err, ActionKind.NOTIFY_WEB_CLIENT, "Broker");
|
|
729
|
+
client.send(msg);
|
|
730
|
+
client.close();
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
// app1 consumes provider1, and provider1 not launch. this._tmpSubscriberShelter at this time: {provider1: Map{subscribers: Map{app1: app1+ip+client'}, timestamp: 'xx'} }
|
|
735
|
+
_addTmpSubScriberRelation(subscriber, publisher) {
|
|
736
|
+
const publisherIdentifier = getIdentifier({
|
|
737
|
+
name: publisher.name,
|
|
738
|
+
ip: publisher.ip
|
|
739
|
+
});
|
|
740
|
+
const subscriberIdentifier = subscriber.name;
|
|
741
|
+
const shelter = this._tmpSubscriberShelter.get(publisherIdentifier);
|
|
742
|
+
if (!shelter) {
|
|
743
|
+
const map = /* @__PURE__ */ new Map();
|
|
744
|
+
map.set(subscriberIdentifier, subscriber);
|
|
745
|
+
this._tmpSubscriberShelter.set(publisherIdentifier, {
|
|
746
|
+
subscribers: map,
|
|
747
|
+
timestamp: Date.now()
|
|
748
|
+
});
|
|
749
|
+
fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier}'s subscriber has ${subscriberIdentifier} `, "Broker", "info");
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
const tmpSubScriberShelterSubscriber = shelter.subscribers.get(subscriberIdentifier);
|
|
753
|
+
if (tmpSubScriberShelterSubscriber) {
|
|
754
|
+
fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier} and ${subscriberIdentifier} relation has been added`, "Broker", "warn");
|
|
755
|
+
shelter.subscribers.set(subscriberIdentifier, subscriber);
|
|
756
|
+
shelter.timestamp = Date.now();
|
|
757
|
+
} else {
|
|
758
|
+
fileLog(
|
|
759
|
+
// eslint-disable-next-line max-len
|
|
760
|
+
`AddTmpSubscriberLog ${publisherIdentifier}'s shelter has been added, update shelter.subscribers ${subscriberIdentifier}`,
|
|
761
|
+
"Broker",
|
|
762
|
+
"warn"
|
|
763
|
+
);
|
|
764
|
+
shelter.subscribers.set(subscriberIdentifier, subscriber);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
_getTmpSubScribers(publisherIdentifier) {
|
|
768
|
+
var _a;
|
|
769
|
+
return (_a = this._tmpSubscriberShelter.get(publisherIdentifier)) == null ? void 0 : _a.subscribers;
|
|
770
|
+
}
|
|
771
|
+
// after adding publisher, it will change the temp subscriber to regular subscriber
|
|
772
|
+
_consumeTmpSubScribers(publisher, tmpSubScribers) {
|
|
773
|
+
tmpSubScribers.forEach((tmpSubScriber, identifier) => {
|
|
774
|
+
fileLog(`notifyTmpSubScribers ${publisher.name} will be add a subscriber: ${identifier} `, "Broker", "warn");
|
|
775
|
+
publisher.addSubscriber(identifier, tmpSubScriber.client);
|
|
776
|
+
publisher.notifySubscriber(identifier, {
|
|
777
|
+
updateKind: UpdateKind.UPDATE_TYPE,
|
|
778
|
+
updateMode: UpdateMode.PASSIVE,
|
|
779
|
+
updateSourcePaths: [
|
|
780
|
+
publisher.name
|
|
781
|
+
],
|
|
782
|
+
remoteTypeTarPath: publisher.remoteTypeTarPath,
|
|
783
|
+
name: publisher.name
|
|
784
|
+
});
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
_clearTmpSubScriberRelation(identifier) {
|
|
788
|
+
this._tmpSubscriberShelter.delete(identifier);
|
|
789
|
+
}
|
|
790
|
+
_clearTmpSubScriberRelations() {
|
|
791
|
+
this._tmpSubscriberShelter.clear();
|
|
792
|
+
}
|
|
793
|
+
_disconnect() {
|
|
794
|
+
this._publisherMap.forEach((publisher) => {
|
|
795
|
+
publisher.close();
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
// Every day on 0/6/9/12/15//18, Publishers that have not been connected within 1.5 hours will be cleared regularly.
|
|
799
|
+
// If process.env.FEDERATION_SERVER_TEST is set, it will be read at a specified time.
|
|
800
|
+
_setSchedule() {
|
|
801
|
+
const rule = new schedule.RecurrenceRule();
|
|
802
|
+
if (Number(process.env["FEDERATION_SERVER_TEST"])) {
|
|
803
|
+
const interval = Number(process.env["FEDERATION_SERVER_TEST"]) / 1e3;
|
|
804
|
+
const second = [];
|
|
805
|
+
for (let i = 0; i < 60; i = i + interval) {
|
|
806
|
+
second.push(i);
|
|
807
|
+
}
|
|
808
|
+
rule.second = second;
|
|
809
|
+
} else {
|
|
810
|
+
rule.second = 0;
|
|
811
|
+
rule.hour = [
|
|
812
|
+
0,
|
|
813
|
+
3,
|
|
814
|
+
6,
|
|
815
|
+
9,
|
|
816
|
+
12,
|
|
817
|
+
15,
|
|
818
|
+
18
|
|
819
|
+
];
|
|
820
|
+
rule.minute = 0;
|
|
821
|
+
}
|
|
822
|
+
const serverTest = Number(process.env["FEDERATION_SERVER_TEST"]);
|
|
823
|
+
this._scheduleJob = schedule.scheduleJob(rule, () => {
|
|
824
|
+
this._tmpSubscriberShelter.forEach((tmpSubscriber, identifier) => {
|
|
825
|
+
fileLog(` _clearTmpSubScriberRelation ${identifier}, ${Date.now() - tmpSubscriber.timestamp >= (process.env["GARFISH_MODULE_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)}`, "Broker", "info");
|
|
826
|
+
if (Date.now() - tmpSubscriber.timestamp >= (process.env["FEDERATION_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)) {
|
|
827
|
+
this._clearTmpSubScriberRelation(identifier);
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
_clearSchedule() {
|
|
833
|
+
if (!this._scheduleJob) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
this._scheduleJob.cancel();
|
|
837
|
+
this._scheduleJob = null;
|
|
838
|
+
}
|
|
839
|
+
_stopWhenSIGTERMOrSIGINT() {
|
|
840
|
+
process.on("SIGTERM", () => {
|
|
841
|
+
this.exit();
|
|
842
|
+
});
|
|
843
|
+
process.on("SIGINT", () => {
|
|
844
|
+
this.exit();
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
_handleUnexpectedExit() {
|
|
848
|
+
process.on("unhandledRejection", (error2) => {
|
|
849
|
+
console.error("Unhandled Rejection Error: ", error2);
|
|
850
|
+
fileLog(`Unhandled Rejection Error: ${error2}`, "Broker", "fatal");
|
|
851
|
+
process.exit(1);
|
|
852
|
+
});
|
|
853
|
+
process.on("uncaughtException", (error2) => {
|
|
854
|
+
console.error("Unhandled Exception Error: ", error2);
|
|
855
|
+
fileLog(`Unhandled Rejection Error: ${error2}`, "Broker", "fatal");
|
|
856
|
+
process.exit(1);
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
start() {
|
|
860
|
+
return __async(this, null, function* () {
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
exit() {
|
|
864
|
+
const brokerExitLog = new BrokerExitLog();
|
|
865
|
+
this.broadcast(JSON.stringify(brokerExitLog));
|
|
866
|
+
this._disconnect();
|
|
867
|
+
this._clearSchedule();
|
|
868
|
+
this._clearTmpSubScriberRelations();
|
|
869
|
+
this._webSocketServer && this._webSocketServer.close();
|
|
870
|
+
this._secureWebSocketServer && this._secureWebSocketServer.close();
|
|
871
|
+
process.exit(0);
|
|
872
|
+
}
|
|
873
|
+
broadcast(message) {
|
|
874
|
+
var _a, _b;
|
|
875
|
+
fileLog(`[broadcast] exit info : ${JSON.stringify(message)}`, "Broker", "warn");
|
|
876
|
+
(_a = this._webSocketServer) == null ? void 0 : _a.clients.forEach((client) => {
|
|
877
|
+
client.send(JSON.stringify(message));
|
|
878
|
+
});
|
|
879
|
+
(_b = this._secureWebSocketServer) == null ? void 0 : _b.clients.forEach((client) => {
|
|
880
|
+
client.send(JSON.stringify(message));
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
__name(_Broker, "Broker");
|
|
885
|
+
__publicField(_Broker, "WEB_SOCKET_CONNECT_MAGIC_ID", WEB_SOCKET_CONNECT_MAGIC_ID);
|
|
886
|
+
__publicField(_Broker, "DEFAULT_WEB_SOCKET_PORT", DEFAULT_WEB_SOCKET_PORT);
|
|
887
|
+
__publicField(_Broker, "DEFAULT_SECURE_WEB_SOCKET_PORT", 16324);
|
|
888
|
+
__publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
|
|
889
|
+
var Broker = _Broker;
|
|
890
|
+
|
|
891
|
+
export {
|
|
892
|
+
APIKind,
|
|
893
|
+
LogKind,
|
|
894
|
+
fileLog,
|
|
895
|
+
getIPV4,
|
|
896
|
+
getIdentifier,
|
|
897
|
+
fib,
|
|
898
|
+
getFreePort,
|
|
899
|
+
Broker
|
|
900
|
+
};
|