systemlynx 1.10.7 → 1.11.8
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/package.json +1 -1
- package/systemlynx/Client/Client.js +19 -13
- package/systemlynx/Client/components/ClientModule.js +9 -5
- package/systemlynx/Client/components/ServiceRequestHandler.js +4 -2
- package/systemlynx/Client/components/loadConnectionData.js +1 -1
- package/systemlynx/ServerManager/ServerManager.js +1 -1
- package/systemlynx/ServerManager/components/Router.js +1 -1
- package/systemlynx/Service/Service.js +1 -1
package/package.json
CHANGED
|
@@ -32,21 +32,27 @@ module.exports = function createClient(httpClient = HttpClient(), systemContext)
|
|
|
32
32
|
Client.cachedServices[connData.serviceUrl] = Service;
|
|
33
33
|
|
|
34
34
|
Service.resetConnection = async (cb) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
try {
|
|
36
|
+
const { modules, host, port, namespace } = await loadConnectionData(
|
|
37
|
+
httpClient,
|
|
38
|
+
connData.serviceUrl
|
|
39
|
+
);
|
|
40
|
+
SocketDispatcher.apply(Service, [namespace, events, systemContext]);
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
modules.forEach(({ namespace, route, name }) => {
|
|
43
|
+
if (Service[name]) {
|
|
44
|
+
Service[name].__setConnection(host, port, route, namespace);
|
|
45
|
+
Service[name].emit("reconnect");
|
|
46
|
+
}
|
|
47
|
+
});
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
Service.emit("reconnect");
|
|
50
|
+
if (typeof cb === "function") cb();
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(
|
|
53
|
+
`[SystemLynx][Client]: Failed to reconnect service @${connData.serviceUrl}`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
50
56
|
};
|
|
51
57
|
|
|
52
58
|
connData.modules.forEach(
|
|
@@ -22,12 +22,16 @@ module.exports = function SystemLynxClientModule(
|
|
|
22
22
|
ClientModule.__setConnection(host, port, route, namespace);
|
|
23
23
|
|
|
24
24
|
const reconnectModule = async (cb) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
try {
|
|
26
|
+
const url = connectionData.serviceUrl + `?modules=${name}`;
|
|
27
|
+
const { modules, port, host } = await loadConnectionData(url);
|
|
28
|
+
const { namespace, route } = modules[0];
|
|
29
|
+
ClientModule.__setConnection(host, port, route, namespace);
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
if (typeof cb === "function") cb();
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(`[SystemLynx][ClientModule]: Failed to reconnect service @${url}`);
|
|
34
|
+
}
|
|
31
35
|
};
|
|
32
36
|
const protocol = getProtocol(serviceUrl);
|
|
33
37
|
methods.forEach(({ method, fn }) => {
|
|
@@ -58,11 +58,13 @@ module.exports = function ServiceRequestHandler(
|
|
|
58
58
|
if (err.SystemLynxService) {
|
|
59
59
|
cb(err);
|
|
60
60
|
} else if (errCount <= 3) {
|
|
61
|
-
console.log(err);
|
|
62
61
|
errCount++;
|
|
63
62
|
if (reconnectModule) reconnectModule(() => tryRequest(cb, errCount));
|
|
64
63
|
else Service.resetConnection(() => tryRequest(cb, errCount));
|
|
65
|
-
} else
|
|
64
|
+
} else {
|
|
65
|
+
console.error(`[SystemLynx][ServiceRequestHandler][Error]: ${err.message}\n`);
|
|
66
|
+
console.error(err);
|
|
67
|
+
}
|
|
66
68
|
};
|
|
67
69
|
|
|
68
70
|
return new Promise((resolve, reject) =>
|
|
@@ -14,7 +14,7 @@ module.exports = function loadConnectionData(
|
|
|
14
14
|
setTimeout(() => getData(resolve, reject), errors.length * wait);
|
|
15
15
|
else {
|
|
16
16
|
console.error(
|
|
17
|
-
`[SystemLynx][Client]
|
|
17
|
+
`[SystemLynx][Client]: Failed to load Service @${url} after ${errors.length} attempts.\n`
|
|
18
18
|
);
|
|
19
19
|
reject(err);
|
|
20
20
|
}
|
|
@@ -78,7 +78,7 @@ module.exports = function createServerManager(customServer, customWebSocketServe
|
|
|
78
78
|
return new Promise((resolve) => {
|
|
79
79
|
const _server = ssl ? createSSLServer(server, ssl) : server;
|
|
80
80
|
_server.listen(port, () => {
|
|
81
|
-
console.log(`[SystemLynx][Service]: Listening on ${serviceUrl}`);
|
|
81
|
+
console.log(`[SystemLynx][Service]: Listening on ${serviceUrl}\n`);
|
|
82
82
|
moduleQueue.forEach(({ name, Module, reserved_methods }) =>
|
|
83
83
|
ServerManager.addModule(name, Module, reserved_methods)
|
|
84
84
|
);
|
|
@@ -69,7 +69,7 @@ module.exports = function createRouter(server, config) {
|
|
|
69
69
|
|
|
70
70
|
if (typeof Module[fn] !== "function")
|
|
71
71
|
return sendResponse({
|
|
72
|
-
message: `[SystemLynx][
|
|
72
|
+
message: `[SystemLynx][Router][Error]:${module_name}.${fn} method not found`,
|
|
73
73
|
status: 404,
|
|
74
74
|
});
|
|
75
75
|
|
|
@@ -42,7 +42,7 @@ module.exports = function createService(
|
|
|
42
42
|
|
|
43
43
|
if (typeof constructor === "function") {
|
|
44
44
|
if (constructor.constructor.name === "AsyncFunction")
|
|
45
|
-
throw `[SystemLynx][
|
|
45
|
+
throw `[SystemLynx][Service][Error]: Module(name, constructor) function cannot receive an async function as the constructor`;
|
|
46
46
|
|
|
47
47
|
const Module = createDispatcher.apply({ ...systemContext, before }, [
|
|
48
48
|
undefined,
|