@liveblocks/core 1.5.0-test1 → 1.5.0-test2
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.mts +46 -13
- package/dist/index.d.ts +46 -13
- package/dist/index.js +225 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +166 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "1.5.0-
|
|
9
|
+
var PKG_VERSION = "1.5.0-test2";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -585,8 +585,8 @@ function tryParseJson(rawMessage) {
|
|
|
585
585
|
return void 0;
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
|
-
function deepClone(
|
|
589
|
-
return JSON.parse(JSON.stringify(
|
|
588
|
+
function deepClone(value) {
|
|
589
|
+
return JSON.parse(JSON.stringify(value));
|
|
590
590
|
}
|
|
591
591
|
function b64decode(b64value) {
|
|
592
592
|
try {
|
|
@@ -673,6 +673,9 @@ function shouldRetryWithoutReauth(code) {
|
|
|
673
673
|
}
|
|
674
674
|
|
|
675
675
|
// src/connection.ts
|
|
676
|
+
function isIdle(status) {
|
|
677
|
+
return status === "initial" || status === "disconnected";
|
|
678
|
+
}
|
|
676
679
|
function newToLegacyStatus(status) {
|
|
677
680
|
switch (status) {
|
|
678
681
|
case "connecting":
|
|
@@ -701,6 +704,7 @@ function toNewConnectionStatus(machine) {
|
|
|
701
704
|
case "@auth.backoff":
|
|
702
705
|
case "@connecting.busy":
|
|
703
706
|
case "@connecting.backoff":
|
|
707
|
+
case "@idle.zombie":
|
|
704
708
|
return machine.context.successCount > 0 ? "reconnecting" : "connecting";
|
|
705
709
|
case "@idle.failed":
|
|
706
710
|
return "disconnected";
|
|
@@ -842,7 +846,7 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
842
846
|
socket: null,
|
|
843
847
|
backoffDelay: RESET_DELAY
|
|
844
848
|
};
|
|
845
|
-
const machine = new FSM(initialContext).addState("@idle.initial").addState("@idle.failed").addState("@auth.busy").addState("@auth.backoff").addState("@connecting.busy").addState("@connecting.backoff").addState("@ok.connected").addState("@ok.awaiting-pong");
|
|
849
|
+
const machine = new FSM(initialContext).addState("@idle.initial").addState("@idle.failed").addState("@idle.zombie").addState("@auth.busy").addState("@auth.backoff").addState("@connecting.busy").addState("@connecting.backoff").addState("@ok.connected").addState("@ok.awaiting-pong");
|
|
846
850
|
machine.addTransitions("*", {
|
|
847
851
|
RECONNECT: {
|
|
848
852
|
target: "@auth.backoff",
|
|
@@ -1052,11 +1056,20 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
1052
1056
|
ctx.socket?.send("ping");
|
|
1053
1057
|
}
|
|
1054
1058
|
};
|
|
1055
|
-
|
|
1056
|
-
|
|
1059
|
+
const maybeHeartbeat = () => {
|
|
1060
|
+
const doc = typeof document !== "undefined" ? document : void 0;
|
|
1061
|
+
const canZombie = doc?.visibilityState === "hidden" && delegates.canZombie();
|
|
1062
|
+
return canZombie ? "@idle.zombie" : sendHeartbeat;
|
|
1063
|
+
};
|
|
1064
|
+
machine.addTimedTransition("@ok.connected", HEARTBEAT_INTERVAL, maybeHeartbeat).addTransitions("@ok.connected", {
|
|
1065
|
+
NAVIGATOR_OFFLINE: maybeHeartbeat,
|
|
1057
1066
|
// Don't take the browser's word for it when it says it's offline. Do a ping/pong to make sure.
|
|
1058
1067
|
WINDOW_GOT_FOCUS: sendHeartbeat
|
|
1059
1068
|
});
|
|
1069
|
+
machine.addTransitions("@idle.zombie", {
|
|
1070
|
+
WINDOW_GOT_FOCUS: "@connecting.backoff"
|
|
1071
|
+
// When in zombie state, the client will try to wake up automatically when the window regains focus
|
|
1072
|
+
});
|
|
1060
1073
|
machine.onEnter("@ok.*", (ctx) => {
|
|
1061
1074
|
ctx.patch({ successCount: ctx.successCount + 1 });
|
|
1062
1075
|
const timerID = setTimeout(
|
|
@@ -1287,6 +1300,12 @@ function createAuthManager(authOptions) {
|
|
|
1287
1300
|
const tokens = [];
|
|
1288
1301
|
const expiryTimes = [];
|
|
1289
1302
|
const requestPromises = /* @__PURE__ */ new Map();
|
|
1303
|
+
function reset() {
|
|
1304
|
+
seenTokens.clear();
|
|
1305
|
+
tokens.length = 0;
|
|
1306
|
+
expiryTimes.length = 0;
|
|
1307
|
+
requestPromises.clear();
|
|
1308
|
+
}
|
|
1290
1309
|
function hasCorrespondingScopes(requestedScope, scopes) {
|
|
1291
1310
|
if (requestedScope === "comments:read") {
|
|
1292
1311
|
return scopes.includes("comments:read" /* CommentsRead */) || scopes.includes("comments:write" /* CommentsWrite */) || scopes.includes("room:read" /* Read */) || scopes.includes("room:write" /* Write */);
|
|
@@ -1322,7 +1341,7 @@ function createAuthManager(authOptions) {
|
|
|
1322
1341
|
if (authentication.type === "private") {
|
|
1323
1342
|
if (fetcher === void 0) {
|
|
1324
1343
|
throw new StopRetrying(
|
|
1325
|
-
"To use Liveblocks client in a non-
|
|
1344
|
+
"To use Liveblocks client in a non-DOM environment with a url as auth endpoint, you need to provide a fetch polyfill."
|
|
1326
1345
|
);
|
|
1327
1346
|
}
|
|
1328
1347
|
const response = await fetchAuthEndpoint(fetcher, authentication.url, {
|
|
@@ -1386,6 +1405,7 @@ function createAuthManager(authOptions) {
|
|
|
1386
1405
|
}
|
|
1387
1406
|
}
|
|
1388
1407
|
return {
|
|
1408
|
+
reset,
|
|
1389
1409
|
getAuthValue
|
|
1390
1410
|
};
|
|
1391
1411
|
}
|
|
@@ -1467,6 +1487,9 @@ async function fetchAuthEndpoint(fetch2, endpoint, body) {
|
|
|
1467
1487
|
return { token };
|
|
1468
1488
|
}
|
|
1469
1489
|
|
|
1490
|
+
// src/constants.ts
|
|
1491
|
+
var DEFAULT_BASE_URL = "https://api.liveblocks.io";
|
|
1492
|
+
|
|
1470
1493
|
// src/devtools/bridge.ts
|
|
1471
1494
|
var _bridgeActive = false;
|
|
1472
1495
|
function activateBridge(allowed) {
|
|
@@ -1718,7 +1741,7 @@ function getAuthBearerHeaderFromAuthValue(authValue) {
|
|
|
1718
1741
|
return authValue.token.raw;
|
|
1719
1742
|
}
|
|
1720
1743
|
}
|
|
1721
|
-
function createCommentsApi(roomId, getAuthValue,
|
|
1744
|
+
function createCommentsApi(roomId, getAuthValue, config) {
|
|
1722
1745
|
async function fetchJson(endpoint, options) {
|
|
1723
1746
|
const response = await fetchApi(roomId, endpoint, options);
|
|
1724
1747
|
if (!response.ok) {
|
|
@@ -1745,9 +1768,10 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
|
|
|
1745
1768
|
}
|
|
1746
1769
|
async function fetchApi(roomId2, endpoint, options) {
|
|
1747
1770
|
const authValue = await getAuthValue();
|
|
1748
|
-
const url =
|
|
1749
|
-
roomId2
|
|
1750
|
-
|
|
1771
|
+
const url = new URL(
|
|
1772
|
+
`/v2/c/rooms/${encodeURIComponent(roomId2)}${endpoint}`,
|
|
1773
|
+
config.baseUrl
|
|
1774
|
+
).toString();
|
|
1751
1775
|
return await fetch(url, {
|
|
1752
1776
|
...options,
|
|
1753
1777
|
headers: {
|
|
@@ -2309,6 +2333,9 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
2309
2333
|
_toImmutable() {
|
|
2310
2334
|
return this._data;
|
|
2311
2335
|
}
|
|
2336
|
+
clone() {
|
|
2337
|
+
return deepClone(this.data);
|
|
2338
|
+
}
|
|
2312
2339
|
};
|
|
2313
2340
|
|
|
2314
2341
|
// src/crdts/LiveList.ts
|
|
@@ -3252,6 +3279,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3252
3279
|
const result = this._items.map((node) => node.toImmutable());
|
|
3253
3280
|
return process.env.NODE_ENV === "production" ? result : Object.freeze(result);
|
|
3254
3281
|
}
|
|
3282
|
+
clone() {
|
|
3283
|
+
return new _LiveList(this._items.map((item) => item.clone()));
|
|
3284
|
+
}
|
|
3255
3285
|
};
|
|
3256
3286
|
var LiveListIterator = class {
|
|
3257
3287
|
constructor(items) {
|
|
@@ -3335,10 +3365,10 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3335
3365
|
this.unacknowledgedSet = /* @__PURE__ */ new Map();
|
|
3336
3366
|
if (entries2) {
|
|
3337
3367
|
const mappedEntries = [];
|
|
3338
|
-
for (const
|
|
3339
|
-
const
|
|
3340
|
-
|
|
3341
|
-
mappedEntries.push([
|
|
3368
|
+
for (const [key, value] of entries2) {
|
|
3369
|
+
const node = lsonToLiveNode(value);
|
|
3370
|
+
node._setParentLink(this, key);
|
|
3371
|
+
mappedEntries.push([key, node]);
|
|
3342
3372
|
}
|
|
3343
3373
|
this._map = new Map(mappedEntries);
|
|
3344
3374
|
} else {
|
|
@@ -3669,6 +3699,11 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3669
3699
|
}
|
|
3670
3700
|
return freeze(result);
|
|
3671
3701
|
}
|
|
3702
|
+
clone() {
|
|
3703
|
+
return new _LiveMap(
|
|
3704
|
+
Array.from(this._map).map(([key, node]) => [key, node.clone()])
|
|
3705
|
+
);
|
|
3706
|
+
}
|
|
3672
3707
|
};
|
|
3673
3708
|
|
|
3674
3709
|
// src/crdts/LiveObject.ts
|
|
@@ -4179,6 +4214,16 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
4179
4214
|
}
|
|
4180
4215
|
return process.env.NODE_ENV === "production" ? result : Object.freeze(result);
|
|
4181
4216
|
}
|
|
4217
|
+
clone() {
|
|
4218
|
+
return new _LiveObject(
|
|
4219
|
+
Object.fromEntries(
|
|
4220
|
+
Array.from(this._map).map(([key, value]) => [
|
|
4221
|
+
key,
|
|
4222
|
+
isLiveStructure(value) ? value.clone() : deepClone(value)
|
|
4223
|
+
])
|
|
4224
|
+
)
|
|
4225
|
+
);
|
|
4226
|
+
}
|
|
4182
4227
|
};
|
|
4183
4228
|
|
|
4184
4229
|
// src/crdts/liveblocks-helpers.ts
|
|
@@ -4264,6 +4309,9 @@ function isLiveObject(value) {
|
|
|
4264
4309
|
function isLiveRegister(value) {
|
|
4265
4310
|
return value instanceof LiveRegister;
|
|
4266
4311
|
}
|
|
4312
|
+
function cloneLson(value) {
|
|
4313
|
+
return value === void 0 ? void 0 : isLiveStructure(value) ? value.clone() : deepClone(value);
|
|
4314
|
+
}
|
|
4267
4315
|
function liveNodeToLson(obj) {
|
|
4268
4316
|
if (obj instanceof LiveRegister) {
|
|
4269
4317
|
return obj.data;
|
|
@@ -4698,10 +4746,40 @@ function userToTreeNode(key, user) {
|
|
|
4698
4746
|
payload: user
|
|
4699
4747
|
};
|
|
4700
4748
|
}
|
|
4749
|
+
function installBackgroundTabSpy() {
|
|
4750
|
+
const doc = typeof document !== "undefined" ? document : void 0;
|
|
4751
|
+
const inBackgroundSince = { current: null };
|
|
4752
|
+
function onVisibilityChange() {
|
|
4753
|
+
if (doc?.visibilityState === "hidden") {
|
|
4754
|
+
inBackgroundSince.current = inBackgroundSince.current ?? Date.now();
|
|
4755
|
+
} else {
|
|
4756
|
+
inBackgroundSince.current = null;
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
doc?.addEventListener("visibilitychange", onVisibilityChange);
|
|
4760
|
+
const unsub = () => {
|
|
4761
|
+
doc?.removeEventListener("visibilitychange", onVisibilityChange);
|
|
4762
|
+
};
|
|
4763
|
+
return [inBackgroundSince, unsub];
|
|
4764
|
+
}
|
|
4701
4765
|
function createRoom(options, config) {
|
|
4702
4766
|
const initialPresence = typeof options.initialPresence === "function" ? options.initialPresence(config.roomId) : options.initialPresence;
|
|
4703
4767
|
const initialStorage = typeof options.initialStorage === "function" ? options.initialStorage(config.roomId) : options.initialStorage;
|
|
4704
|
-
const
|
|
4768
|
+
const [inBackgroundSince, uninstallBgTabSpy] = installBackgroundTabSpy();
|
|
4769
|
+
const delegates = {
|
|
4770
|
+
...config.delegates,
|
|
4771
|
+
// A connection is allowed to go into "zombie state" only if all of the
|
|
4772
|
+
// following conditions apply:
|
|
4773
|
+
//
|
|
4774
|
+
// - The `backgroundKeepAliveTimeout` client option is configured
|
|
4775
|
+
// - The browser window has been in the background for at least
|
|
4776
|
+
// `backgroundKeepAliveTimeout` milliseconds
|
|
4777
|
+
// - There are no pending changes
|
|
4778
|
+
//
|
|
4779
|
+
canZombie() {
|
|
4780
|
+
return config.backgroundKeepAliveTimeout !== void 0 && inBackgroundSince.current !== null && Date.now() > inBackgroundSince.current + config.backgroundKeepAliveTimeout && getStorageStatus() !== "synchronizing";
|
|
4781
|
+
}
|
|
4782
|
+
};
|
|
4705
4783
|
const managedSocket = new ManagedSocket(
|
|
4706
4784
|
delegates,
|
|
4707
4785
|
config.enableDebugLogging
|
|
@@ -4901,15 +4979,13 @@ function createRoom(options, config) {
|
|
|
4901
4979
|
comments: makeEventSource()
|
|
4902
4980
|
};
|
|
4903
4981
|
async function httpSend(authTokenOrPublicApiKey, roomId, nonce, messages) {
|
|
4904
|
-
const baseUrl = new URL(config.liveblocksServer);
|
|
4905
|
-
baseUrl.protocol = "https";
|
|
4906
4982
|
const url = new URL(
|
|
4907
4983
|
`/v2/c/rooms/${encodeURIComponent(roomId)}/send-message`,
|
|
4908
|
-
baseUrl
|
|
4909
|
-
);
|
|
4984
|
+
config.baseUrl
|
|
4985
|
+
).toString();
|
|
4910
4986
|
const fetcher = config.polyfills?.fetch || /* istanbul ignore next */
|
|
4911
4987
|
fetch;
|
|
4912
|
-
return fetcher(url
|
|
4988
|
+
return fetcher(url, {
|
|
4913
4989
|
method: "POST",
|
|
4914
4990
|
headers: {
|
|
4915
4991
|
"Content-Type": "application/json",
|
|
@@ -4990,7 +5066,7 @@ function createRoom(options, config) {
|
|
|
4990
5066
|
const stackSizeBefore = context.undoStack.length;
|
|
4991
5067
|
for (const key in context.initialStorage) {
|
|
4992
5068
|
if (context.root.get(key) === void 0) {
|
|
4993
|
-
context.root.set(key, context.initialStorage[key]);
|
|
5069
|
+
context.root.set(key, cloneLson(context.initialStorage[key]));
|
|
4994
5070
|
}
|
|
4995
5071
|
}
|
|
4996
5072
|
context.undoStack.length = stackSizeBefore;
|
|
@@ -5021,25 +5097,23 @@ function createRoom(options, config) {
|
|
|
5021
5097
|
_addToRealUndoStack(historyOps, batchedUpdatesWrapper);
|
|
5022
5098
|
}
|
|
5023
5099
|
}
|
|
5024
|
-
function notify({
|
|
5025
|
-
storageUpdates =
|
|
5026
|
-
|
|
5027
|
-
others: otherEvents = []
|
|
5028
|
-
}, batchedUpdatesWrapper) {
|
|
5100
|
+
function notify(updates, batchedUpdatesWrapper) {
|
|
5101
|
+
const storageUpdates = updates.storageUpdates;
|
|
5102
|
+
const othersUpdates = updates.others;
|
|
5029
5103
|
batchedUpdatesWrapper(() => {
|
|
5030
|
-
if (
|
|
5104
|
+
if (othersUpdates !== void 0 && othersUpdates.length > 0) {
|
|
5031
5105
|
const others = context.others.current;
|
|
5032
|
-
for (const event of
|
|
5033
|
-
eventHub.others.notify({
|
|
5106
|
+
for (const event of othersUpdates) {
|
|
5107
|
+
eventHub.others.notify({ ...event, others });
|
|
5034
5108
|
}
|
|
5035
5109
|
}
|
|
5036
|
-
if (presence) {
|
|
5110
|
+
if (updates.presence ?? false) {
|
|
5037
5111
|
notifySelfChanged(doNotBatchUpdates);
|
|
5038
5112
|
eventHub.myPresence.notify(context.myPresence.current);
|
|
5039
5113
|
}
|
|
5040
|
-
if (storageUpdates.size > 0) {
|
|
5041
|
-
const
|
|
5042
|
-
eventHub.storage.notify(
|
|
5114
|
+
if (storageUpdates !== void 0 && storageUpdates.size > 0) {
|
|
5115
|
+
const updates2 = Array.from(storageUpdates.values());
|
|
5116
|
+
eventHub.storage.notify(updates2);
|
|
5043
5117
|
}
|
|
5044
5118
|
notifyStorageStatus();
|
|
5045
5119
|
});
|
|
@@ -5705,7 +5779,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5705
5779
|
comments: eventHub.comments.observable
|
|
5706
5780
|
};
|
|
5707
5781
|
const commentsApi = createCommentsApi(config.roomId, delegates.authenticate, {
|
|
5708
|
-
|
|
5782
|
+
baseUrl: config.baseUrl
|
|
5709
5783
|
});
|
|
5710
5784
|
return Object.defineProperty(
|
|
5711
5785
|
{
|
|
@@ -5738,7 +5812,10 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5738
5812
|
connect: () => managedSocket.connect(),
|
|
5739
5813
|
reconnect: () => managedSocket.reconnect(),
|
|
5740
5814
|
disconnect: () => managedSocket.disconnect(),
|
|
5741
|
-
destroy: () =>
|
|
5815
|
+
destroy: () => {
|
|
5816
|
+
uninstallBgTabSpy();
|
|
5817
|
+
managedSocket.destroy();
|
|
5818
|
+
},
|
|
5742
5819
|
// Presence
|
|
5743
5820
|
updatePresence,
|
|
5744
5821
|
updateYDoc,
|
|
@@ -5809,9 +5886,10 @@ function makeClassicSubscribeFn(events) {
|
|
|
5809
5886
|
return events.myPresence.subscribe(callback);
|
|
5810
5887
|
case "others": {
|
|
5811
5888
|
const cb = callback;
|
|
5812
|
-
return events.others.subscribe(
|
|
5813
|
-
|
|
5814
|
-
|
|
5889
|
+
return events.others.subscribe((event) => {
|
|
5890
|
+
const { others, ...internalEvent } = event;
|
|
5891
|
+
return cb(others, internalEvent);
|
|
5892
|
+
});
|
|
5815
5893
|
}
|
|
5816
5894
|
case "error":
|
|
5817
5895
|
return events.error.subscribe(callback);
|
|
@@ -5870,15 +5948,17 @@ function makeAuthDelegateForRoom(roomId, authManager) {
|
|
|
5870
5948
|
return authManager.getAuthValue("room:read", roomId);
|
|
5871
5949
|
};
|
|
5872
5950
|
}
|
|
5873
|
-
function makeCreateSocketDelegateForRoom(roomId,
|
|
5951
|
+
function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill) {
|
|
5874
5952
|
return (authValue) => {
|
|
5875
5953
|
const ws = WebSocketPolyfill ?? (typeof WebSocket === "undefined" ? void 0 : WebSocket);
|
|
5876
5954
|
if (ws === void 0) {
|
|
5877
5955
|
throw new StopRetrying(
|
|
5878
|
-
"To use Liveblocks client in a non-
|
|
5956
|
+
"To use Liveblocks client in a non-DOM environment, you need to provide a WebSocket polyfill."
|
|
5879
5957
|
);
|
|
5880
5958
|
}
|
|
5881
|
-
const url = new URL(
|
|
5959
|
+
const url = new URL(baseUrl);
|
|
5960
|
+
url.protocol = url.protocol === "http:" ? "ws" : "wss";
|
|
5961
|
+
url.pathname = "/v7";
|
|
5882
5962
|
url.searchParams.set("roomId", roomId);
|
|
5883
5963
|
if (authValue.type === "secret") {
|
|
5884
5964
|
url.searchParams.set("tok", authValue.token.raw);
|
|
@@ -5896,13 +5976,20 @@ function makeCreateSocketDelegateForRoom(roomId, liveblocksServer, WebSocketPoly
|
|
|
5896
5976
|
var MIN_THROTTLE = 16;
|
|
5897
5977
|
var MAX_THROTTLE = 1e3;
|
|
5898
5978
|
var DEFAULT_THROTTLE = 100;
|
|
5979
|
+
var MIN_BACKGROUND_KEEP_ALIVE_TIMEOUT = 6e4;
|
|
5899
5980
|
var MIN_LOST_CONNECTION_TIMEOUT = 200;
|
|
5900
5981
|
var RECOMMENDED_MIN_LOST_CONNECTION_TIMEOUT = 1e3;
|
|
5901
5982
|
var MAX_LOST_CONNECTION_TIMEOUT = 3e4;
|
|
5902
5983
|
var DEFAULT_LOST_CONNECTION_TIMEOUT = 5e3;
|
|
5903
|
-
function
|
|
5904
|
-
|
|
5905
|
-
|
|
5984
|
+
function getBaseUrlFromClientOptions(clientOptions) {
|
|
5985
|
+
if ("liveblocksServer" in clientOptions) {
|
|
5986
|
+
throw new Error("Client option no longer supported");
|
|
5987
|
+
}
|
|
5988
|
+
if (typeof clientOptions.baseUrl === "string" && clientOptions.baseUrl.startsWith("http")) {
|
|
5989
|
+
return clientOptions.baseUrl;
|
|
5990
|
+
} else {
|
|
5991
|
+
return DEFAULT_BASE_URL;
|
|
5992
|
+
}
|
|
5906
5993
|
}
|
|
5907
5994
|
function createClient(options) {
|
|
5908
5995
|
const clientOptions = options;
|
|
@@ -5910,6 +5997,9 @@ function createClient(options) {
|
|
|
5910
5997
|
const lostConnectionTimeout = getLostConnectionTimeout(
|
|
5911
5998
|
clientOptions.lostConnectionTimeout ?? DEFAULT_LOST_CONNECTION_TIMEOUT
|
|
5912
5999
|
);
|
|
6000
|
+
const backgroundKeepAliveTimeout = getBackgroundKeepAliveTimeout(
|
|
6001
|
+
clientOptions.backgroundKeepAliveTimeout
|
|
6002
|
+
);
|
|
5913
6003
|
const authManager = createAuthManager(options);
|
|
5914
6004
|
const roomsById = /* @__PURE__ */ new Map();
|
|
5915
6005
|
function teardownRoom(room) {
|
|
@@ -5945,6 +6035,7 @@ function createClient(options) {
|
|
|
5945
6035
|
options2.initialPresence === null || options2.initialPresence === void 0,
|
|
5946
6036
|
"Please provide an initial presence value for the current user when entering the room."
|
|
5947
6037
|
);
|
|
6038
|
+
const baseUrl = getBaseUrlFromClientOptions(clientOptions);
|
|
5948
6039
|
const newRoom = createRoom(
|
|
5949
6040
|
{
|
|
5950
6041
|
initialPresence: options2.initialPresence ?? {},
|
|
@@ -5954,18 +6045,19 @@ function createClient(options) {
|
|
|
5954
6045
|
roomId,
|
|
5955
6046
|
throttleDelay,
|
|
5956
6047
|
lostConnectionTimeout,
|
|
6048
|
+
backgroundKeepAliveTimeout,
|
|
5957
6049
|
polyfills: clientOptions.polyfills,
|
|
5958
6050
|
delegates: clientOptions.mockedDelegates ?? {
|
|
5959
6051
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
5960
6052
|
roomId,
|
|
5961
|
-
|
|
6053
|
+
baseUrl,
|
|
5962
6054
|
clientOptions.polyfills?.WebSocket
|
|
5963
6055
|
),
|
|
5964
6056
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
5965
6057
|
},
|
|
5966
6058
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
5967
6059
|
unstable_batchedUpdates: options2?.unstable_batchedUpdates,
|
|
5968
|
-
|
|
6060
|
+
baseUrl,
|
|
5969
6061
|
unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP
|
|
5970
6062
|
}
|
|
5971
6063
|
);
|
|
@@ -6004,7 +6096,16 @@ function createClient(options) {
|
|
|
6004
6096
|
unsub();
|
|
6005
6097
|
}
|
|
6006
6098
|
}
|
|
6099
|
+
function logout() {
|
|
6100
|
+
authManager.reset();
|
|
6101
|
+
for (const { room } of roomsById.values()) {
|
|
6102
|
+
if (!isIdle(room.getStatus())) {
|
|
6103
|
+
room.reconnect();
|
|
6104
|
+
}
|
|
6105
|
+
}
|
|
6106
|
+
}
|
|
6007
6107
|
return {
|
|
6108
|
+
logout,
|
|
6008
6109
|
// Old, deprecated APIs
|
|
6009
6110
|
enter,
|
|
6010
6111
|
getRoom,
|
|
@@ -6014,13 +6115,28 @@ function createClient(options) {
|
|
|
6014
6115
|
};
|
|
6015
6116
|
}
|
|
6016
6117
|
function checkBounds(option, value, min, max, recommendedMin) {
|
|
6017
|
-
if (typeof value !== "number" || value < min || value > max) {
|
|
6118
|
+
if (typeof value !== "number" || value < min || max === void 0 || value > max) {
|
|
6018
6119
|
throw new Error(
|
|
6019
|
-
`${option} should be
|
|
6120
|
+
max !== void 0 ? `${option} should be between ${recommendedMin ?? min} and ${max}.` : `${option} should be at least ${recommendedMin ?? min}.`
|
|
6020
6121
|
);
|
|
6021
6122
|
}
|
|
6022
6123
|
return value;
|
|
6023
6124
|
}
|
|
6125
|
+
function getBackgroundKeepAliveTimeout(value) {
|
|
6126
|
+
if (value === void 0)
|
|
6127
|
+
return void 0;
|
|
6128
|
+
if (typeof document === "undefined") {
|
|
6129
|
+
warn(
|
|
6130
|
+
"Setting backgroundKeepAliveTimeout won't have an effect in a non-DOM environment."
|
|
6131
|
+
);
|
|
6132
|
+
return void 0;
|
|
6133
|
+
}
|
|
6134
|
+
return checkBounds(
|
|
6135
|
+
"backgroundKeepAliveTimeout",
|
|
6136
|
+
value,
|
|
6137
|
+
MIN_BACKGROUND_KEEP_ALIVE_TIMEOUT
|
|
6138
|
+
);
|
|
6139
|
+
}
|
|
6024
6140
|
function getThrottle(value) {
|
|
6025
6141
|
return checkBounds("throttle", value, MIN_THROTTLE, MAX_THROTTLE);
|
|
6026
6142
|
}
|
|
@@ -6640,6 +6756,7 @@ export {
|
|
|
6640
6756
|
assert,
|
|
6641
6757
|
assertNever,
|
|
6642
6758
|
b64decode,
|
|
6759
|
+
cloneLson,
|
|
6643
6760
|
fancy_console_exports as console,
|
|
6644
6761
|
createAsyncCache,
|
|
6645
6762
|
createClient,
|