@cadenza.io/service 2.3.1 → 2.3.2
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/index.js +34 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1851,12 +1851,23 @@ var SocketController = class _SocketController {
|
|
|
1851
1851
|
CadenzaService.createMetaTask(
|
|
1852
1852
|
"Connect to socket server",
|
|
1853
1853
|
(ctx) => {
|
|
1854
|
-
const {
|
|
1854
|
+
const {
|
|
1855
|
+
serviceInstanceId,
|
|
1856
|
+
communicationTypes,
|
|
1857
|
+
serviceName,
|
|
1858
|
+
serviceAddress,
|
|
1859
|
+
servicePort,
|
|
1860
|
+
protocol
|
|
1861
|
+
} = ctx;
|
|
1855
1862
|
const socketProtocol = protocol === "https" ? "wss" : "ws";
|
|
1856
1863
|
const port = protocol === "https" ? 443 : servicePort;
|
|
1857
1864
|
const URL = `${socketProtocol}://${serviceAddress}:${port}`;
|
|
1858
1865
|
const fetchId = `${serviceAddress}_${port}`;
|
|
1859
1866
|
let handshake = false;
|
|
1867
|
+
if (CadenzaService.get(`Socket handshake with ${URL}`)) {
|
|
1868
|
+
console.error("Socket client already exists", URL);
|
|
1869
|
+
return;
|
|
1870
|
+
}
|
|
1860
1871
|
const socket = io(URL, {
|
|
1861
1872
|
reconnection: true,
|
|
1862
1873
|
reconnectionAttempts: 5,
|
|
@@ -1944,7 +1955,7 @@ var SocketController = class _SocketController {
|
|
|
1944
1955
|
{ error: err.message, serviceName, socketId: socket.id, URL },
|
|
1945
1956
|
"error"
|
|
1946
1957
|
);
|
|
1947
|
-
CadenzaService.emit(
|
|
1958
|
+
CadenzaService.emit(`meta.socket_client.connect_error:${fetchId}`, err);
|
|
1948
1959
|
});
|
|
1949
1960
|
socket.on("reconnect_attempt", (attempt) => {
|
|
1950
1961
|
CadenzaService.log(`Reconnect attempt: ${attempt}`);
|
|
@@ -1985,8 +1996,8 @@ var SocketController = class _SocketController {
|
|
|
1985
1996
|
handshake = false;
|
|
1986
1997
|
});
|
|
1987
1998
|
socket.connect();
|
|
1988
|
-
CadenzaService.
|
|
1989
|
-
`
|
|
1999
|
+
const handshakeTask = CadenzaService.createMetaTask(
|
|
2000
|
+
`Socket handshake with ${URL}`,
|
|
1990
2001
|
async () => {
|
|
1991
2002
|
if (handshake) return;
|
|
1992
2003
|
handshake = true;
|
|
@@ -2020,7 +2031,7 @@ var SocketController = class _SocketController {
|
|
|
2020
2031
|
"Handshakes with socket server"
|
|
2021
2032
|
).doOn(`meta.socket_client.connected:${fetchId}`);
|
|
2022
2033
|
const delegateTask = CadenzaService.createMetaTask(
|
|
2023
|
-
`Delegate flow to ${URL}`,
|
|
2034
|
+
`Delegate flow to Socket service ${URL}`,
|
|
2024
2035
|
async (ctx2, emit) => {
|
|
2025
2036
|
if (ctx2.__remoteRoutineName === void 0) {
|
|
2026
2037
|
return;
|
|
@@ -2053,7 +2064,7 @@ var SocketController = class _SocketController {
|
|
|
2053
2064
|
`Delegate flow to service ${serviceName} with address ${URL}`
|
|
2054
2065
|
).doOn(`meta.service_registry.selected_instance_for_socket:${fetchId}`).attachSignal("meta.socket_client.delegated");
|
|
2055
2066
|
const transmitTask = CadenzaService.createMetaTask(
|
|
2056
|
-
`Transmit signal to ${URL}`,
|
|
2067
|
+
`Transmit signal to socket server ${URL}`,
|
|
2057
2068
|
async (ctx2, emit) => {
|
|
2058
2069
|
if (ctx2.__signalName === void 0) {
|
|
2059
2070
|
return;
|
|
@@ -2075,16 +2086,31 @@ var SocketController = class _SocketController {
|
|
|
2075
2086
|
).doOn(`meta.service_registry.selected_instance_for_socket:${fetchId}`).attachSignal("meta.socket_client.transmitted");
|
|
2076
2087
|
CadenzaService.createEphemeralMetaTask(
|
|
2077
2088
|
`Shutdown SocketClient ${URL}`,
|
|
2078
|
-
() => {
|
|
2089
|
+
(ctx2, emit) => {
|
|
2090
|
+
CadenzaService.log("Shutting down socket client", { URL, serviceName });
|
|
2079
2091
|
socket?.close();
|
|
2092
|
+
handshakeTask.destroy();
|
|
2080
2093
|
delegateTask.destroy();
|
|
2081
2094
|
transmitTask.destroy();
|
|
2095
|
+
emit(`meta.fetch.handshake_requested:${fetchId}`, {
|
|
2096
|
+
serviceInstanceId,
|
|
2097
|
+
serviceName,
|
|
2098
|
+
communicationTypes,
|
|
2099
|
+
serviceAddress,
|
|
2100
|
+
servicePort,
|
|
2101
|
+
protocol,
|
|
2102
|
+
handshakeData: {
|
|
2103
|
+
instanceId: CadenzaService.serviceRegistry.serviceInstanceId,
|
|
2104
|
+
serviceName: CadenzaService.serviceRegistry.serviceName
|
|
2105
|
+
}
|
|
2106
|
+
});
|
|
2082
2107
|
},
|
|
2083
2108
|
"Shuts down the socket client"
|
|
2084
2109
|
).doOn(
|
|
2085
2110
|
`meta.socket_shutdown_requested:${fetchId}`,
|
|
2086
2111
|
`meta.socket_client.disconnected:${fetchId}`,
|
|
2087
|
-
`meta.fetch.handshake_failed:${fetchId}
|
|
2112
|
+
`meta.fetch.handshake_failed:${fetchId}`,
|
|
2113
|
+
`meta.socket_client.connect_error:${fetchId}`
|
|
2088
2114
|
).emits("meta.socket_client_shutdown_complete");
|
|
2089
2115
|
return true;
|
|
2090
2116
|
},
|