@persistica/flux-agent 0.0.18 → 0.0.19
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/index.js +18 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -132,6 +132,7 @@ var RPCServer = class {
|
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
// libs/flux/shared/ws/src/lib/ws-client.ts
|
|
135
|
+
var RECONNECTION_DELAY_ON_KICK_MS = 18e5;
|
|
135
136
|
var WebSocketClient = class extends RPCServer {
|
|
136
137
|
options;
|
|
137
138
|
eventListeners = {
|
|
@@ -180,17 +181,25 @@ var WebSocketClient = class extends RPCServer {
|
|
|
180
181
|
this.ws.onmessage = (event) => {
|
|
181
182
|
this.emit("message", event.data);
|
|
182
183
|
};
|
|
183
|
-
this.ws.onclose = () => {
|
|
184
|
+
this.ws.onclose = (closeEvent) => {
|
|
185
|
+
const wasKicked = closeEvent.reason === "Kicked by process";
|
|
184
186
|
clearTimeout(timeout);
|
|
185
187
|
if (this.isOpen) {
|
|
186
|
-
this.emit(
|
|
188
|
+
this.emit(
|
|
189
|
+
"close",
|
|
190
|
+
wasKicked ? "kicked" : void 0
|
|
191
|
+
);
|
|
187
192
|
this.isOpen = false;
|
|
188
193
|
}
|
|
189
194
|
if (this.options.autoReconnect && (this.options.retries === void 0 || this.reconnectAttempts < this.options.retries)) {
|
|
195
|
+
const delay = wasKicked ? RECONNECTION_DELAY_ON_KICK_MS : Math.min(
|
|
196
|
+
this.options.reconnectDelay ?? Number.POSITIVE_INFINITY,
|
|
197
|
+
(this.options.reconnectDelay ?? 0) * (this.reconnectAttempts || 1)
|
|
198
|
+
);
|
|
190
199
|
setTimeout(() => {
|
|
191
200
|
this.reconnectAttempts++;
|
|
192
201
|
this.connect();
|
|
193
|
-
},
|
|
202
|
+
}, delay);
|
|
194
203
|
} else if (this.options.autoReconnect) {
|
|
195
204
|
this.emit("error", new Error("Connection failed: retries exhausted"));
|
|
196
205
|
}
|
|
@@ -596,10 +605,13 @@ var FluxWebSocketConnection = class {
|
|
|
596
605
|
}
|
|
597
606
|
);
|
|
598
607
|
this.socket.clearEventSubscribers();
|
|
599
|
-
this.socket.on("message", this.handleMessage.bind(this)).on("close", () => {
|
|
608
|
+
this.socket.on("message", this.handleMessage.bind(this)).on("close", (reason) => {
|
|
600
609
|
this.webSocketClient = void 0;
|
|
601
|
-
|
|
602
|
-
|
|
610
|
+
PicoLogger.log(
|
|
611
|
+
reason === "kicked" ? `\u{1F50C}\u{1F534} Kicked, delaying reconnect ${RECONNECTION_DELAY_ON_KICK_MS / 6e4} minutes` : "\u{1F50C}\u{1F534} Disconnected",
|
|
612
|
+
this.fluxInstanceId
|
|
613
|
+
);
|
|
614
|
+
this.stateManager.emitNetworkState(reason === "kicked" ? "kicked" : "disconnected");
|
|
603
615
|
}).on("connecting", (retryAttempt) => {
|
|
604
616
|
this.stateManager.emitNetworkState("disconnected");
|
|
605
617
|
if (retryAttempt > 0) {
|