@persistica/flux-agent 0.0.17 → 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 +27 -10
- 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
|
}
|
|
@@ -393,7 +402,9 @@ var FluxAgentNetworkConnection = class {
|
|
|
393
402
|
this._fluxWebSocketClientConnection,
|
|
394
403
|
this._webRTCStateChange
|
|
395
404
|
);
|
|
396
|
-
console.log(
|
|
405
|
+
console.log(
|
|
406
|
+
this.iceConnection ? `RTCPeerConnection is available` : `RTCPeerConnection is not available`
|
|
407
|
+
);
|
|
397
408
|
} else {
|
|
398
409
|
console.warn("\u2757WebRTC is not available in this environment.");
|
|
399
410
|
}
|
|
@@ -510,7 +521,7 @@ var createWSConnection = (id, ticket, stateManager, onReconnectCallback, options
|
|
|
510
521
|
stateManager,
|
|
511
522
|
ticket,
|
|
512
523
|
{
|
|
513
|
-
domain: options
|
|
524
|
+
domain: options.domain,
|
|
514
525
|
secretKey: options?.secretKey,
|
|
515
526
|
retries: options?.retries
|
|
516
527
|
}
|
|
@@ -524,7 +535,7 @@ var FluxWebSocketConnection = class {
|
|
|
524
535
|
this.token = token;
|
|
525
536
|
this.options = options;
|
|
526
537
|
this.options = {
|
|
527
|
-
domain: this.options
|
|
538
|
+
domain: this.options.domain,
|
|
528
539
|
secretKey: this.options?.secretKey,
|
|
529
540
|
retries: this.options?.retries ?? 1e4
|
|
530
541
|
};
|
|
@@ -594,10 +605,13 @@ var FluxWebSocketConnection = class {
|
|
|
594
605
|
}
|
|
595
606
|
);
|
|
596
607
|
this.socket.clearEventSubscribers();
|
|
597
|
-
this.socket.on("message", this.handleMessage.bind(this)).on("close", () => {
|
|
608
|
+
this.socket.on("message", this.handleMessage.bind(this)).on("close", (reason) => {
|
|
598
609
|
this.webSocketClient = void 0;
|
|
599
|
-
|
|
600
|
-
|
|
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");
|
|
601
615
|
}).on("connecting", (retryAttempt) => {
|
|
602
616
|
this.stateManager.emitNetworkState("disconnected");
|
|
603
617
|
if (retryAttempt > 0) {
|
|
@@ -1126,7 +1140,10 @@ var FluxAgent = class {
|
|
|
1126
1140
|
clientUId
|
|
1127
1141
|
);
|
|
1128
1142
|
},
|
|
1129
|
-
|
|
1143
|
+
{
|
|
1144
|
+
...this.options,
|
|
1145
|
+
domain
|
|
1146
|
+
}
|
|
1130
1147
|
);
|
|
1131
1148
|
this.fluxClientData.updateWsConnection(this.fluxWebSocketConnection);
|
|
1132
1149
|
const fluxNetworkConnection = await this.fluxWebSocketConnection.connectToNetwork();
|