@fluxstack/live-client 0.5.1 → 0.6.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/index.cjs +21 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/live-client.browser.global.js +22 -2
- package/dist/live-client.browser.global.js.map +1 -1
- package/package.json +2 -2
- package/src/connection.ts +17 -1
- package/src/persistence.ts +5 -1
|
@@ -39,7 +39,7 @@ var FluxstackLive = (() => {
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
// src/connection.ts
|
|
42
|
-
var
|
|
42
|
+
var _LiveConnection = class _LiveConnection {
|
|
43
43
|
constructor(options = {}) {
|
|
44
44
|
__publicField(this, "ws", null);
|
|
45
45
|
__publicField(this, "options");
|
|
@@ -59,6 +59,7 @@ var FluxstackLive = (() => {
|
|
|
59
59
|
authenticated: false,
|
|
60
60
|
auth: { authenticated: false, session: null }
|
|
61
61
|
});
|
|
62
|
+
__publicField(this, "consecutiveHeartbeatFailures", 0);
|
|
62
63
|
this.options = {
|
|
63
64
|
url: options.url,
|
|
64
65
|
auth: options.auth,
|
|
@@ -203,16 +204,30 @@ var FluxstackLive = (() => {
|
|
|
203
204
|
}
|
|
204
205
|
startHeartbeat() {
|
|
205
206
|
this.stopHeartbeat();
|
|
207
|
+
this.consecutiveHeartbeatFailures = 0;
|
|
206
208
|
this.heartbeatInterval = setInterval(() => {
|
|
207
209
|
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
210
|
+
let failed = false;
|
|
208
211
|
for (const componentId of this.componentCallbacks.keys()) {
|
|
209
212
|
this.sendMessage({
|
|
210
213
|
type: "COMPONENT_PING",
|
|
211
214
|
componentId,
|
|
212
215
|
timestamp: Date.now()
|
|
213
216
|
}).catch(() => {
|
|
217
|
+
failed = true;
|
|
214
218
|
});
|
|
215
219
|
}
|
|
220
|
+
if (failed) {
|
|
221
|
+
this.consecutiveHeartbeatFailures++;
|
|
222
|
+
this.log(`Heartbeat failed (${this.consecutiveHeartbeatFailures}/${_LiveConnection.MAX_HEARTBEAT_FAILURES})`);
|
|
223
|
+
if (this.consecutiveHeartbeatFailures >= _LiveConnection.MAX_HEARTBEAT_FAILURES) {
|
|
224
|
+
this.log("Too many heartbeat failures, reconnecting...");
|
|
225
|
+
this.setState({ error: "Heartbeat failed" });
|
|
226
|
+
this.reconnect();
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
this.consecutiveHeartbeatFailures = 0;
|
|
230
|
+
}
|
|
216
231
|
}
|
|
217
232
|
}, this.options.heartbeatInterval);
|
|
218
233
|
}
|
|
@@ -428,6 +443,8 @@ var FluxstackLive = (() => {
|
|
|
428
443
|
this.stateListeners.clear();
|
|
429
444
|
}
|
|
430
445
|
};
|
|
446
|
+
__publicField(_LiveConnection, "MAX_HEARTBEAT_FAILURES", 3);
|
|
447
|
+
var LiveConnection = _LiveConnection;
|
|
431
448
|
|
|
432
449
|
// src/component.ts
|
|
433
450
|
function isPlainObject(v) {
|
|
@@ -1426,7 +1443,10 @@ var FluxstackLive = (() => {
|
|
|
1426
1443
|
userId,
|
|
1427
1444
|
lastUpdate: Date.now()
|
|
1428
1445
|
}));
|
|
1429
|
-
} catch {
|
|
1446
|
+
} catch (e) {
|
|
1447
|
+
if (typeof console !== "undefined") {
|
|
1448
|
+
console.warn(`[fluxstack] Failed to persist state for '${name}':`, e instanceof Error ? e.message : e);
|
|
1449
|
+
}
|
|
1430
1450
|
}
|
|
1431
1451
|
}
|
|
1432
1452
|
function getPersistedState(enabled, name) {
|