@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
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/connection.ts
|
|
2
|
-
var LiveConnection = class {
|
|
2
|
+
var LiveConnection = class _LiveConnection {
|
|
3
3
|
ws = null;
|
|
4
4
|
options;
|
|
5
5
|
reconnectAttempts = 0;
|
|
@@ -161,18 +161,34 @@ var LiveConnection = class {
|
|
|
161
161
|
this.setState({ error: "Max reconnection attempts reached" });
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
+
consecutiveHeartbeatFailures = 0;
|
|
165
|
+
static MAX_HEARTBEAT_FAILURES = 3;
|
|
164
166
|
startHeartbeat() {
|
|
165
167
|
this.stopHeartbeat();
|
|
168
|
+
this.consecutiveHeartbeatFailures = 0;
|
|
166
169
|
this.heartbeatInterval = setInterval(() => {
|
|
167
170
|
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
171
|
+
let failed = false;
|
|
168
172
|
for (const componentId of this.componentCallbacks.keys()) {
|
|
169
173
|
this.sendMessage({
|
|
170
174
|
type: "COMPONENT_PING",
|
|
171
175
|
componentId,
|
|
172
176
|
timestamp: Date.now()
|
|
173
177
|
}).catch(() => {
|
|
178
|
+
failed = true;
|
|
174
179
|
});
|
|
175
180
|
}
|
|
181
|
+
if (failed) {
|
|
182
|
+
this.consecutiveHeartbeatFailures++;
|
|
183
|
+
this.log(`Heartbeat failed (${this.consecutiveHeartbeatFailures}/${_LiveConnection.MAX_HEARTBEAT_FAILURES})`);
|
|
184
|
+
if (this.consecutiveHeartbeatFailures >= _LiveConnection.MAX_HEARTBEAT_FAILURES) {
|
|
185
|
+
this.log("Too many heartbeat failures, reconnecting...");
|
|
186
|
+
this.setState({ error: "Heartbeat failed" });
|
|
187
|
+
this.reconnect();
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
this.consecutiveHeartbeatFailures = 0;
|
|
191
|
+
}
|
|
176
192
|
}
|
|
177
193
|
}, this.options.heartbeatInterval);
|
|
178
194
|
}
|
|
@@ -1386,7 +1402,10 @@ function persistState(enabled, name, signedState, room, userId) {
|
|
|
1386
1402
|
userId,
|
|
1387
1403
|
lastUpdate: Date.now()
|
|
1388
1404
|
}));
|
|
1389
|
-
} catch {
|
|
1405
|
+
} catch (e) {
|
|
1406
|
+
if (typeof console !== "undefined") {
|
|
1407
|
+
console.warn(`[fluxstack] Failed to persist state for '${name}':`, e instanceof Error ? e.message : e);
|
|
1408
|
+
}
|
|
1390
1409
|
}
|
|
1391
1410
|
}
|
|
1392
1411
|
function getPersistedState(enabled, name) {
|