@liveblocks/core 1.1.6 → 1.1.8
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 +224 -211
- package/dist/index.d.ts +224 -211
- package/dist/index.js +43 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
2
|
var PKG_NAME = "@liveblocks/core";
|
|
3
|
-
var PKG_VERSION = "1.1.
|
|
3
|
+
var PKG_VERSION = "1.1.8";
|
|
4
4
|
var PKG_FORMAT = "esm";
|
|
5
5
|
|
|
6
6
|
// src/dupe-detection.ts
|
|
@@ -195,7 +195,7 @@ function startSyncStream(room) {
|
|
|
195
195
|
// Any time storage updates, send the new storage root
|
|
196
196
|
room.events.storage.subscribe(() => partialSyncStorage(room)),
|
|
197
197
|
// Any time "me" or "others" updates, send the new values accordingly
|
|
198
|
-
room.events.
|
|
198
|
+
room.events.self.subscribe(() => partialSyncMe(room)),
|
|
199
199
|
room.events.others.subscribe(() => partialSyncOthers(room))
|
|
200
200
|
]);
|
|
201
201
|
}
|
|
@@ -3893,16 +3893,11 @@ function isJsonObject(data) {
|
|
|
3893
3893
|
}
|
|
3894
3894
|
|
|
3895
3895
|
// src/protocol/AuthToken.ts
|
|
3896
|
-
function isTokenExpired(token) {
|
|
3897
|
-
const now = Date.now() / 1e3;
|
|
3898
|
-
const valid = now <= token.exp - 300 && now >= token.iat - 300;
|
|
3899
|
-
return !valid;
|
|
3900
|
-
}
|
|
3901
3896
|
function isStringList(value) {
|
|
3902
3897
|
return Array.isArray(value) && value.every((i) => typeof i === "string");
|
|
3903
3898
|
}
|
|
3904
3899
|
function isMinimalTokenPayload(data) {
|
|
3905
|
-
return isPlainObject(data) && typeof data.
|
|
3900
|
+
return isPlainObject(data) && typeof data.actor === "number" && (data.id === void 0 || typeof data.id === "string") && isStringList(data.scopes);
|
|
3906
3901
|
}
|
|
3907
3902
|
function parseAuthToken(rawTokenString) {
|
|
3908
3903
|
const tokenParts = rawTokenString.split(".");
|
|
@@ -4243,6 +4238,7 @@ function createRoom(options, config) {
|
|
|
4243
4238
|
batchUpdates(() => {
|
|
4244
4239
|
eventHub.status.notify(newStatus);
|
|
4245
4240
|
eventHub.connection.notify(newToLegacyStatus(newStatus));
|
|
4241
|
+
notifySelfChanged(doNotBatchUpdates);
|
|
4246
4242
|
});
|
|
4247
4243
|
}
|
|
4248
4244
|
let _connectionLossTimerId;
|
|
@@ -4366,7 +4362,8 @@ function createRoom(options, config) {
|
|
|
4366
4362
|
// New/recommended API
|
|
4367
4363
|
lostConnection: makeEventSource(),
|
|
4368
4364
|
customEvent: makeEventSource(),
|
|
4369
|
-
|
|
4365
|
+
self: makeEventSource(),
|
|
4366
|
+
myPresence: makeEventSource(),
|
|
4370
4367
|
others: makeEventSource(),
|
|
4371
4368
|
error: makeEventSource(),
|
|
4372
4369
|
storage: makeEventSource(),
|
|
@@ -4380,15 +4377,16 @@ function createRoom(options, config) {
|
|
|
4380
4377
|
if (config.unstable_fallbackToHTTP) {
|
|
4381
4378
|
const size = new TextEncoder().encode(message).length;
|
|
4382
4379
|
if (size > MAX_MESSAGE_SIZE && managedSocket.token?.raw && config.httpSendEndpoint) {
|
|
4383
|
-
if (isTokenExpired(managedSocket.token.parsed)) {
|
|
4384
|
-
return managedSocket.reconnect();
|
|
4385
|
-
}
|
|
4386
4380
|
void httpSend(
|
|
4387
4381
|
message,
|
|
4388
4382
|
managedSocket.token.raw,
|
|
4389
4383
|
config.httpSendEndpoint,
|
|
4390
4384
|
config.polyfills?.fetch
|
|
4391
|
-
)
|
|
4385
|
+
).then((resp) => {
|
|
4386
|
+
if (!resp.ok && resp.status === 403) {
|
|
4387
|
+
managedSocket.reconnect();
|
|
4388
|
+
}
|
|
4389
|
+
});
|
|
4392
4390
|
warn(
|
|
4393
4391
|
"Message was too large for websockets and sent over HTTP instead"
|
|
4394
4392
|
);
|
|
@@ -4410,6 +4408,16 @@ function createRoom(options, config) {
|
|
|
4410
4408
|
} : null;
|
|
4411
4409
|
}
|
|
4412
4410
|
);
|
|
4411
|
+
let _lastSelf;
|
|
4412
|
+
function notifySelfChanged(batchedUpdatesWrapper) {
|
|
4413
|
+
const currSelf = self.current;
|
|
4414
|
+
if (currSelf !== null && currSelf !== _lastSelf) {
|
|
4415
|
+
batchedUpdatesWrapper(() => {
|
|
4416
|
+
eventHub.self.notify(currSelf);
|
|
4417
|
+
});
|
|
4418
|
+
_lastSelf = currSelf;
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4413
4421
|
const selfAsTreeNode = new DerivedRef(
|
|
4414
4422
|
self,
|
|
4415
4423
|
(me) => me !== null ? userToTreeNode("Me", me) : null
|
|
@@ -4468,12 +4476,14 @@ function createRoom(options, config) {
|
|
|
4468
4476
|
}
|
|
4469
4477
|
}
|
|
4470
4478
|
if (presence) {
|
|
4471
|
-
|
|
4479
|
+
notifySelfChanged(doNotBatchUpdates);
|
|
4480
|
+
eventHub.myPresence.notify(context.me.current);
|
|
4472
4481
|
}
|
|
4473
4482
|
if (storageUpdates.size > 0) {
|
|
4474
4483
|
const updates = Array.from(storageUpdates.values());
|
|
4475
4484
|
eventHub.storage.notify(updates);
|
|
4476
4485
|
}
|
|
4486
|
+
notifyStorageStatus();
|
|
4477
4487
|
});
|
|
4478
4488
|
}
|
|
4479
4489
|
function getConnectionId() {
|
|
@@ -4549,7 +4559,6 @@ function createRoom(options, config) {
|
|
|
4549
4559
|
}
|
|
4550
4560
|
}
|
|
4551
4561
|
}
|
|
4552
|
-
notifyStorageStatus();
|
|
4553
4562
|
return {
|
|
4554
4563
|
ops,
|
|
4555
4564
|
reverse: output.reverse,
|
|
@@ -4793,7 +4802,7 @@ function createRoom(options, config) {
|
|
|
4793
4802
|
break;
|
|
4794
4803
|
}
|
|
4795
4804
|
case 300 /* UPDATE_YDOC */: {
|
|
4796
|
-
eventHub.ydoc.notify(message
|
|
4805
|
+
eventHub.ydoc.notify(message);
|
|
4797
4806
|
break;
|
|
4798
4807
|
}
|
|
4799
4808
|
case 104 /* ROOM_STATE */: {
|
|
@@ -5101,7 +5110,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5101
5110
|
lostConnection: eventHub.lostConnection.observable,
|
|
5102
5111
|
customEvent: eventHub.customEvent.observable,
|
|
5103
5112
|
others: eventHub.others.observable,
|
|
5104
|
-
|
|
5113
|
+
self: eventHub.self.observable,
|
|
5114
|
+
myPresence: eventHub.myPresence.observable,
|
|
5105
5115
|
error: eventHub.error.observable,
|
|
5106
5116
|
storage: eventHub.storage.observable,
|
|
5107
5117
|
history: eventHub.history.observable,
|
|
@@ -5207,7 +5217,7 @@ function makeClassicSubscribeFn(events) {
|
|
|
5207
5217
|
callback
|
|
5208
5218
|
);
|
|
5209
5219
|
case "my-presence":
|
|
5210
|
-
return events.
|
|
5220
|
+
return events.myPresence.subscribe(callback);
|
|
5211
5221
|
case "others": {
|
|
5212
5222
|
const cb = callback;
|
|
5213
5223
|
return events.others.subscribe(
|
|
@@ -5315,12 +5325,25 @@ function makeAuthDelegateForRoom(roomId, authentication, fetchPolyfill) {
|
|
|
5315
5325
|
} else if (authentication.type === "custom") {
|
|
5316
5326
|
return async () => {
|
|
5317
5327
|
const response = await authentication.callback(roomId);
|
|
5318
|
-
if (!response ||
|
|
5328
|
+
if (!response || typeof response !== "object") {
|
|
5329
|
+
throw new Error(
|
|
5330
|
+
'We expect the authentication callback to return a token, but it does not. Hint: the return value should look like: { token: "..." }'
|
|
5331
|
+
);
|
|
5332
|
+
}
|
|
5333
|
+
if (typeof response.token === "string") {
|
|
5334
|
+
return parseAuthToken(response.token);
|
|
5335
|
+
} else if (typeof response.error === "string") {
|
|
5336
|
+
const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
|
|
5337
|
+
if (response.error === "forbidden") {
|
|
5338
|
+
throw new StopRetrying(reason);
|
|
5339
|
+
} else {
|
|
5340
|
+
throw new Error(reason);
|
|
5341
|
+
}
|
|
5342
|
+
} else {
|
|
5319
5343
|
throw new Error(
|
|
5320
5344
|
'We expect the authentication callback to return a token, but it does not. Hint: the return value should look like: { token: "..." }'
|
|
5321
5345
|
);
|
|
5322
5346
|
}
|
|
5323
|
-
return parseAuthToken(response.token);
|
|
5324
5347
|
};
|
|
5325
5348
|
} else {
|
|
5326
5349
|
throw new Error("Internal error. Unexpected authentication type");
|