@liveblocks/core 1.0.9 → 1.0.11
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.d.ts +1 -0
- package/dist/index.js +56 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1115,6 +1115,7 @@ declare type AuthEndpoint = string | ((room: string) => Promise<{
|
|
|
1115
1115
|
declare type ClientOptions = {
|
|
1116
1116
|
throttle?: number;
|
|
1117
1117
|
polyfills?: Polyfills;
|
|
1118
|
+
unstable_fallbackToHTTP?: boolean;
|
|
1118
1119
|
/**
|
|
1119
1120
|
* Backward-compatible way to set `polyfills.fetch`.
|
|
1120
1121
|
*/
|
package/dist/index.js
CHANGED
|
@@ -117,7 +117,7 @@ var onMessageFromPanel = eventSource.observable;
|
|
|
117
117
|
// src/devtools/index.ts
|
|
118
118
|
var VERSION = true ? (
|
|
119
119
|
/* istanbul ignore next */
|
|
120
|
-
"1.0.
|
|
120
|
+
"1.0.11"
|
|
121
121
|
) : "dev";
|
|
122
122
|
var _devtoolsSetupHasRun = false;
|
|
123
123
|
function setupDevTools(getAllRooms) {
|
|
@@ -2399,7 +2399,6 @@ var LiveObject = class extends AbstractCrdt {
|
|
|
2399
2399
|
id,
|
|
2400
2400
|
data: {}
|
|
2401
2401
|
};
|
|
2402
|
-
reverse.push(reverseUpdate);
|
|
2403
2402
|
for (const key in op.data) {
|
|
2404
2403
|
const oldValue = this._map.get(key);
|
|
2405
2404
|
if (isLiveNode(oldValue)) {
|
|
@@ -2955,7 +2954,8 @@ function hasJwtMeta(data) {
|
|
|
2955
2954
|
}
|
|
2956
2955
|
function isTokenExpired(token) {
|
|
2957
2956
|
const now = Date.now() / 1e3;
|
|
2958
|
-
|
|
2957
|
+
const valid = now <= token.exp - 300 && now >= token.iat - 300;
|
|
2958
|
+
return !valid;
|
|
2959
2959
|
}
|
|
2960
2960
|
function isStringList(value) {
|
|
2961
2961
|
return Array.isArray(value) && value.every((i) => typeof i === "string");
|
|
@@ -3257,6 +3257,7 @@ var BACKOFF_RETRY_DELAYS = [250, 500, 1e3, 2e3, 4e3, 8e3, 1e4];
|
|
|
3257
3257
|
var BACKOFF_RETRY_DELAYS_SLOW = [2e3, 3e4, 6e4, 3e5];
|
|
3258
3258
|
var HEARTBEAT_INTERVAL = 3e4;
|
|
3259
3259
|
var PONG_TIMEOUT = 2e3;
|
|
3260
|
+
var MAX_MESSAGE_SIZE = 1024 * 1024 - 128;
|
|
3260
3261
|
function makeIdFactory(connectionId) {
|
|
3261
3262
|
let count = 0;
|
|
3262
3263
|
return () => `${connectionId}:${count++}`;
|
|
@@ -3405,14 +3406,33 @@ function createRoom(options, config) {
|
|
|
3405
3406
|
}
|
|
3406
3407
|
},
|
|
3407
3408
|
send(messageOrMessages) {
|
|
3409
|
+
var _a2, _b;
|
|
3408
3410
|
if (context.socket === null) {
|
|
3409
3411
|
throw new Error("Can't send message if socket is null");
|
|
3410
3412
|
}
|
|
3411
3413
|
if (context.socket.readyState === context.socket.OPEN) {
|
|
3412
|
-
|
|
3414
|
+
const message = JSON.stringify(messageOrMessages);
|
|
3415
|
+
if (config.unstable_fallbackToHTTP) {
|
|
3416
|
+
const size = new TextEncoder().encode(message).length;
|
|
3417
|
+
if (size > MAX_MESSAGE_SIZE && ((_a2 = context.token) == null ? void 0 : _a2.raw) && config.httpSendEndpoint) {
|
|
3418
|
+
if (isTokenExpired(context.token.parsed)) {
|
|
3419
|
+
return reconnect();
|
|
3420
|
+
}
|
|
3421
|
+
void httpSend(
|
|
3422
|
+
message,
|
|
3423
|
+
context.token.raw,
|
|
3424
|
+
config.httpSendEndpoint,
|
|
3425
|
+
(_b = config.polyfills) == null ? void 0 : _b.fetch
|
|
3426
|
+
);
|
|
3427
|
+
warn(
|
|
3428
|
+
"Message was too large for websockets and sent over HTTP instead"
|
|
3429
|
+
);
|
|
3430
|
+
return;
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
context.socket.send(message);
|
|
3413
3434
|
}
|
|
3414
3435
|
},
|
|
3415
|
-
scheduleFlush: (delay) => setTimeout(tryFlushing, delay),
|
|
3416
3436
|
scheduleReconnect: (delay) => setTimeout(handleConnect, delay),
|
|
3417
3437
|
startHeartbeatInterval: () => setInterval(heartbeat, HEARTBEAT_INTERVAL),
|
|
3418
3438
|
schedulePongTimeout: () => setTimeout(pongTimeout, PONG_TIMEOUT)
|
|
@@ -4099,7 +4119,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
4099
4119
|
};
|
|
4100
4120
|
} else {
|
|
4101
4121
|
clearTimeout(context.timers.flush);
|
|
4102
|
-
context.timers.flush =
|
|
4122
|
+
context.timers.flush = setTimeout(
|
|
4123
|
+
tryFlushing,
|
|
4103
4124
|
config.throttleDelay - elapsedMillis
|
|
4104
4125
|
);
|
|
4105
4126
|
}
|
|
@@ -4503,11 +4524,25 @@ function prepareCreateWebSocket(liveblocksServer, WebSocketPolyfill) {
|
|
|
4503
4524
|
// @ts-ignore (__PACKAGE_VERSION__ will be injected by the build script)
|
|
4504
4525
|
true ? (
|
|
4505
4526
|
/* istanbul ignore next */
|
|
4506
|
-
"1.0.
|
|
4527
|
+
"1.0.11"
|
|
4507
4528
|
) : "dev"}`
|
|
4508
4529
|
);
|
|
4509
4530
|
};
|
|
4510
4531
|
}
|
|
4532
|
+
function httpSend(message, token, endpoint, fetchPolyfill) {
|
|
4533
|
+
return __async(this, null, function* () {
|
|
4534
|
+
const fetcher = fetchPolyfill || /* istanbul ignore next */
|
|
4535
|
+
fetch;
|
|
4536
|
+
return fetcher(endpoint, {
|
|
4537
|
+
method: "POST",
|
|
4538
|
+
headers: {
|
|
4539
|
+
"Content-Type": "application/json",
|
|
4540
|
+
Authorization: `Bearer ${token}`
|
|
4541
|
+
},
|
|
4542
|
+
body: message
|
|
4543
|
+
});
|
|
4544
|
+
});
|
|
4545
|
+
}
|
|
4511
4546
|
function prepareAuthEndpoint(roomId, authentication, fetchPolyfill) {
|
|
4512
4547
|
if (authentication.type === "public") {
|
|
4513
4548
|
if (typeof window === "undefined" && fetchPolyfill === void 0) {
|
|
@@ -4628,7 +4663,12 @@ function createClient(options) {
|
|
|
4628
4663
|
polyfills: clientOptions.polyfills,
|
|
4629
4664
|
unstable_batchedUpdates: options2 == null ? void 0 : options2.unstable_batchedUpdates,
|
|
4630
4665
|
liveblocksServer: getServerFromClientOptions(clientOptions),
|
|
4631
|
-
authentication: prepareAuthentication(clientOptions, roomId)
|
|
4666
|
+
authentication: prepareAuthentication(clientOptions, roomId),
|
|
4667
|
+
httpSendEndpoint: buildLiveblocksHttpSendEndpoint(
|
|
4668
|
+
clientOptions,
|
|
4669
|
+
roomId
|
|
4670
|
+
),
|
|
4671
|
+
unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP
|
|
4632
4672
|
}
|
|
4633
4673
|
);
|
|
4634
4674
|
rooms.set(roomId, newRoom);
|
|
@@ -4732,6 +4772,14 @@ function prepareAuthentication(clientOptions, roomId) {
|
|
|
4732
4772
|
"Invalid Liveblocks client options. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClient"
|
|
4733
4773
|
);
|
|
4734
4774
|
}
|
|
4775
|
+
function buildLiveblocksHttpSendEndpoint(options, roomId) {
|
|
4776
|
+
if (options.httpSendEndpoint) {
|
|
4777
|
+
return options.httpSendEndpoint.replace("{roomId}", roomId);
|
|
4778
|
+
}
|
|
4779
|
+
return `https://api.liveblocks.io/v2/rooms/${encodeURIComponent(
|
|
4780
|
+
roomId
|
|
4781
|
+
)}/send-message`;
|
|
4782
|
+
}
|
|
4735
4783
|
function buildLiveblocksPublicAuthorizeEndpoint(options, roomId) {
|
|
4736
4784
|
if (options.publicAuthorizeEndpoint) {
|
|
4737
4785
|
return options.publicAuthorizeEndpoint.replace("{roomId}", roomId);
|