@fluxstack/live-client 0.4.0 → 0.5.1
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 +31 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +31 -18
- package/dist/index.js.map +1 -1
- package/dist/live-client.browser.global.js +31 -18
- 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 +508 -0
- package/src/index.ts +219 -0
- package/src/persistence.ts +48 -0
- package/src/rooms.ts +539 -0
- package/src/state-validator.ts +121 -0
- package/src/upload.ts +366 -0
|
@@ -56,7 +56,8 @@ var FluxstackLive = (() => {
|
|
|
56
56
|
connecting: false,
|
|
57
57
|
error: null,
|
|
58
58
|
connectionId: null,
|
|
59
|
-
authenticated: false
|
|
59
|
+
authenticated: false,
|
|
60
|
+
auth: { authenticated: false, session: null }
|
|
60
61
|
});
|
|
61
62
|
this.options = {
|
|
62
63
|
url: options.url,
|
|
@@ -88,21 +89,14 @@ var FluxstackLive = (() => {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
getWebSocketUrl() {
|
|
91
|
-
const auth = this.options.auth;
|
|
92
|
-
let baseUrl;
|
|
93
92
|
if (this.options.url) {
|
|
94
|
-
|
|
93
|
+
return this.options.url;
|
|
95
94
|
} else if (typeof window === "undefined") {
|
|
96
|
-
|
|
95
|
+
return "ws://localhost:3000/api/live/ws";
|
|
97
96
|
} else {
|
|
98
97
|
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
|
99
|
-
|
|
98
|
+
return `${protocol}//${window.location.host}/api/live/ws`;
|
|
100
99
|
}
|
|
101
|
-
if (auth?.token) {
|
|
102
|
-
const separator = baseUrl.includes("?") ? "&" : "?";
|
|
103
|
-
return `${baseUrl}${separator}token=${encodeURIComponent(auth.token)}`;
|
|
104
|
-
}
|
|
105
|
-
return baseUrl;
|
|
106
100
|
}
|
|
107
101
|
log(message, data) {
|
|
108
102
|
if (this.options.debug) {
|
|
@@ -159,7 +153,7 @@ var FluxstackLive = (() => {
|
|
|
159
153
|
};
|
|
160
154
|
ws.onclose = (event) => {
|
|
161
155
|
this.log("Disconnected", { code: event.code, reason: event.reason });
|
|
162
|
-
this.setState({ connected: false, connecting: false, connectionId: null });
|
|
156
|
+
this.setState({ connected: false, connecting: false, connectionId: null, authenticated: false, auth: { authenticated: false, session: null } });
|
|
163
157
|
this.stopHeartbeat();
|
|
164
158
|
if (event.code === 4003) {
|
|
165
159
|
this.setState({ error: "Connection rejected: origin not allowed" });
|
|
@@ -235,17 +229,29 @@ var FluxstackLive = (() => {
|
|
|
235
229
|
authenticated: response.authenticated || false
|
|
236
230
|
});
|
|
237
231
|
const auth = this.options.auth;
|
|
238
|
-
if (auth &&
|
|
232
|
+
if (auth && Object.keys(auth).some((k) => auth[k])) {
|
|
239
233
|
this.sendMessageAndWait({ type: "AUTH", payload: auth }).then((authResp) => {
|
|
240
|
-
|
|
241
|
-
|
|
234
|
+
const payload = authResp.payload;
|
|
235
|
+
if (payload?.authenticated) {
|
|
236
|
+
this.setState({
|
|
237
|
+
authenticated: true,
|
|
238
|
+
auth: { authenticated: true, session: payload.session || null }
|
|
239
|
+
});
|
|
242
240
|
}
|
|
243
241
|
}).catch(() => {
|
|
244
242
|
});
|
|
245
243
|
}
|
|
246
244
|
}
|
|
247
245
|
if (response.type === "AUTH_RESPONSE") {
|
|
248
|
-
|
|
246
|
+
const payload = response.payload;
|
|
247
|
+
const authenticated = payload?.authenticated || false;
|
|
248
|
+
this.setState({
|
|
249
|
+
authenticated,
|
|
250
|
+
auth: {
|
|
251
|
+
authenticated,
|
|
252
|
+
session: authenticated ? payload?.session || null : null
|
|
253
|
+
}
|
|
254
|
+
});
|
|
249
255
|
}
|
|
250
256
|
if (response.requestId && this.pendingRequests.has(response.requestId)) {
|
|
251
257
|
const request = this.pendingRequests.get(response.requestId);
|
|
@@ -390,8 +396,15 @@ var FluxstackLive = (() => {
|
|
|
390
396
|
{ type: "AUTH", payload: credentials },
|
|
391
397
|
5e3
|
|
392
398
|
);
|
|
393
|
-
const
|
|
394
|
-
|
|
399
|
+
const payload = response.payload;
|
|
400
|
+
const success = payload?.authenticated || false;
|
|
401
|
+
this.setState({
|
|
402
|
+
authenticated: success,
|
|
403
|
+
auth: {
|
|
404
|
+
authenticated: success,
|
|
405
|
+
session: success ? payload?.session || null : null
|
|
406
|
+
}
|
|
407
|
+
});
|
|
395
408
|
return success;
|
|
396
409
|
} catch {
|
|
397
410
|
return false;
|