@liveblocks/core 1.2.0-internal1 → 1.2.0-internal3
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 +50 -15
- package/dist/index.js +108 -83
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -686,11 +686,11 @@ declare function asArrayWithLegacyMethods<T>(arr: readonly T[]): ReadonlyArrayWi
|
|
|
686
686
|
*/
|
|
687
687
|
declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
|
|
688
688
|
/**
|
|
689
|
-
* The connection
|
|
689
|
+
* The connection ID of the User. It is unique and increment at every new connection.
|
|
690
690
|
*/
|
|
691
691
|
readonly connectionId: number;
|
|
692
692
|
/**
|
|
693
|
-
* The
|
|
693
|
+
* The ID of the User that has been set in the authentication endpoint.
|
|
694
694
|
* Useful to get additional information about the connected user.
|
|
695
695
|
*/
|
|
696
696
|
readonly id: TUserMeta["id"];
|
|
@@ -699,13 +699,20 @@ declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta>
|
|
|
699
699
|
*/
|
|
700
700
|
readonly info: TUserMeta["info"];
|
|
701
701
|
/**
|
|
702
|
-
* The user presence.
|
|
702
|
+
* The user’s presence data.
|
|
703
703
|
*/
|
|
704
704
|
readonly presence: TPresence;
|
|
705
705
|
/**
|
|
706
|
-
*
|
|
706
|
+
* @deprecated Use `!user.canWrite` instead.
|
|
707
|
+
* False if the user can mutate the Room’s Storage and/or YDoc, true if they
|
|
708
|
+
* can only read but not mutate it.
|
|
707
709
|
*/
|
|
708
710
|
readonly isReadOnly: boolean;
|
|
711
|
+
/**
|
|
712
|
+
* True if the user can mutate the Room’s Storage and/or YDoc, false if they
|
|
713
|
+
* can only read but not mutate it.
|
|
714
|
+
*/
|
|
715
|
+
readonly canWrite: boolean;
|
|
709
716
|
};
|
|
710
717
|
|
|
711
718
|
/**
|
|
@@ -1548,6 +1555,33 @@ declare enum ServerMsgCode {
|
|
|
1548
1555
|
REJECT_STORAGE_OP = 299,
|
|
1549
1556
|
UPDATE_YDOC = 300
|
|
1550
1557
|
}
|
|
1558
|
+
/**
|
|
1559
|
+
* Traits are bitflags that are used at the protocol level to communicate what
|
|
1560
|
+
* traits a given User has. Traits may or may not map to official permissions.
|
|
1561
|
+
* Users cannot see each other's true permissions, but they can see each
|
|
1562
|
+
* other's traits.
|
|
1563
|
+
*
|
|
1564
|
+
* Traits are not a security feature, but should only be used to optimize the
|
|
1565
|
+
* app experience (e.g. to visually indicate that another connected user has no
|
|
1566
|
+
* write access to the document).
|
|
1567
|
+
*/
|
|
1568
|
+
declare enum Traits {
|
|
1569
|
+
None = 0,
|
|
1570
|
+
/**
|
|
1571
|
+
* Whether the user has write access to Storage™ + YDoc.
|
|
1572
|
+
* Maps to the public `User.canWrite` property.
|
|
1573
|
+
*/
|
|
1574
|
+
CanWriteDocument = 1,
|
|
1575
|
+
/**
|
|
1576
|
+
* Whether the user has access to Comments™.
|
|
1577
|
+
* Maps to the public `User.canComment` property.
|
|
1578
|
+
*/
|
|
1579
|
+
CanWriteComments = 2,
|
|
1580
|
+
/**
|
|
1581
|
+
* Convenience accessor only, where all the bitflags are enabled.
|
|
1582
|
+
*/
|
|
1583
|
+
All = 3
|
|
1584
|
+
}
|
|
1551
1585
|
/**
|
|
1552
1586
|
* Messages that can be sent from the server to the client.
|
|
1553
1587
|
*/
|
|
@@ -1622,9 +1656,10 @@ declare type UserJoinServerMsg<TUserMeta extends BaseUserMeta> = {
|
|
|
1622
1656
|
*/
|
|
1623
1657
|
readonly info: TUserMeta["info"];
|
|
1624
1658
|
/**
|
|
1625
|
-
*
|
|
1659
|
+
* Informs the client what Traits this (other) User has.
|
|
1660
|
+
* @since v1.2 (WS API v7)
|
|
1626
1661
|
*/
|
|
1627
|
-
readonly
|
|
1662
|
+
readonly traits: Traits;
|
|
1628
1663
|
};
|
|
1629
1664
|
/**
|
|
1630
1665
|
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
@@ -1665,21 +1700,21 @@ declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = {
|
|
|
1665
1700
|
*/
|
|
1666
1701
|
declare type RoomStateServerMsg<TUserMeta extends BaseUserMeta> = {
|
|
1667
1702
|
readonly type: ServerMsgCode.ROOM_STATE;
|
|
1668
|
-
readonly users: {
|
|
1669
|
-
readonly [actor: number]: TUserMeta & {
|
|
1670
|
-
scopes: string[];
|
|
1671
|
-
};
|
|
1672
|
-
};
|
|
1673
1703
|
/**
|
|
1674
|
-
* Informs the client what their actor ID is.
|
|
1704
|
+
* Informs the client what their actor ID is going to be.
|
|
1675
1705
|
* @since v1.2 (WS API v7)
|
|
1676
1706
|
*/
|
|
1677
1707
|
readonly actor: number;
|
|
1678
1708
|
/**
|
|
1679
|
-
* Informs the client
|
|
1709
|
+
* Informs the client what Traits the current User (self) has.
|
|
1680
1710
|
* @since v1.2 (WS API v7)
|
|
1681
1711
|
*/
|
|
1682
|
-
readonly
|
|
1712
|
+
readonly traits: Traits;
|
|
1713
|
+
readonly users: {
|
|
1714
|
+
readonly [otherActor: number]: TUserMeta & {
|
|
1715
|
+
traits: Traits;
|
|
1716
|
+
};
|
|
1717
|
+
};
|
|
1683
1718
|
};
|
|
1684
1719
|
/**
|
|
1685
1720
|
* Sent by the WebSocket server to a single client in response to the client
|
|
@@ -1900,4 +1935,4 @@ declare type EnsureJson<T> = [
|
|
|
1900
1935
|
[K in keyof T]: EnsureJson<T[K]>;
|
|
1901
1936
|
};
|
|
1902
1937
|
|
|
1903
|
-
export { AckOp, BaseAuthResult, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ToImmutable, ToJson, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, asArrayWithLegacyMethods, asPos, assert, assertNever, b64decode, createClient, deprecate, deprecateIf, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makePosition, nn, patchLiveObjectKey, shallow, throwUsageError, toPlainLson, tryParseJson, withTimeout };
|
|
1938
|
+
export { AckOp, BaseAuthResult, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ToImmutable, ToJson, Traits, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, asArrayWithLegacyMethods, asPos, assert, assertNever, b64decode, createClient, deprecate, deprecateIf, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makePosition, nn, patchLiveObjectKey, shallow, throwUsageError, toPlainLson, tryParseJson, withTimeout };
|
package/dist/index.js
CHANGED
|
@@ -145,7 +145,7 @@ var onMessageFromPanel = eventSource.observable;
|
|
|
145
145
|
// src/devtools/index.ts
|
|
146
146
|
var VERSION = true ? (
|
|
147
147
|
/* istanbul ignore next */
|
|
148
|
-
"1.2.0-
|
|
148
|
+
"1.2.0-internal3"
|
|
149
149
|
) : "dev";
|
|
150
150
|
var _devtoolsSetupHasRun = false;
|
|
151
151
|
function setupDevTools(getAllRooms) {
|
|
@@ -3973,6 +3973,19 @@ var ServerMsgCode = /* @__PURE__ */ ((ServerMsgCode2) => {
|
|
|
3973
3973
|
return ServerMsgCode2;
|
|
3974
3974
|
})(ServerMsgCode || {});
|
|
3975
3975
|
|
|
3976
|
+
// src/lib/LegacyArray.ts
|
|
3977
|
+
function asArrayWithLegacyMethods(arr) {
|
|
3978
|
+
Object.defineProperty(arr, "count", {
|
|
3979
|
+
value: arr.length,
|
|
3980
|
+
enumerable: false
|
|
3981
|
+
});
|
|
3982
|
+
Object.defineProperty(arr, "toArray", {
|
|
3983
|
+
value: () => arr,
|
|
3984
|
+
enumerable: false
|
|
3985
|
+
});
|
|
3986
|
+
return freeze(arr);
|
|
3987
|
+
}
|
|
3988
|
+
|
|
3976
3989
|
// src/refs/ImmutableRef.ts
|
|
3977
3990
|
function merge(target, patch) {
|
|
3978
3991
|
let updated = false;
|
|
@@ -4010,45 +4023,21 @@ var ImmutableRef = class {
|
|
|
4010
4023
|
}
|
|
4011
4024
|
};
|
|
4012
4025
|
|
|
4013
|
-
// src/refs/MeRef.ts
|
|
4014
|
-
var MeRef = class extends ImmutableRef {
|
|
4015
|
-
constructor(initialPresence) {
|
|
4016
|
-
super();
|
|
4017
|
-
this._me = freeze(compactObject(initialPresence));
|
|
4018
|
-
}
|
|
4019
|
-
/** @internal */
|
|
4020
|
-
_toImmutable() {
|
|
4021
|
-
return this._me;
|
|
4022
|
-
}
|
|
4023
|
-
/**
|
|
4024
|
-
* Patches the current "me" instance.
|
|
4025
|
-
*/
|
|
4026
|
-
patch(patch) {
|
|
4027
|
-
const oldMe = this._me;
|
|
4028
|
-
const newMe = merge(oldMe, patch);
|
|
4029
|
-
if (oldMe !== newMe) {
|
|
4030
|
-
this._me = freeze(newMe);
|
|
4031
|
-
this.invalidate();
|
|
4032
|
-
}
|
|
4033
|
-
}
|
|
4034
|
-
};
|
|
4035
|
-
|
|
4036
|
-
// src/lib/LegacyArray.ts
|
|
4037
|
-
function asArrayWithLegacyMethods(arr) {
|
|
4038
|
-
Object.defineProperty(arr, "count", {
|
|
4039
|
-
value: arr.length,
|
|
4040
|
-
enumerable: false
|
|
4041
|
-
});
|
|
4042
|
-
Object.defineProperty(arr, "toArray", {
|
|
4043
|
-
value: () => arr,
|
|
4044
|
-
enumerable: false
|
|
4045
|
-
});
|
|
4046
|
-
return freeze(arr);
|
|
4047
|
-
}
|
|
4048
|
-
|
|
4049
4026
|
// src/refs/OthersRef.ts
|
|
4050
4027
|
function makeUser(conn, presence) {
|
|
4051
|
-
|
|
4028
|
+
const { connectionId, id, info, traits } = conn;
|
|
4029
|
+
const canWrite = (traits & 1 /* CanWriteDocument */) === 1 /* CanWriteDocument */;
|
|
4030
|
+
return freeze(
|
|
4031
|
+
compactObject({
|
|
4032
|
+
connectionId,
|
|
4033
|
+
id,
|
|
4034
|
+
info,
|
|
4035
|
+
canWrite,
|
|
4036
|
+
isReadOnly: !canWrite,
|
|
4037
|
+
// Deprecated, kept for backward-compatibility
|
|
4038
|
+
presence
|
|
4039
|
+
})
|
|
4040
|
+
);
|
|
4052
4041
|
}
|
|
4053
4042
|
var OthersRef = class extends ImmutableRef {
|
|
4054
4043
|
//
|
|
@@ -4107,12 +4096,12 @@ var OthersRef = class extends ImmutableRef {
|
|
|
4107
4096
|
* Records a known connection. This records the connection ID and the
|
|
4108
4097
|
* associated metadata.
|
|
4109
4098
|
*/
|
|
4110
|
-
setConnection(connectionId, metaUserId, metaUserInfo
|
|
4099
|
+
setConnection(connectionId, traits, metaUserId, metaUserInfo) {
|
|
4111
4100
|
this._connections[connectionId] = freeze({
|
|
4112
|
-
connectionId,
|
|
4113
4101
|
id: metaUserId,
|
|
4114
4102
|
info: metaUserInfo,
|
|
4115
|
-
|
|
4103
|
+
connectionId,
|
|
4104
|
+
traits
|
|
4116
4105
|
});
|
|
4117
4106
|
if (this._presences[connectionId] !== void 0) {
|
|
4118
4107
|
this._invalidateUser(connectionId);
|
|
@@ -4155,6 +4144,29 @@ var OthersRef = class extends ImmutableRef {
|
|
|
4155
4144
|
}
|
|
4156
4145
|
};
|
|
4157
4146
|
|
|
4147
|
+
// src/refs/PatchableRef.ts
|
|
4148
|
+
var PatchableRef = class extends ImmutableRef {
|
|
4149
|
+
constructor(data) {
|
|
4150
|
+
super();
|
|
4151
|
+
this._data = freeze(compactObject(data));
|
|
4152
|
+
}
|
|
4153
|
+
/** @internal */
|
|
4154
|
+
_toImmutable() {
|
|
4155
|
+
return this._data;
|
|
4156
|
+
}
|
|
4157
|
+
/**
|
|
4158
|
+
* Patches the current object.
|
|
4159
|
+
*/
|
|
4160
|
+
patch(patch) {
|
|
4161
|
+
const oldMe = this._data;
|
|
4162
|
+
const newMe = merge(oldMe, patch);
|
|
4163
|
+
if (oldMe !== newMe) {
|
|
4164
|
+
this._data = freeze(newMe);
|
|
4165
|
+
this.invalidate();
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
};
|
|
4169
|
+
|
|
4158
4170
|
// src/refs/ValueRef.ts
|
|
4159
4171
|
var ValueRef = class extends ImmutableRef {
|
|
4160
4172
|
constructor(initialValue) {
|
|
@@ -4236,8 +4248,9 @@ function createRoom(options, config) {
|
|
|
4236
4248
|
messages: [],
|
|
4237
4249
|
storageOperations: []
|
|
4238
4250
|
},
|
|
4239
|
-
|
|
4240
|
-
|
|
4251
|
+
staticSessionInfo: new ValueRef(null),
|
|
4252
|
+
dynamicSessionInfo: new ValueRef(null),
|
|
4253
|
+
myPresence: new PatchableRef(initialPresence),
|
|
4241
4254
|
others: new OthersRef(),
|
|
4242
4255
|
initialStorage,
|
|
4243
4256
|
idFactory: null,
|
|
@@ -4261,11 +4274,9 @@ function createRoom(options, config) {
|
|
|
4261
4274
|
var _a2;
|
|
4262
4275
|
const token = (_a2 = managedSocket.token) == null ? void 0 : _a2.parsed;
|
|
4263
4276
|
if (token !== void 0 && token !== lastToken) {
|
|
4264
|
-
context.
|
|
4265
|
-
id: token.actor,
|
|
4277
|
+
context.staticSessionInfo.set({
|
|
4266
4278
|
userInfo: token.info,
|
|
4267
|
-
userId: token.id
|
|
4268
|
-
isReadOnly: isStorageReadOnly(token.scopes)
|
|
4279
|
+
userId: token.id
|
|
4269
4280
|
});
|
|
4270
4281
|
lastToken = token;
|
|
4271
4282
|
}
|
|
@@ -4303,20 +4314,15 @@ function createRoom(options, config) {
|
|
|
4303
4314
|
}
|
|
4304
4315
|
}
|
|
4305
4316
|
function onDidConnect() {
|
|
4306
|
-
const sessionInfo = context.sessionInfo.current;
|
|
4307
|
-
if (sessionInfo === null) {
|
|
4308
|
-
throw new Error("Unexpected missing session info");
|
|
4309
|
-
}
|
|
4310
4317
|
context.buffer.me = {
|
|
4311
4318
|
type: "full",
|
|
4312
4319
|
data: (
|
|
4313
4320
|
// Because context.me.current is a readonly object, we'll have to
|
|
4314
4321
|
// make a copy here. Otherwise, type errors happen later when
|
|
4315
4322
|
// "patching" my presence.
|
|
4316
|
-
__spreadValues({}, context.
|
|
4323
|
+
__spreadValues({}, context.myPresence.current)
|
|
4317
4324
|
)
|
|
4318
4325
|
};
|
|
4319
|
-
context.idFactory = makeIdFactory(sessionInfo.id);
|
|
4320
4326
|
if (_getStorage$ !== null) {
|
|
4321
4327
|
refreshStorage({ flush: false });
|
|
4322
4328
|
}
|
|
@@ -4381,8 +4387,17 @@ function createRoom(options, config) {
|
|
|
4381
4387
|
}
|
|
4382
4388
|
},
|
|
4383
4389
|
assertStorageIsWritable: () => {
|
|
4384
|
-
var _a2;
|
|
4385
|
-
|
|
4390
|
+
var _a2, _b2;
|
|
4391
|
+
const traits = (_b2 = (_a2 = context.dynamicSessionInfo.current) == null ? void 0 : _a2.traits) != null ? _b2 : (
|
|
4392
|
+
// XXX Double-check if this is the sane thing to do! Previously this is
|
|
4393
|
+
// how the context.sessionInfo?.isReadOnly check worked too. If the
|
|
4394
|
+
// isReadOnly property wasn't known yet, the client assumed write
|
|
4395
|
+
// access. Not sure if this will break anything if we flip it to
|
|
4396
|
+
// Traits.None.
|
|
4397
|
+
3 /* All */
|
|
4398
|
+
);
|
|
4399
|
+
const canWrite = (traits & 1 /* CanWriteDocument */) === 1 /* CanWriteDocument */;
|
|
4400
|
+
if (!canWrite) {
|
|
4386
4401
|
throw new Error(
|
|
4387
4402
|
"Cannot write to storage with a read only user, please ensure the user has write permissions"
|
|
4388
4403
|
);
|
|
@@ -4429,16 +4444,24 @@ function createRoom(options, config) {
|
|
|
4429
4444
|
managedSocket.send(message);
|
|
4430
4445
|
}
|
|
4431
4446
|
const self = new DerivedRef(
|
|
4432
|
-
context.
|
|
4433
|
-
context.
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4447
|
+
context.staticSessionInfo,
|
|
4448
|
+
context.dynamicSessionInfo,
|
|
4449
|
+
context.myPresence,
|
|
4450
|
+
(staticSession, dynamicSession, myPresence) => {
|
|
4451
|
+
if (staticSession === null || dynamicSession === null) {
|
|
4452
|
+
return null;
|
|
4453
|
+
} else {
|
|
4454
|
+
const canWrite = (dynamicSession.traits & 1 /* CanWriteDocument */) === 1 /* CanWriteDocument */;
|
|
4455
|
+
return {
|
|
4456
|
+
connectionId: dynamicSession.actor,
|
|
4457
|
+
id: staticSession.userId,
|
|
4458
|
+
info: staticSession.userInfo,
|
|
4459
|
+
presence: myPresence,
|
|
4460
|
+
canWrite,
|
|
4461
|
+
isReadOnly: !canWrite
|
|
4462
|
+
// Deprecated, kept for backward-compatibility
|
|
4463
|
+
};
|
|
4464
|
+
}
|
|
4442
4465
|
}
|
|
4443
4466
|
);
|
|
4444
4467
|
const selfAsTreeNode = new DerivedRef(
|
|
@@ -4499,7 +4522,7 @@ function createRoom(options, config) {
|
|
|
4499
4522
|
}
|
|
4500
4523
|
}
|
|
4501
4524
|
if (presence) {
|
|
4502
|
-
eventHub.me.notify(context.
|
|
4525
|
+
eventHub.me.notify(context.myPresence.current);
|
|
4503
4526
|
}
|
|
4504
4527
|
if (storageUpdates.size > 0) {
|
|
4505
4528
|
const updates = Array.from(storageUpdates.values());
|
|
@@ -4508,9 +4531,9 @@ function createRoom(options, config) {
|
|
|
4508
4531
|
});
|
|
4509
4532
|
}
|
|
4510
4533
|
function getConnectionId() {
|
|
4511
|
-
const info = context.
|
|
4534
|
+
const info = context.dynamicSessionInfo.current;
|
|
4512
4535
|
if (info) {
|
|
4513
|
-
return info.
|
|
4536
|
+
return info.actor;
|
|
4514
4537
|
}
|
|
4515
4538
|
throw new Error(
|
|
4516
4539
|
"Internal. Tried to get connection id but connection was never open"
|
|
@@ -4537,9 +4560,9 @@ function createRoom(options, config) {
|
|
|
4537
4560
|
data: {}
|
|
4538
4561
|
};
|
|
4539
4562
|
for (const key in op.data) {
|
|
4540
|
-
reverse.data[key] = context.
|
|
4563
|
+
reverse.data[key] = context.myPresence.current[key];
|
|
4541
4564
|
}
|
|
4542
|
-
context.
|
|
4565
|
+
context.myPresence.patch(op.data);
|
|
4543
4566
|
if (context.buffer.me === null) {
|
|
4544
4567
|
context.buffer.me = { type: "partial", data: op.data };
|
|
4545
4568
|
} else {
|
|
@@ -4647,9 +4670,9 @@ function createRoom(options, config) {
|
|
|
4647
4670
|
continue;
|
|
4648
4671
|
}
|
|
4649
4672
|
context.buffer.me.data[key] = overrideValue;
|
|
4650
|
-
oldValues[key] = context.
|
|
4673
|
+
oldValues[key] = context.myPresence.current[key];
|
|
4651
4674
|
}
|
|
4652
|
-
context.
|
|
4675
|
+
context.myPresence.patch(patch);
|
|
4653
4676
|
if (context.activeBatch) {
|
|
4654
4677
|
if (options2 == null ? void 0 : options2.addToHistory) {
|
|
4655
4678
|
context.activeBatch.reverseOps.unshift({
|
|
@@ -4671,9 +4694,6 @@ function createRoom(options, config) {
|
|
|
4671
4694
|
});
|
|
4672
4695
|
}
|
|
4673
4696
|
}
|
|
4674
|
-
function isStorageReadOnly(scopes) {
|
|
4675
|
-
return scopes.includes("room:read" /* Read */) && scopes.includes("room:presence:write" /* PresenceWrite */) && !scopes.includes("room:write" /* Write */);
|
|
4676
|
-
}
|
|
4677
4697
|
function onUpdatePresenceMessage(message) {
|
|
4678
4698
|
if (message.targetActor !== void 0) {
|
|
4679
4699
|
const oldUser = context.others.getUser(message.actor);
|
|
@@ -4705,6 +4725,11 @@ function createRoom(options, config) {
|
|
|
4705
4725
|
return null;
|
|
4706
4726
|
}
|
|
4707
4727
|
function onRoomStateMessage(message) {
|
|
4728
|
+
context.dynamicSessionInfo.set({
|
|
4729
|
+
actor: message.actor,
|
|
4730
|
+
traits: message.traits
|
|
4731
|
+
});
|
|
4732
|
+
context.idFactory = makeIdFactory(message.actor);
|
|
4708
4733
|
for (const connectionId in context.others._connections) {
|
|
4709
4734
|
const user = message.users[connectionId];
|
|
4710
4735
|
if (user === void 0) {
|
|
@@ -4716,9 +4741,9 @@ function createRoom(options, config) {
|
|
|
4716
4741
|
const connectionId = Number(key);
|
|
4717
4742
|
context.others.setConnection(
|
|
4718
4743
|
connectionId,
|
|
4744
|
+
user.traits,
|
|
4719
4745
|
user.id,
|
|
4720
|
-
user.info
|
|
4721
|
-
isStorageReadOnly(user.scopes)
|
|
4746
|
+
user.info
|
|
4722
4747
|
);
|
|
4723
4748
|
}
|
|
4724
4749
|
return { type: "reset" };
|
|
@@ -4737,13 +4762,13 @@ function createRoom(options, config) {
|
|
|
4737
4762
|
function onUserJoinedMessage(message) {
|
|
4738
4763
|
context.others.setConnection(
|
|
4739
4764
|
message.actor,
|
|
4765
|
+
message.traits,
|
|
4740
4766
|
message.id,
|
|
4741
|
-
message.info
|
|
4742
|
-
isStorageReadOnly(message.scopes)
|
|
4767
|
+
message.info
|
|
4743
4768
|
);
|
|
4744
4769
|
context.buffer.messages.push({
|
|
4745
4770
|
type: 100 /* UPDATE_PRESENCE */,
|
|
4746
|
-
data: context.
|
|
4771
|
+
data: context.myPresence.current,
|
|
4747
4772
|
targetActor: message.actor
|
|
4748
4773
|
});
|
|
4749
4774
|
flushNowOrSoon();
|
|
@@ -5196,10 +5221,10 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5196
5221
|
// Core
|
|
5197
5222
|
getStatus: () => managedSocket.getStatus(),
|
|
5198
5223
|
getConnectionState: () => managedSocket.getLegacyStatus(),
|
|
5199
|
-
isSelfAware: () => context.
|
|
5224
|
+
isSelfAware: () => context.staticSessionInfo.current !== null,
|
|
5200
5225
|
getSelf: () => self.current,
|
|
5201
5226
|
// Presence
|
|
5202
|
-
getPresence: () => context.
|
|
5227
|
+
getPresence: () => context.myPresence.current,
|
|
5203
5228
|
getOthers: () => context.others.current
|
|
5204
5229
|
};
|
|
5205
5230
|
}
|
|
@@ -5304,7 +5329,7 @@ function makeCreateSocketDelegateForRoom(liveblocksServer, WebSocketPolyfill) {
|
|
|
5304
5329
|
// @ts-ignore (__PACKAGE_VERSION__ will be injected by the build script)
|
|
5305
5330
|
true ? (
|
|
5306
5331
|
/* istanbul ignore next */
|
|
5307
|
-
"1.2.0-
|
|
5332
|
+
"1.2.0-internal3"
|
|
5308
5333
|
) : "dev"}`
|
|
5309
5334
|
);
|
|
5310
5335
|
};
|