microboard-temp 0.13.59 → 0.13.61
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/cjs/browser.js +210 -144
- package/dist/cjs/index.js +210 -144
- package/dist/cjs/node.js +210 -144
- package/dist/esm/browser.js +210 -144
- package/dist/esm/index.js +210 -144
- package/dist/esm/node.js +210 -144
- package/dist/types/Events/Events.d.ts +9 -4
- package/dist/types/Events/Log/EventsLog.d.ts +2 -2
- package/dist/types/Events/Log/getRedoRecordFromList.d.ts +1 -1
- package/dist/types/Events/Log/getUndoRecordFromList.d.ts +1 -1
- package/dist/types/Events/Log/shouldSkipEvent.d.ts +1 -1
- package/dist/types/Events/MessageRouter/boardMessageInterface.d.ts +7 -3
- package/dist/types/Events/identity.d.ts +9 -0
- package/dist/types/Presence/Presence.d.ts +7 -4
- package/dist/types/Settings.d.ts +4 -0
- package/package.json +1 -1
package/dist/esm/browser.js
CHANGED
|
@@ -5831,17 +5831,50 @@ function getRecordByIdFromList(id, list) {
|
|
|
5831
5831
|
return;
|
|
5832
5832
|
}
|
|
5833
5833
|
|
|
5834
|
+
// src/Events/identity.ts
|
|
5835
|
+
function getBoardEventSessionId(body) {
|
|
5836
|
+
if (body.sessionId) {
|
|
5837
|
+
return body.sessionId;
|
|
5838
|
+
}
|
|
5839
|
+
if (body.userId === undefined || body.userId === null) {
|
|
5840
|
+
return;
|
|
5841
|
+
}
|
|
5842
|
+
return String(body.userId);
|
|
5843
|
+
}
|
|
5844
|
+
function getConnectionSessionId(connection) {
|
|
5845
|
+
return connection?.getSessionId?.() || connection?.sessionId || String(connection?.connectionId || 0);
|
|
5846
|
+
}
|
|
5847
|
+
function getConnectionSessionIds(connection) {
|
|
5848
|
+
const ids = new Set;
|
|
5849
|
+
const primary = connection?.getSessionId?.() || connection?.sessionId;
|
|
5850
|
+
if (primary) {
|
|
5851
|
+
ids.add(primary);
|
|
5852
|
+
}
|
|
5853
|
+
if (connection?.connectionId !== undefined) {
|
|
5854
|
+
ids.add(String(connection.connectionId));
|
|
5855
|
+
}
|
|
5856
|
+
if (ids.size === 0) {
|
|
5857
|
+
ids.add("0");
|
|
5858
|
+
}
|
|
5859
|
+
return Array.from(ids);
|
|
5860
|
+
}
|
|
5861
|
+
function getConnectionAuthorUserId(connection) {
|
|
5862
|
+
return connection?.getAuthorUserId?.() || connection?.authorUserId || connection?.getCurrentUser?.();
|
|
5863
|
+
}
|
|
5864
|
+
|
|
5834
5865
|
// src/Events/Log/shouldSkipEvent.ts
|
|
5835
|
-
function shouldSkipEvent(record,
|
|
5866
|
+
function shouldSkipEvent(record, sessionIds) {
|
|
5836
5867
|
const { operation } = record.event.body;
|
|
5837
|
-
|
|
5868
|
+
const eventSessionId = getBoardEventSessionId(record.event.body);
|
|
5869
|
+
return eventSessionId === undefined || !sessionIds.includes(eventSessionId) || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
|
|
5838
5870
|
}
|
|
5871
|
+
var init_shouldSkipEvent = () => {};
|
|
5839
5872
|
|
|
5840
5873
|
// src/Events/Log/getRedoRecordFromList.ts
|
|
5841
|
-
function getRedoRecordFromList(
|
|
5874
|
+
function getRedoRecordFromList(sessionIds, list) {
|
|
5842
5875
|
let counter = 0;
|
|
5843
5876
|
for (const record of list.backwardIterable()) {
|
|
5844
|
-
if (shouldSkipEvent(record,
|
|
5877
|
+
if (shouldSkipEvent(record, sessionIds)) {
|
|
5845
5878
|
continue;
|
|
5846
5879
|
}
|
|
5847
5880
|
if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
|
|
@@ -5860,17 +5893,19 @@ function getRedoRecordFromList(userId, list) {
|
|
|
5860
5893
|
}
|
|
5861
5894
|
return null;
|
|
5862
5895
|
}
|
|
5863
|
-
var init_getRedoRecordFromList = () => {
|
|
5896
|
+
var init_getRedoRecordFromList = __esm(() => {
|
|
5897
|
+
init_shouldSkipEvent();
|
|
5898
|
+
});
|
|
5864
5899
|
|
|
5865
5900
|
// src/Events/Log/getUndoRecordFromList.ts
|
|
5866
|
-
function getUndoRecordFromList(
|
|
5901
|
+
function getUndoRecordFromList(sessionIds, list) {
|
|
5867
5902
|
let counter = 0;
|
|
5868
5903
|
const isAllEventsConfirmed = list.isAllEventsConfirmed();
|
|
5869
5904
|
if (!isAllEventsConfirmed) {
|
|
5870
5905
|
return null;
|
|
5871
5906
|
}
|
|
5872
5907
|
for (const record of list.getConfirmedRecords().slice().reverse()) {
|
|
5873
|
-
if (shouldSkipEvent(record,
|
|
5908
|
+
if (shouldSkipEvent(record, sessionIds)) {
|
|
5874
5909
|
continue;
|
|
5875
5910
|
}
|
|
5876
5911
|
if (record.event.body.operation.method === "undo") {
|
|
@@ -5883,7 +5918,9 @@ function getUndoRecordFromList(userId, list) {
|
|
|
5883
5918
|
}
|
|
5884
5919
|
return null;
|
|
5885
5920
|
}
|
|
5886
|
-
var init_getUndoRecordFromList = () => {
|
|
5921
|
+
var init_getUndoRecordFromList = __esm(() => {
|
|
5922
|
+
init_shouldSkipEvent();
|
|
5923
|
+
});
|
|
5887
5924
|
|
|
5888
5925
|
// src/Events/Log/getUnpublishedEventFromList.ts
|
|
5889
5926
|
function getUnpublishedEventFromList(list) {
|
|
@@ -5962,11 +5999,12 @@ function expandEvents(events) {
|
|
|
5962
5999
|
order: event.order,
|
|
5963
6000
|
body: {
|
|
5964
6001
|
eventId: operation.actualId || bodyWithoutOps.eventId,
|
|
6002
|
+
authorUserId: bodyWithoutOps.authorUserId,
|
|
6003
|
+
sessionId: bodyWithoutOps.sessionId,
|
|
5965
6004
|
userId: bodyWithoutOps.userId,
|
|
5966
6005
|
boardId: bodyWithoutOps.boardId,
|
|
5967
6006
|
operation
|
|
5968
6007
|
},
|
|
5969
|
-
userId: bodyWithoutOps.userId,
|
|
5970
6008
|
lastKnownOrder
|
|
5971
6009
|
}));
|
|
5972
6010
|
} else {
|
|
@@ -6085,7 +6123,6 @@ function deserializeAndApplyToList(events, list, board) {
|
|
|
6085
6123
|
const singleEvent = {
|
|
6086
6124
|
order: event.order,
|
|
6087
6125
|
lastKnownOrder,
|
|
6088
|
-
userId: bodyWithoutOps.userId,
|
|
6089
6126
|
body: {
|
|
6090
6127
|
...bodyWithoutOps,
|
|
6091
6128
|
operation: op
|
|
@@ -6172,11 +6209,11 @@ class EventsLog {
|
|
|
6172
6209
|
getUnorderedRecords() {
|
|
6173
6210
|
return this.list.getRecordsToSend().concat(this.list.getNewRecords());
|
|
6174
6211
|
}
|
|
6175
|
-
getUndoRecord(
|
|
6176
|
-
return getUndoRecordFromList(
|
|
6212
|
+
getUndoRecord(sessionIds) {
|
|
6213
|
+
return getUndoRecordFromList(sessionIds, this.list);
|
|
6177
6214
|
}
|
|
6178
|
-
getRedoRecord(
|
|
6179
|
-
return getRedoRecordFromList(
|
|
6215
|
+
getRedoRecord(sessionIds) {
|
|
6216
|
+
return getRedoRecordFromList(sessionIds, this.list);
|
|
6180
6217
|
}
|
|
6181
6218
|
getRecordById(id) {
|
|
6182
6219
|
return getRecordByIdFromList(id, this.list);
|
|
@@ -14190,10 +14227,13 @@ class Events {
|
|
|
14190
14227
|
console.error("[DEBUG] transformMany emitted from Events.emit!", JSON.stringify(operation));
|
|
14191
14228
|
console.trace("[DEBUG] transformMany stack trace");
|
|
14192
14229
|
}
|
|
14193
|
-
const
|
|
14230
|
+
const sessionId = this.getSessionId();
|
|
14231
|
+
const authorUserId = this.getAuthorUserId();
|
|
14194
14232
|
const body = {
|
|
14195
14233
|
eventId: this.getNextEventId(),
|
|
14196
|
-
userId,
|
|
14234
|
+
userId: sessionId,
|
|
14235
|
+
authorUserId,
|
|
14236
|
+
sessionId,
|
|
14197
14237
|
boardId: this.board.getBoardId(),
|
|
14198
14238
|
operation
|
|
14199
14239
|
};
|
|
@@ -14203,7 +14243,7 @@ class Events {
|
|
|
14203
14243
|
command: command || Events.createCommand(this.board, operation)
|
|
14204
14244
|
};
|
|
14205
14245
|
this.log.insertNewLocalEventRecordAfterEmit(record);
|
|
14206
|
-
this.setLatestUserEvent(operation,
|
|
14246
|
+
this.setLatestUserEvent(operation, sessionId);
|
|
14207
14247
|
this.subject.publish(event);
|
|
14208
14248
|
if (this.board.getBoardId().includes("local")) {
|
|
14209
14249
|
if (this.log.saveFileTimeout) {
|
|
@@ -14224,13 +14264,13 @@ class Events {
|
|
|
14224
14264
|
this.emit(operation, cmd);
|
|
14225
14265
|
}
|
|
14226
14266
|
undo() {
|
|
14227
|
-
const
|
|
14228
|
-
const record = this.log.getUndoRecord(
|
|
14267
|
+
const currentSessionIds = this.getSessionIds();
|
|
14268
|
+
const record = this.log.getUndoRecord(currentSessionIds);
|
|
14229
14269
|
if (!record) {
|
|
14230
14270
|
return;
|
|
14231
14271
|
}
|
|
14232
|
-
const { operation,
|
|
14233
|
-
const canUndo = this.canUndoEvent(operation,
|
|
14272
|
+
const { operation, eventId } = record.event.body;
|
|
14273
|
+
const canUndo = this.canUndoEvent(operation, getBoardEventSessionId(record.event.body));
|
|
14234
14274
|
if (!canUndo) {
|
|
14235
14275
|
return;
|
|
14236
14276
|
}
|
|
@@ -14241,8 +14281,8 @@ class Events {
|
|
|
14241
14281
|
});
|
|
14242
14282
|
}
|
|
14243
14283
|
redo() {
|
|
14244
|
-
const
|
|
14245
|
-
const record = this.log.getRedoRecord(
|
|
14284
|
+
const sessionIds = this.getSessionIds();
|
|
14285
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14246
14286
|
if (!record) {
|
|
14247
14287
|
return;
|
|
14248
14288
|
}
|
|
@@ -14253,22 +14293,22 @@ class Events {
|
|
|
14253
14293
|
});
|
|
14254
14294
|
}
|
|
14255
14295
|
canUndo() {
|
|
14256
|
-
const
|
|
14257
|
-
const record = this.log.getUndoRecord(
|
|
14296
|
+
const sessionIds = this.getSessionIds();
|
|
14297
|
+
const record = this.log.getUndoRecord(sessionIds);
|
|
14258
14298
|
if (!record) {
|
|
14259
14299
|
return false;
|
|
14260
14300
|
}
|
|
14261
|
-
return this.canUndoEvent(record.event.body.operation, record.event.body
|
|
14301
|
+
return this.canUndoEvent(record.event.body.operation, getBoardEventSessionId(record.event.body));
|
|
14262
14302
|
}
|
|
14263
14303
|
canRedo() {
|
|
14264
|
-
const
|
|
14265
|
-
const record = this.log.getRedoRecord(
|
|
14304
|
+
const sessionIds = this.getSessionIds();
|
|
14305
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14266
14306
|
return record !== null;
|
|
14267
14307
|
}
|
|
14268
14308
|
sendPresenceEvent(event) {
|
|
14269
14309
|
conf.connection.publishPresenceEvent(this.board.getBoardId(), event);
|
|
14270
14310
|
}
|
|
14271
|
-
canUndoEvent(op,
|
|
14311
|
+
canUndoEvent(op, bySessionId) {
|
|
14272
14312
|
if (op.method === "undo") {
|
|
14273
14313
|
return false;
|
|
14274
14314
|
}
|
|
@@ -14278,24 +14318,30 @@ class Events {
|
|
|
14278
14318
|
}
|
|
14279
14319
|
const key = this.getOpKey(op);
|
|
14280
14320
|
const latest = this.latestEvent[key];
|
|
14281
|
-
return
|
|
14321
|
+
return bySessionId === undefined || bySessionId === latest;
|
|
14282
14322
|
}
|
|
14283
|
-
setLatestUserEvent(op,
|
|
14323
|
+
setLatestUserEvent(op, sessionId) {
|
|
14284
14324
|
if (op.class !== "Events" && op.method !== "paste" && op.method !== "duplicate") {
|
|
14285
14325
|
const key = this.getOpKey(op);
|
|
14286
|
-
this.latestEvent[key] =
|
|
14326
|
+
this.latestEvent[key] = sessionId;
|
|
14287
14327
|
}
|
|
14288
14328
|
}
|
|
14289
14329
|
getOpKey(op) {
|
|
14290
14330
|
return op.method;
|
|
14291
14331
|
}
|
|
14292
|
-
|
|
14293
|
-
return this.connection
|
|
14332
|
+
getSessionId() {
|
|
14333
|
+
return getConnectionSessionId(this.connection);
|
|
14334
|
+
}
|
|
14335
|
+
getSessionIds() {
|
|
14336
|
+
return getConnectionSessionIds(this.connection);
|
|
14337
|
+
}
|
|
14338
|
+
getAuthorUserId() {
|
|
14339
|
+
return getConnectionAuthorUserId(this.connection);
|
|
14294
14340
|
}
|
|
14295
14341
|
getNextEventId() {
|
|
14296
14342
|
const id = ++this.eventCounter;
|
|
14297
|
-
const
|
|
14298
|
-
return
|
|
14343
|
+
const sessionId = this.getSessionId();
|
|
14344
|
+
return sessionId + ":" + id;
|
|
14299
14345
|
}
|
|
14300
14346
|
}
|
|
14301
14347
|
function createEvents(board, connection, lastIndex) {
|
|
@@ -51309,6 +51355,9 @@ function validateItemsMap(parsedObject) {
|
|
|
51309
51355
|
}
|
|
51310
51356
|
return true;
|
|
51311
51357
|
}
|
|
51358
|
+
function isColorValue(v) {
|
|
51359
|
+
return typeof v === "string" || typeof v === "object" && v !== null;
|
|
51360
|
+
}
|
|
51312
51361
|
function validateItemData(itemData) {
|
|
51313
51362
|
if (typeof itemData !== "object" || itemData === null || !("itemType" in itemData) || typeof itemData.itemType !== "string") {
|
|
51314
51363
|
return false;
|
|
@@ -51321,7 +51370,7 @@ function validateFrameData(data) {
|
|
|
51321
51370
|
return false;
|
|
51322
51371
|
}
|
|
51323
51372
|
const frameData = data;
|
|
51324
|
-
const isValid = frameData.hasOwnProperty("shapeType") && frameData.hasOwnProperty("backgroundColor") && frameData.hasOwnProperty("backgroundOpacity") && frameData.hasOwnProperty("borderColor") && frameData.hasOwnProperty("borderOpacity") && frameData.hasOwnProperty("borderStyle") && frameData.hasOwnProperty("borderWidth") && frameData.hasOwnProperty("transformation") && frameData.hasOwnProperty("text") && frameData.hasOwnProperty("children") && typeof frameData.shapeType === "string" &&
|
|
51373
|
+
const isValid = frameData.hasOwnProperty("shapeType") && frameData.hasOwnProperty("backgroundColor") && frameData.hasOwnProperty("backgroundOpacity") && frameData.hasOwnProperty("borderColor") && frameData.hasOwnProperty("borderOpacity") && frameData.hasOwnProperty("borderStyle") && frameData.hasOwnProperty("borderWidth") && frameData.hasOwnProperty("transformation") && frameData.hasOwnProperty("text") && frameData.hasOwnProperty("children") && typeof frameData.shapeType === "string" && isColorValue(frameData.backgroundColor) && typeof frameData.backgroundOpacity === "number" && isColorValue(frameData.borderColor) && typeof frameData.borderOpacity === "number" && typeof frameData.borderStyle === "string" && typeof frameData.borderWidth === "number" && Array.isArray(frameData.children) && validateTransformationData(frameData.transformation) && validateRichTextData(frameData.text);
|
|
51325
51374
|
return isValid;
|
|
51326
51375
|
}
|
|
51327
51376
|
function validateShapeData(shapeData) {
|
|
@@ -51329,7 +51378,7 @@ function validateShapeData(shapeData) {
|
|
|
51329
51378
|
return false;
|
|
51330
51379
|
}
|
|
51331
51380
|
const data = shapeData;
|
|
51332
|
-
const isValid = data.hasOwnProperty("shapeType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("backgroundOpacity") && data.hasOwnProperty("borderColor") && data.hasOwnProperty("borderOpacity") && data.hasOwnProperty("borderStyle") && data.hasOwnProperty("borderWidth") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") && typeof data.shapeType === "string" &&
|
|
51381
|
+
const isValid = data.hasOwnProperty("shapeType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("backgroundOpacity") && data.hasOwnProperty("borderColor") && data.hasOwnProperty("borderOpacity") && data.hasOwnProperty("borderStyle") && data.hasOwnProperty("borderWidth") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") && typeof data.shapeType === "string" && isColorValue(data.backgroundColor) && typeof data.backgroundOpacity === "number" && isColorValue(data.borderColor) && typeof data.borderOpacity === "number" && typeof data.borderStyle === "string" && typeof data.borderWidth === "number" && validateTransformationData(data.transformation) && validateRichTextData(data.text);
|
|
51333
51382
|
return isValid;
|
|
51334
51383
|
}
|
|
51335
51384
|
function validateStickerData(shapeData) {
|
|
@@ -51337,7 +51386,7 @@ function validateStickerData(shapeData) {
|
|
|
51337
51386
|
return false;
|
|
51338
51387
|
}
|
|
51339
51388
|
const data = shapeData;
|
|
51340
|
-
const isValid = data.hasOwnProperty("itemType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") &&
|
|
51389
|
+
const isValid = data.hasOwnProperty("itemType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") && isColorValue(data.backgroundColor) && validateTransformationData(data.transformation) && validateRichTextData(data.text);
|
|
51341
51390
|
return isValid;
|
|
51342
51391
|
}
|
|
51343
51392
|
function validateTransformationData(transformationData) {
|
|
@@ -51361,7 +51410,7 @@ function validateConnectorData(connectorData) {
|
|
|
51361
51410
|
return false;
|
|
51362
51411
|
}
|
|
51363
51412
|
const data = connectorData;
|
|
51364
|
-
const isValid = data.hasOwnProperty("startPoint") && data.hasOwnProperty("endPoint") && data.hasOwnProperty("startPointerStyle") && data.hasOwnProperty("endPointerStyle") && data.hasOwnProperty("lineStyle") && data.hasOwnProperty("lineColor") && data.hasOwnProperty("lineWidth") && data.hasOwnProperty("transformation") && typeof data.startPoint === "object" && typeof data.endPoint === "object" && typeof data.startPointerStyle === "string" && typeof data.endPointerStyle === "string" && typeof data.lineStyle === "string" &&
|
|
51413
|
+
const isValid = data.hasOwnProperty("startPoint") && data.hasOwnProperty("endPoint") && data.hasOwnProperty("startPointerStyle") && data.hasOwnProperty("endPointerStyle") && data.hasOwnProperty("lineStyle") && data.hasOwnProperty("lineColor") && data.hasOwnProperty("lineWidth") && data.hasOwnProperty("transformation") && typeof data.startPoint === "object" && typeof data.endPoint === "object" && typeof data.startPointerStyle === "string" && typeof data.endPointerStyle === "string" && typeof data.lineStyle === "string" && isColorValue(data.lineColor) && typeof data.lineWidth === "number" && validateTransformationData(data.transformation);
|
|
51365
51414
|
return isValid;
|
|
51366
51415
|
}
|
|
51367
51416
|
function validateChildren(children) {
|
|
@@ -55528,9 +55577,9 @@ function handleBoardEventMessage(message, board) {
|
|
|
55528
55577
|
if (event.order <= log.getLastIndex()) {
|
|
55529
55578
|
return;
|
|
55530
55579
|
}
|
|
55531
|
-
const
|
|
55532
|
-
const currentConnectionId = board.events.connection
|
|
55533
|
-
const isEventFromCurrentUser =
|
|
55580
|
+
const eventSessionId = getBoardEventSessionId(event.body);
|
|
55581
|
+
const currentConnectionId = getConnectionSessionId(board.events.connection);
|
|
55582
|
+
const isEventFromCurrentUser = eventSessionId !== undefined && eventSessionId === currentConnectionId;
|
|
55534
55583
|
if (isEventFromCurrentUser) {
|
|
55535
55584
|
return;
|
|
55536
55585
|
}
|
|
@@ -55544,6 +55593,7 @@ function handleBoardEventMessage(message, board) {
|
|
|
55544
55593
|
board.events.subject.publish(last);
|
|
55545
55594
|
}
|
|
55546
55595
|
}
|
|
55596
|
+
var init_handleBoardEventMessage = () => {};
|
|
55547
55597
|
|
|
55548
55598
|
// src/Events/MessageRouter/handleBoardSubscriptionCompletedMsg.ts
|
|
55549
55599
|
function handleBoardSubscriptionCompletedMsg(msg, board) {
|
|
@@ -55652,8 +55702,7 @@ function sendBoardEvent(board, batch, sequenceNumber) {
|
|
|
55652
55702
|
type: "BoardEvent",
|
|
55653
55703
|
boardId: board.getBoardId(),
|
|
55654
55704
|
event: toSend,
|
|
55655
|
-
sequenceNumber
|
|
55656
|
-
userId: conf.connection.getCurrentUser()
|
|
55705
|
+
sequenceNumber
|
|
55657
55706
|
});
|
|
55658
55707
|
const date = Date.now();
|
|
55659
55708
|
log.pendingEvent = {
|
|
@@ -55789,6 +55838,7 @@ function handleUserJoinMessage(message, board) {
|
|
|
55789
55838
|
var messageRouter;
|
|
55790
55839
|
var init_messageRouter = __esm(() => {
|
|
55791
55840
|
init_handleAiChatMassage();
|
|
55841
|
+
init_handleBoardEventMessage();
|
|
55792
55842
|
init_handleBoardSubscriptionCompletedMsg();
|
|
55793
55843
|
init_handleConfirmation();
|
|
55794
55844
|
init_handleCreateSnapshotRequestMessage();
|
|
@@ -57063,6 +57113,15 @@ var PRESENCE_CLEANUP_USER_TIMER = 180000;
|
|
|
57063
57113
|
var PRESENCE_CLEANUP_IDLE_TIMER = 60000;
|
|
57064
57114
|
var CURSORS_IDLE_CLEANUP_DELAY = 1e4;
|
|
57065
57115
|
var PING_CLEANUP = 15000;
|
|
57116
|
+
function getPresenceSessionId(message) {
|
|
57117
|
+
if (message.sessionId) {
|
|
57118
|
+
return message.sessionId;
|
|
57119
|
+
}
|
|
57120
|
+
if (message.userId === undefined || message.userId === null) {
|
|
57121
|
+
return;
|
|
57122
|
+
}
|
|
57123
|
+
return String(message.userId);
|
|
57124
|
+
}
|
|
57066
57125
|
var cleanupInterval = null;
|
|
57067
57126
|
|
|
57068
57127
|
class Presence {
|
|
@@ -57072,7 +57131,6 @@ class Presence {
|
|
|
57072
57131
|
trackedUser = null;
|
|
57073
57132
|
cursorsEnabled = true;
|
|
57074
57133
|
drawingContext = null;
|
|
57075
|
-
currentUserId = null;
|
|
57076
57134
|
users = new Map;
|
|
57077
57135
|
followers = [];
|
|
57078
57136
|
svgImageCache = {};
|
|
@@ -57098,7 +57156,7 @@ class Presence {
|
|
|
57098
57156
|
throttleSelectionEvent(this.board.selection);
|
|
57099
57157
|
});
|
|
57100
57158
|
if (typeof window !== "undefined") {
|
|
57101
|
-
window.addEventListener("storage", this.
|
|
57159
|
+
window.addEventListener("storage", this.onStorageChange);
|
|
57102
57160
|
}
|
|
57103
57161
|
}
|
|
57104
57162
|
clear() {
|
|
@@ -57137,19 +57195,30 @@ class Presence {
|
|
|
57137
57195
|
}
|
|
57138
57196
|
return !this.board.camera.matrix.compare(new Matrix(trackedUser.camera.translateX, trackedUser.camera.translateY, trackedUser.camera.scaleX, trackedUser.camera.scaleY, trackedUser.camera.shearX, trackedUser.camera.shearY));
|
|
57139
57197
|
}
|
|
57140
|
-
|
|
57141
|
-
|
|
57198
|
+
onStorageChange = (_event) => {};
|
|
57199
|
+
getCurrentSessionId() {
|
|
57200
|
+
return this.events?.connection?.getSessionId?.() || this.events?.connection?.sessionId || null;
|
|
57142
57201
|
}
|
|
57143
|
-
|
|
57144
|
-
if (
|
|
57145
|
-
|
|
57146
|
-
this.setCurrentUser(event.newValue);
|
|
57147
|
-
}
|
|
57202
|
+
getLegacyCurrentUserId() {
|
|
57203
|
+
if (typeof localStorage === "undefined") {
|
|
57204
|
+
return null;
|
|
57148
57205
|
}
|
|
57206
|
+
return localStorage.getItem("currentUser");
|
|
57207
|
+
}
|
|
57208
|
+
isCurrentSessionTarget(value) {
|
|
57209
|
+
if (value === undefined || value === null) {
|
|
57210
|
+
return false;
|
|
57211
|
+
}
|
|
57212
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57213
|
+
if (currentSessionId && String(value) === currentSessionId) {
|
|
57214
|
+
return true;
|
|
57215
|
+
}
|
|
57216
|
+
const currentUser = this.getLegacyCurrentUserId();
|
|
57217
|
+
return currentUser !== null && String(value) === currentUser;
|
|
57149
57218
|
}
|
|
57150
57219
|
cleanup() {
|
|
57151
57220
|
if (typeof window !== "undefined") {
|
|
57152
|
-
window.removeEventListener("storage", this.
|
|
57221
|
+
window.removeEventListener("storage", this.onStorageChange);
|
|
57153
57222
|
}
|
|
57154
57223
|
this.drawingContext = null;
|
|
57155
57224
|
this.clear();
|
|
@@ -57189,24 +57258,25 @@ class Presence {
|
|
|
57189
57258
|
}
|
|
57190
57259
|
join(msg) {
|
|
57191
57260
|
Object.entries(msg.snapshots).map(([userId, snapshot]) => {
|
|
57192
|
-
|
|
57261
|
+
const sessionId = snapshot.sessionId || userId;
|
|
57262
|
+
this.users.set(sessionId, {
|
|
57263
|
+
...snapshot,
|
|
57264
|
+
userId: snapshot.userId || sessionId,
|
|
57265
|
+
sessionId,
|
|
57266
|
+
authorUserId: snapshot.authorUserId || null
|
|
57267
|
+
});
|
|
57193
57268
|
});
|
|
57194
57269
|
this.subject.publish(this);
|
|
57195
57270
|
}
|
|
57196
57271
|
getUsers(boardId, excludeSelf = false) {
|
|
57197
57272
|
let filteredUsers = Array.from(this.users.values()).filter((user) => user.boardId === boardId && (user.lastPing > Date.now() - PING_CLEANUP || user.lastActivity > Date.now() - PING_CLEANUP));
|
|
57198
57273
|
if (excludeSelf) {
|
|
57199
|
-
const
|
|
57200
|
-
if (
|
|
57201
|
-
filteredUsers = filteredUsers.filter((user) => user.
|
|
57274
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57275
|
+
if (currentSessionId) {
|
|
57276
|
+
filteredUsers = filteredUsers.filter((user) => user.sessionId !== currentSessionId);
|
|
57202
57277
|
}
|
|
57203
57278
|
}
|
|
57204
|
-
|
|
57205
|
-
filteredUsers.forEach((user) => {
|
|
57206
|
-
const key = user.hardId === null ? Symbol() : user.hardId;
|
|
57207
|
-
uniqueUsers.set(key, user);
|
|
57208
|
-
});
|
|
57209
|
-
return Array.from(uniqueUsers.values());
|
|
57279
|
+
return filteredUsers;
|
|
57210
57280
|
}
|
|
57211
57281
|
getColors() {
|
|
57212
57282
|
return Array.from(this.users.values()).map((user) => user.color);
|
|
@@ -57215,8 +57285,12 @@ class Presence {
|
|
|
57215
57285
|
if (!this.drawingContext) {
|
|
57216
57286
|
return;
|
|
57217
57287
|
}
|
|
57218
|
-
const
|
|
57219
|
-
|
|
57288
|
+
const sessionId = getPresenceSessionId(event);
|
|
57289
|
+
if (!sessionId) {
|
|
57290
|
+
return;
|
|
57291
|
+
}
|
|
57292
|
+
const { event: eventData } = event;
|
|
57293
|
+
let user = this.users.get(sessionId);
|
|
57220
57294
|
if (!user) {
|
|
57221
57295
|
let color2 = null;
|
|
57222
57296
|
const storageColor = localStorage.getItem(`userColor`);
|
|
@@ -57227,8 +57301,10 @@ class Presence {
|
|
|
57227
57301
|
} else {
|
|
57228
57302
|
color2 = this.generateUserColor();
|
|
57229
57303
|
}
|
|
57230
|
-
this.users.set(
|
|
57231
|
-
userId:
|
|
57304
|
+
this.users.set(sessionId, {
|
|
57305
|
+
userId: sessionId,
|
|
57306
|
+
sessionId,
|
|
57307
|
+
authorUserId: event.authorUserId || null,
|
|
57232
57308
|
softId: event.softId,
|
|
57233
57309
|
hardId: event.hardId,
|
|
57234
57310
|
color: color2,
|
|
@@ -57243,7 +57319,7 @@ class Presence {
|
|
|
57243
57319
|
boardId: this.board.getBoardId(),
|
|
57244
57320
|
lastPointerActivity: eventData.timestamp
|
|
57245
57321
|
});
|
|
57246
|
-
user = this.users.get(
|
|
57322
|
+
user = this.users.get(sessionId);
|
|
57247
57323
|
}
|
|
57248
57324
|
switch (eventData.method) {
|
|
57249
57325
|
case "PointerMove":
|
|
@@ -57286,6 +57362,9 @@ class Presence {
|
|
|
57286
57362
|
if (msg.color) {
|
|
57287
57363
|
userCopy.color = msg.color;
|
|
57288
57364
|
}
|
|
57365
|
+
if (msg.authorUserId) {
|
|
57366
|
+
userCopy.authorUserId = msg.authorUserId;
|
|
57367
|
+
}
|
|
57289
57368
|
userCopy.nickname = msg.nickname;
|
|
57290
57369
|
userCopy.boardId = msg.boardId;
|
|
57291
57370
|
if (shouldUpdateActivity) {
|
|
@@ -57293,107 +57372,113 @@ class Presence {
|
|
|
57293
57372
|
}
|
|
57294
57373
|
}
|
|
57295
57374
|
processFollowEvent(msg) {
|
|
57296
|
-
|
|
57297
|
-
|
|
57298
|
-
|
|
57299
|
-
|
|
57300
|
-
|
|
57301
|
-
this.followers.push(
|
|
57375
|
+
if (this.isCurrentSessionTarget(msg.event.user)) {
|
|
57376
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57377
|
+
if (!sessionId) {
|
|
57378
|
+
return;
|
|
57379
|
+
}
|
|
57380
|
+
this.followers.push(sessionId);
|
|
57302
57381
|
this.followers = Array.from(new Set(this.followers));
|
|
57303
57382
|
}
|
|
57304
57383
|
}
|
|
57305
57384
|
processBringToMe(msg) {
|
|
57306
|
-
|
|
57307
|
-
|
|
57308
|
-
|
|
57309
|
-
|
|
57310
|
-
|
|
57311
|
-
const bringerId = msg.userId.toString();
|
|
57385
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57386
|
+
const bringerId = getPresenceSessionId(msg);
|
|
57387
|
+
if (!bringerId) {
|
|
57388
|
+
return;
|
|
57389
|
+
}
|
|
57312
57390
|
const userToTrack = this.users.get(bringerId);
|
|
57313
57391
|
if (userToTrack) {
|
|
57314
57392
|
this.trackedUser = userToTrack;
|
|
57315
|
-
this.enableTracking(userToTrack.userId);
|
|
57393
|
+
this.enableTracking(userToTrack.sessionId || userToTrack.userId);
|
|
57316
57394
|
}
|
|
57317
57395
|
}
|
|
57318
57396
|
}
|
|
57319
57397
|
processStopFollowing(msg) {
|
|
57320
|
-
const
|
|
57321
|
-
if (!
|
|
57398
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57399
|
+
if (!sessionId) {
|
|
57322
57400
|
return;
|
|
57323
57401
|
}
|
|
57324
|
-
if (msg.event.users.
|
|
57325
|
-
this.followers = this.followers.filter((follower) => follower !==
|
|
57402
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57403
|
+
this.followers = this.followers.filter((follower) => follower !== sessionId);
|
|
57326
57404
|
}
|
|
57327
57405
|
if (!this.trackedUser) {
|
|
57328
57406
|
return;
|
|
57329
57407
|
}
|
|
57330
|
-
if (this.trackedUser.
|
|
57408
|
+
if (this.trackedUser.sessionId !== sessionId) {
|
|
57331
57409
|
return;
|
|
57332
57410
|
}
|
|
57333
|
-
if (msg.event.users.
|
|
57411
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57334
57412
|
this.disableTracking();
|
|
57335
57413
|
}
|
|
57336
57414
|
}
|
|
57337
57415
|
processPing(msg) {
|
|
57338
|
-
const
|
|
57416
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57417
|
+
const user = this.users.get(sessionId);
|
|
57339
57418
|
user.lastPing = msg.event.timestamp;
|
|
57340
57419
|
const userCopy = { ...user };
|
|
57341
57420
|
this.updateUserMetaInfo(msg, userCopy, false);
|
|
57342
|
-
this.users.set(
|
|
57421
|
+
this.users.set(sessionId, userCopy);
|
|
57343
57422
|
}
|
|
57344
57423
|
processCameraEvent(msg) {
|
|
57345
|
-
const
|
|
57424
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57425
|
+
const user = this.users.get(sessionId);
|
|
57346
57426
|
const eventData = msg.event;
|
|
57347
57427
|
const userCopy = { ...user };
|
|
57348
57428
|
userCopy.camera = eventData;
|
|
57349
57429
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57350
|
-
this.users.set(
|
|
57351
|
-
if (this.trackedUser && this.trackedUser.
|
|
57430
|
+
this.users.set(sessionId, userCopy);
|
|
57431
|
+
if (this.trackedUser && this.trackedUser.sessionId === sessionId) {
|
|
57352
57432
|
this.trackedUser.camera = eventData;
|
|
57353
57433
|
this.board.camera.animateToMatrix(new Matrix(eventData.translateX, eventData.translateY, eventData.scaleX, eventData.scaleY, eventData.shearX, eventData.shearY));
|
|
57354
57434
|
}
|
|
57355
57435
|
}
|
|
57356
57436
|
processDrawSelect(msg) {
|
|
57357
|
-
const
|
|
57437
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57438
|
+
const user = this.users.get(sessionId);
|
|
57358
57439
|
const eventData = msg.event;
|
|
57359
57440
|
const userCopy = { ...user };
|
|
57360
57441
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57361
57442
|
userCopy.select = eventData.size;
|
|
57362
|
-
this.users.set(
|
|
57443
|
+
this.users.set(sessionId, userCopy);
|
|
57363
57444
|
}
|
|
57364
57445
|
processCancelDrawSelect(msg) {
|
|
57365
|
-
const
|
|
57446
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57447
|
+
const user = this.users.get(sessionId);
|
|
57366
57448
|
const userCopy = { ...user };
|
|
57367
57449
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57368
57450
|
userCopy.select = undefined;
|
|
57369
|
-
this.users.set(
|
|
57451
|
+
this.users.set(sessionId, userCopy);
|
|
57370
57452
|
}
|
|
57371
57453
|
processPointerMove(msg) {
|
|
57372
|
-
const
|
|
57454
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57455
|
+
const user = this.users.get(sessionId);
|
|
57373
57456
|
const eventData = msg.event;
|
|
57374
57457
|
const userCopy = { ...user };
|
|
57375
57458
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57376
57459
|
userCopy.lastPointerActivity = Date.now();
|
|
57377
57460
|
userCopy.pointer = { x: eventData.position.x, y: eventData.position.y };
|
|
57378
|
-
this.users.set(
|
|
57461
|
+
this.users.set(sessionId, userCopy);
|
|
57379
57462
|
}
|
|
57380
57463
|
processSelection(msg) {
|
|
57381
|
-
const
|
|
57464
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57465
|
+
const user = this.users.get(sessionId);
|
|
57382
57466
|
const eventData = msg.event;
|
|
57383
57467
|
const userCopy = { ...user };
|
|
57384
57468
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57385
57469
|
userCopy.selection = eventData.selectedItems;
|
|
57386
|
-
this.users.set(
|
|
57470
|
+
this.users.set(sessionId, userCopy);
|
|
57387
57471
|
}
|
|
57388
57472
|
processSetColor(msg) {
|
|
57389
|
-
const
|
|
57473
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57474
|
+
const user = this.users.get(sessionId);
|
|
57390
57475
|
const userCopy = { ...user };
|
|
57391
57476
|
userCopy.colorChangeable = false;
|
|
57392
57477
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57393
|
-
this.users.set(
|
|
57478
|
+
this.users.set(sessionId, userCopy);
|
|
57394
57479
|
}
|
|
57395
|
-
enableTracking(
|
|
57396
|
-
const user = this.users.get(
|
|
57480
|
+
enableTracking(sessionId) {
|
|
57481
|
+
const user = this.users.get(sessionId);
|
|
57397
57482
|
if (!user) {
|
|
57398
57483
|
this.trackedUser = null;
|
|
57399
57484
|
} else {
|
|
@@ -57403,7 +57488,7 @@ class Presence {
|
|
|
57403
57488
|
}
|
|
57404
57489
|
this.emit({
|
|
57405
57490
|
method: "Follow",
|
|
57406
|
-
user:
|
|
57491
|
+
user: sessionId,
|
|
57407
57492
|
timestamp: Date.now()
|
|
57408
57493
|
});
|
|
57409
57494
|
}
|
|
@@ -57416,7 +57501,7 @@ class Presence {
|
|
|
57416
57501
|
this.emit({
|
|
57417
57502
|
method: "StopFollowing",
|
|
57418
57503
|
timestamp: Date.now(),
|
|
57419
|
-
users: [this.trackedUser
|
|
57504
|
+
users: [this.trackedUser.sessionId || this.trackedUser.userId]
|
|
57420
57505
|
});
|
|
57421
57506
|
this.trackedUser = null;
|
|
57422
57507
|
}
|
|
@@ -57435,18 +57520,12 @@ class Presence {
|
|
|
57435
57520
|
return this.cursorsEnabled;
|
|
57436
57521
|
}
|
|
57437
57522
|
getSelects() {
|
|
57438
|
-
const
|
|
57523
|
+
const selects = [];
|
|
57524
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57439
57525
|
this.users.forEach((user) => {
|
|
57440
|
-
if (user.
|
|
57441
|
-
|
|
57442
|
-
const existingUser = uniqueUsers.get(key);
|
|
57443
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
57444
|
-
uniqueUsers.set(key, user);
|
|
57445
|
-
}
|
|
57526
|
+
if (currentSessionId && user.sessionId === currentSessionId) {
|
|
57527
|
+
return;
|
|
57446
57528
|
}
|
|
57447
|
-
});
|
|
57448
|
-
const selects = [];
|
|
57449
|
-
uniqueUsers.forEach((user) => {
|
|
57450
57529
|
if (user.select && Date.now() - user.lastActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57451
57530
|
selects.push({
|
|
57452
57531
|
...user.select,
|
|
@@ -57460,42 +57539,29 @@ class Presence {
|
|
|
57460
57539
|
getCursors() {
|
|
57461
57540
|
const currentBoardId = this.board.getBoardId();
|
|
57462
57541
|
const now = Date.now();
|
|
57463
|
-
const
|
|
57542
|
+
const cursors = [];
|
|
57543
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57464
57544
|
this.users.forEach((user) => {
|
|
57465
|
-
if (
|
|
57466
|
-
|
|
57467
|
-
|
|
57468
|
-
|
|
57469
|
-
|
|
57470
|
-
|
|
57545
|
+
if (currentSessionId !== user.sessionId && user.boardId === currentBoardId && now - user.lastPointerActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57546
|
+
cursors.push({
|
|
57547
|
+
...user.pointer,
|
|
57548
|
+
userId: user.sessionId || user.userId,
|
|
57549
|
+
color: user.color,
|
|
57550
|
+
nickname: user.nickname
|
|
57551
|
+
});
|
|
57471
57552
|
}
|
|
57472
57553
|
});
|
|
57473
|
-
const cursors = [];
|
|
57474
|
-
uniqueUsers.forEach((user) => {
|
|
57475
|
-
cursors.push({
|
|
57476
|
-
...user.pointer,
|
|
57477
|
-
userId: user.userId,
|
|
57478
|
-
color: user.color,
|
|
57479
|
-
nickname: user.nickname
|
|
57480
|
-
});
|
|
57481
|
-
});
|
|
57482
57554
|
return cursors;
|
|
57483
57555
|
}
|
|
57484
57556
|
getSelections() {
|
|
57485
57557
|
const currentBoardId = this.board.getBoardId();
|
|
57486
57558
|
const now = Date.now();
|
|
57487
|
-
const
|
|
57559
|
+
const selections = [];
|
|
57560
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57488
57561
|
this.users.forEach((user) => {
|
|
57489
|
-
if (
|
|
57490
|
-
|
|
57491
|
-
const existingUser = uniqueUsers.get(key);
|
|
57492
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
57493
|
-
uniqueUsers.set(key, user);
|
|
57494
|
-
}
|
|
57562
|
+
if (currentSessionId === user.sessionId || user.boardId !== currentBoardId || now - user.lastPointerActivity > CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57563
|
+
return;
|
|
57495
57564
|
}
|
|
57496
|
-
});
|
|
57497
|
-
const selections = [];
|
|
57498
|
-
uniqueUsers.forEach((user) => {
|
|
57499
57565
|
if (Date.now() - user.lastActivity >= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57500
57566
|
return;
|
|
57501
57567
|
}
|