@fluxstack/live-client 0.5.0 → 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 +30 -4
- 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 +30 -4
- package/dist/index.js.map +1 -1
- package/dist/live-client.browser.global.js +31 -4
- package/dist/live-client.browser.global.js.map +1 -1
- package/package.json +4 -3
- package/src/__tests__/rooms.binary.test.ts +359 -0
- package/src/component.ts +364 -0
- package/src/connection.ts +524 -0
- package/src/index.ts +219 -0
- package/src/persistence.ts +52 -0
- package/src/rooms.ts +539 -0
- package/src/state-validator.ts +121 -0
- package/src/upload.ts +366 -0
package/dist/index.cjs
CHANGED
|
@@ -37,7 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
38
|
|
|
39
39
|
// src/connection.ts
|
|
40
|
-
var LiveConnection = class {
|
|
40
|
+
var LiveConnection = class _LiveConnection {
|
|
41
41
|
ws = null;
|
|
42
42
|
options;
|
|
43
43
|
reconnectAttempts = 0;
|
|
@@ -199,18 +199,34 @@ var LiveConnection = class {
|
|
|
199
199
|
this.setState({ error: "Max reconnection attempts reached" });
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
|
+
consecutiveHeartbeatFailures = 0;
|
|
203
|
+
static MAX_HEARTBEAT_FAILURES = 3;
|
|
202
204
|
startHeartbeat() {
|
|
203
205
|
this.stopHeartbeat();
|
|
206
|
+
this.consecutiveHeartbeatFailures = 0;
|
|
204
207
|
this.heartbeatInterval = setInterval(() => {
|
|
205
208
|
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
209
|
+
let failed = false;
|
|
206
210
|
for (const componentId of this.componentCallbacks.keys()) {
|
|
207
211
|
this.sendMessage({
|
|
208
212
|
type: "COMPONENT_PING",
|
|
209
213
|
componentId,
|
|
210
214
|
timestamp: Date.now()
|
|
211
215
|
}).catch(() => {
|
|
216
|
+
failed = true;
|
|
212
217
|
});
|
|
213
218
|
}
|
|
219
|
+
if (failed) {
|
|
220
|
+
this.consecutiveHeartbeatFailures++;
|
|
221
|
+
this.log(`Heartbeat failed (${this.consecutiveHeartbeatFailures}/${_LiveConnection.MAX_HEARTBEAT_FAILURES})`);
|
|
222
|
+
if (this.consecutiveHeartbeatFailures >= _LiveConnection.MAX_HEARTBEAT_FAILURES) {
|
|
223
|
+
this.log("Too many heartbeat failures, reconnecting...");
|
|
224
|
+
this.setState({ error: "Heartbeat failed" });
|
|
225
|
+
this.reconnect();
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
this.consecutiveHeartbeatFailures = 0;
|
|
229
|
+
}
|
|
214
230
|
}
|
|
215
231
|
}, this.options.heartbeatInterval);
|
|
216
232
|
}
|
|
@@ -394,8 +410,15 @@ var LiveConnection = class {
|
|
|
394
410
|
{ type: "AUTH", payload: credentials },
|
|
395
411
|
5e3
|
|
396
412
|
);
|
|
397
|
-
const
|
|
398
|
-
|
|
413
|
+
const payload = response.payload;
|
|
414
|
+
const success = payload?.authenticated || false;
|
|
415
|
+
this.setState({
|
|
416
|
+
authenticated: success,
|
|
417
|
+
auth: {
|
|
418
|
+
authenticated: success,
|
|
419
|
+
session: success ? payload?.session || null : null
|
|
420
|
+
}
|
|
421
|
+
});
|
|
399
422
|
return success;
|
|
400
423
|
} catch {
|
|
401
424
|
return false;
|
|
@@ -1417,7 +1440,10 @@ function persistState(enabled, name, signedState, room, userId) {
|
|
|
1417
1440
|
userId,
|
|
1418
1441
|
lastUpdate: Date.now()
|
|
1419
1442
|
}));
|
|
1420
|
-
} catch {
|
|
1443
|
+
} catch (e) {
|
|
1444
|
+
if (typeof console !== "undefined") {
|
|
1445
|
+
console.warn(`[fluxstack] Failed to persist state for '${name}':`, e instanceof Error ? e.message : e);
|
|
1446
|
+
}
|
|
1421
1447
|
}
|
|
1422
1448
|
}
|
|
1423
1449
|
function getPersistedState(enabled, name) {
|