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/cjs/browser.js
CHANGED
|
@@ -5859,17 +5859,50 @@ function getRecordByIdFromList(id, list) {
|
|
|
5859
5859
|
return;
|
|
5860
5860
|
}
|
|
5861
5861
|
|
|
5862
|
+
// src/Events/identity.ts
|
|
5863
|
+
function getBoardEventSessionId(body) {
|
|
5864
|
+
if (body.sessionId) {
|
|
5865
|
+
return body.sessionId;
|
|
5866
|
+
}
|
|
5867
|
+
if (body.userId === undefined || body.userId === null) {
|
|
5868
|
+
return;
|
|
5869
|
+
}
|
|
5870
|
+
return String(body.userId);
|
|
5871
|
+
}
|
|
5872
|
+
function getConnectionSessionId(connection) {
|
|
5873
|
+
return connection?.getSessionId?.() || connection?.sessionId || String(connection?.connectionId || 0);
|
|
5874
|
+
}
|
|
5875
|
+
function getConnectionSessionIds(connection) {
|
|
5876
|
+
const ids = new Set;
|
|
5877
|
+
const primary = connection?.getSessionId?.() || connection?.sessionId;
|
|
5878
|
+
if (primary) {
|
|
5879
|
+
ids.add(primary);
|
|
5880
|
+
}
|
|
5881
|
+
if (connection?.connectionId !== undefined) {
|
|
5882
|
+
ids.add(String(connection.connectionId));
|
|
5883
|
+
}
|
|
5884
|
+
if (ids.size === 0) {
|
|
5885
|
+
ids.add("0");
|
|
5886
|
+
}
|
|
5887
|
+
return Array.from(ids);
|
|
5888
|
+
}
|
|
5889
|
+
function getConnectionAuthorUserId(connection) {
|
|
5890
|
+
return connection?.getAuthorUserId?.() || connection?.authorUserId || connection?.getCurrentUser?.();
|
|
5891
|
+
}
|
|
5892
|
+
|
|
5862
5893
|
// src/Events/Log/shouldSkipEvent.ts
|
|
5863
|
-
function shouldSkipEvent(record,
|
|
5894
|
+
function shouldSkipEvent(record, sessionIds) {
|
|
5864
5895
|
const { operation } = record.event.body;
|
|
5865
|
-
|
|
5896
|
+
const eventSessionId = getBoardEventSessionId(record.event.body);
|
|
5897
|
+
return eventSessionId === undefined || !sessionIds.includes(eventSessionId) || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
|
|
5866
5898
|
}
|
|
5899
|
+
var init_shouldSkipEvent = () => {};
|
|
5867
5900
|
|
|
5868
5901
|
// src/Events/Log/getRedoRecordFromList.ts
|
|
5869
|
-
function getRedoRecordFromList(
|
|
5902
|
+
function getRedoRecordFromList(sessionIds, list) {
|
|
5870
5903
|
let counter = 0;
|
|
5871
5904
|
for (const record of list.backwardIterable()) {
|
|
5872
|
-
if (shouldSkipEvent(record,
|
|
5905
|
+
if (shouldSkipEvent(record, sessionIds)) {
|
|
5873
5906
|
continue;
|
|
5874
5907
|
}
|
|
5875
5908
|
if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
|
|
@@ -5888,17 +5921,19 @@ function getRedoRecordFromList(userId, list) {
|
|
|
5888
5921
|
}
|
|
5889
5922
|
return null;
|
|
5890
5923
|
}
|
|
5891
|
-
var init_getRedoRecordFromList = () => {
|
|
5924
|
+
var init_getRedoRecordFromList = __esm(() => {
|
|
5925
|
+
init_shouldSkipEvent();
|
|
5926
|
+
});
|
|
5892
5927
|
|
|
5893
5928
|
// src/Events/Log/getUndoRecordFromList.ts
|
|
5894
|
-
function getUndoRecordFromList(
|
|
5929
|
+
function getUndoRecordFromList(sessionIds, list) {
|
|
5895
5930
|
let counter = 0;
|
|
5896
5931
|
const isAllEventsConfirmed = list.isAllEventsConfirmed();
|
|
5897
5932
|
if (!isAllEventsConfirmed) {
|
|
5898
5933
|
return null;
|
|
5899
5934
|
}
|
|
5900
5935
|
for (const record of list.getConfirmedRecords().slice().reverse()) {
|
|
5901
|
-
if (shouldSkipEvent(record,
|
|
5936
|
+
if (shouldSkipEvent(record, sessionIds)) {
|
|
5902
5937
|
continue;
|
|
5903
5938
|
}
|
|
5904
5939
|
if (record.event.body.operation.method === "undo") {
|
|
@@ -5911,7 +5946,9 @@ function getUndoRecordFromList(userId, list) {
|
|
|
5911
5946
|
}
|
|
5912
5947
|
return null;
|
|
5913
5948
|
}
|
|
5914
|
-
var init_getUndoRecordFromList = () => {
|
|
5949
|
+
var init_getUndoRecordFromList = __esm(() => {
|
|
5950
|
+
init_shouldSkipEvent();
|
|
5951
|
+
});
|
|
5915
5952
|
|
|
5916
5953
|
// src/Events/Log/getUnpublishedEventFromList.ts
|
|
5917
5954
|
function getUnpublishedEventFromList(list) {
|
|
@@ -5990,11 +6027,12 @@ function expandEvents(events) {
|
|
|
5990
6027
|
order: event.order,
|
|
5991
6028
|
body: {
|
|
5992
6029
|
eventId: operation.actualId || bodyWithoutOps.eventId,
|
|
6030
|
+
authorUserId: bodyWithoutOps.authorUserId,
|
|
6031
|
+
sessionId: bodyWithoutOps.sessionId,
|
|
5993
6032
|
userId: bodyWithoutOps.userId,
|
|
5994
6033
|
boardId: bodyWithoutOps.boardId,
|
|
5995
6034
|
operation
|
|
5996
6035
|
},
|
|
5997
|
-
userId: bodyWithoutOps.userId,
|
|
5998
6036
|
lastKnownOrder
|
|
5999
6037
|
}));
|
|
6000
6038
|
} else {
|
|
@@ -6113,7 +6151,6 @@ function deserializeAndApplyToList(events, list, board) {
|
|
|
6113
6151
|
const singleEvent = {
|
|
6114
6152
|
order: event.order,
|
|
6115
6153
|
lastKnownOrder,
|
|
6116
|
-
userId: bodyWithoutOps.userId,
|
|
6117
6154
|
body: {
|
|
6118
6155
|
...bodyWithoutOps,
|
|
6119
6156
|
operation: op
|
|
@@ -6200,11 +6237,11 @@ class EventsLog {
|
|
|
6200
6237
|
getUnorderedRecords() {
|
|
6201
6238
|
return this.list.getRecordsToSend().concat(this.list.getNewRecords());
|
|
6202
6239
|
}
|
|
6203
|
-
getUndoRecord(
|
|
6204
|
-
return getUndoRecordFromList(
|
|
6240
|
+
getUndoRecord(sessionIds) {
|
|
6241
|
+
return getUndoRecordFromList(sessionIds, this.list);
|
|
6205
6242
|
}
|
|
6206
|
-
getRedoRecord(
|
|
6207
|
-
return getRedoRecordFromList(
|
|
6243
|
+
getRedoRecord(sessionIds) {
|
|
6244
|
+
return getRedoRecordFromList(sessionIds, this.list);
|
|
6208
6245
|
}
|
|
6209
6246
|
getRecordById(id) {
|
|
6210
6247
|
return getRecordByIdFromList(id, this.list);
|
|
@@ -14218,10 +14255,13 @@ class Events {
|
|
|
14218
14255
|
console.error("[DEBUG] transformMany emitted from Events.emit!", JSON.stringify(operation));
|
|
14219
14256
|
console.trace("[DEBUG] transformMany stack trace");
|
|
14220
14257
|
}
|
|
14221
|
-
const
|
|
14258
|
+
const sessionId = this.getSessionId();
|
|
14259
|
+
const authorUserId = this.getAuthorUserId();
|
|
14222
14260
|
const body = {
|
|
14223
14261
|
eventId: this.getNextEventId(),
|
|
14224
|
-
userId,
|
|
14262
|
+
userId: sessionId,
|
|
14263
|
+
authorUserId,
|
|
14264
|
+
sessionId,
|
|
14225
14265
|
boardId: this.board.getBoardId(),
|
|
14226
14266
|
operation
|
|
14227
14267
|
};
|
|
@@ -14231,7 +14271,7 @@ class Events {
|
|
|
14231
14271
|
command: command || Events.createCommand(this.board, operation)
|
|
14232
14272
|
};
|
|
14233
14273
|
this.log.insertNewLocalEventRecordAfterEmit(record);
|
|
14234
|
-
this.setLatestUserEvent(operation,
|
|
14274
|
+
this.setLatestUserEvent(operation, sessionId);
|
|
14235
14275
|
this.subject.publish(event);
|
|
14236
14276
|
if (this.board.getBoardId().includes("local")) {
|
|
14237
14277
|
if (this.log.saveFileTimeout) {
|
|
@@ -14252,13 +14292,13 @@ class Events {
|
|
|
14252
14292
|
this.emit(operation, cmd);
|
|
14253
14293
|
}
|
|
14254
14294
|
undo() {
|
|
14255
|
-
const
|
|
14256
|
-
const record = this.log.getUndoRecord(
|
|
14295
|
+
const currentSessionIds = this.getSessionIds();
|
|
14296
|
+
const record = this.log.getUndoRecord(currentSessionIds);
|
|
14257
14297
|
if (!record) {
|
|
14258
14298
|
return;
|
|
14259
14299
|
}
|
|
14260
|
-
const { operation,
|
|
14261
|
-
const canUndo = this.canUndoEvent(operation,
|
|
14300
|
+
const { operation, eventId } = record.event.body;
|
|
14301
|
+
const canUndo = this.canUndoEvent(operation, getBoardEventSessionId(record.event.body));
|
|
14262
14302
|
if (!canUndo) {
|
|
14263
14303
|
return;
|
|
14264
14304
|
}
|
|
@@ -14269,8 +14309,8 @@ class Events {
|
|
|
14269
14309
|
});
|
|
14270
14310
|
}
|
|
14271
14311
|
redo() {
|
|
14272
|
-
const
|
|
14273
|
-
const record = this.log.getRedoRecord(
|
|
14312
|
+
const sessionIds = this.getSessionIds();
|
|
14313
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14274
14314
|
if (!record) {
|
|
14275
14315
|
return;
|
|
14276
14316
|
}
|
|
@@ -14281,22 +14321,22 @@ class Events {
|
|
|
14281
14321
|
});
|
|
14282
14322
|
}
|
|
14283
14323
|
canUndo() {
|
|
14284
|
-
const
|
|
14285
|
-
const record = this.log.getUndoRecord(
|
|
14324
|
+
const sessionIds = this.getSessionIds();
|
|
14325
|
+
const record = this.log.getUndoRecord(sessionIds);
|
|
14286
14326
|
if (!record) {
|
|
14287
14327
|
return false;
|
|
14288
14328
|
}
|
|
14289
|
-
return this.canUndoEvent(record.event.body.operation, record.event.body
|
|
14329
|
+
return this.canUndoEvent(record.event.body.operation, getBoardEventSessionId(record.event.body));
|
|
14290
14330
|
}
|
|
14291
14331
|
canRedo() {
|
|
14292
|
-
const
|
|
14293
|
-
const record = this.log.getRedoRecord(
|
|
14332
|
+
const sessionIds = this.getSessionIds();
|
|
14333
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14294
14334
|
return record !== null;
|
|
14295
14335
|
}
|
|
14296
14336
|
sendPresenceEvent(event) {
|
|
14297
14337
|
conf.connection.publishPresenceEvent(this.board.getBoardId(), event);
|
|
14298
14338
|
}
|
|
14299
|
-
canUndoEvent(op,
|
|
14339
|
+
canUndoEvent(op, bySessionId) {
|
|
14300
14340
|
if (op.method === "undo") {
|
|
14301
14341
|
return false;
|
|
14302
14342
|
}
|
|
@@ -14306,24 +14346,30 @@ class Events {
|
|
|
14306
14346
|
}
|
|
14307
14347
|
const key = this.getOpKey(op);
|
|
14308
14348
|
const latest = this.latestEvent[key];
|
|
14309
|
-
return
|
|
14349
|
+
return bySessionId === undefined || bySessionId === latest;
|
|
14310
14350
|
}
|
|
14311
|
-
setLatestUserEvent(op,
|
|
14351
|
+
setLatestUserEvent(op, sessionId) {
|
|
14312
14352
|
if (op.class !== "Events" && op.method !== "paste" && op.method !== "duplicate") {
|
|
14313
14353
|
const key = this.getOpKey(op);
|
|
14314
|
-
this.latestEvent[key] =
|
|
14354
|
+
this.latestEvent[key] = sessionId;
|
|
14315
14355
|
}
|
|
14316
14356
|
}
|
|
14317
14357
|
getOpKey(op) {
|
|
14318
14358
|
return op.method;
|
|
14319
14359
|
}
|
|
14320
|
-
|
|
14321
|
-
return this.connection
|
|
14360
|
+
getSessionId() {
|
|
14361
|
+
return getConnectionSessionId(this.connection);
|
|
14362
|
+
}
|
|
14363
|
+
getSessionIds() {
|
|
14364
|
+
return getConnectionSessionIds(this.connection);
|
|
14365
|
+
}
|
|
14366
|
+
getAuthorUserId() {
|
|
14367
|
+
return getConnectionAuthorUserId(this.connection);
|
|
14322
14368
|
}
|
|
14323
14369
|
getNextEventId() {
|
|
14324
14370
|
const id = ++this.eventCounter;
|
|
14325
|
-
const
|
|
14326
|
-
return
|
|
14371
|
+
const sessionId = this.getSessionId();
|
|
14372
|
+
return sessionId + ":" + id;
|
|
14327
14373
|
}
|
|
14328
14374
|
}
|
|
14329
14375
|
function createEvents(board, connection, lastIndex) {
|
|
@@ -51371,6 +51417,9 @@ function validateItemsMap(parsedObject) {
|
|
|
51371
51417
|
}
|
|
51372
51418
|
return true;
|
|
51373
51419
|
}
|
|
51420
|
+
function isColorValue(v) {
|
|
51421
|
+
return typeof v === "string" || typeof v === "object" && v !== null;
|
|
51422
|
+
}
|
|
51374
51423
|
function validateItemData(itemData) {
|
|
51375
51424
|
if (typeof itemData !== "object" || itemData === null || !("itemType" in itemData) || typeof itemData.itemType !== "string") {
|
|
51376
51425
|
return false;
|
|
@@ -51383,7 +51432,7 @@ function validateFrameData(data) {
|
|
|
51383
51432
|
return false;
|
|
51384
51433
|
}
|
|
51385
51434
|
const frameData = data;
|
|
51386
|
-
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" &&
|
|
51435
|
+
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);
|
|
51387
51436
|
return isValid;
|
|
51388
51437
|
}
|
|
51389
51438
|
function validateShapeData(shapeData) {
|
|
@@ -51391,7 +51440,7 @@ function validateShapeData(shapeData) {
|
|
|
51391
51440
|
return false;
|
|
51392
51441
|
}
|
|
51393
51442
|
const data = shapeData;
|
|
51394
|
-
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" &&
|
|
51443
|
+
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);
|
|
51395
51444
|
return isValid;
|
|
51396
51445
|
}
|
|
51397
51446
|
function validateStickerData(shapeData) {
|
|
@@ -51399,7 +51448,7 @@ function validateStickerData(shapeData) {
|
|
|
51399
51448
|
return false;
|
|
51400
51449
|
}
|
|
51401
51450
|
const data = shapeData;
|
|
51402
|
-
const isValid = data.hasOwnProperty("itemType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") &&
|
|
51451
|
+
const isValid = data.hasOwnProperty("itemType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") && isColorValue(data.backgroundColor) && validateTransformationData(data.transformation) && validateRichTextData(data.text);
|
|
51403
51452
|
return isValid;
|
|
51404
51453
|
}
|
|
51405
51454
|
function validateTransformationData(transformationData) {
|
|
@@ -51423,7 +51472,7 @@ function validateConnectorData(connectorData) {
|
|
|
51423
51472
|
return false;
|
|
51424
51473
|
}
|
|
51425
51474
|
const data = connectorData;
|
|
51426
|
-
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" &&
|
|
51475
|
+
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);
|
|
51427
51476
|
return isValid;
|
|
51428
51477
|
}
|
|
51429
51478
|
function validateChildren(children) {
|
|
@@ -55590,9 +55639,9 @@ function handleBoardEventMessage(message, board) {
|
|
|
55590
55639
|
if (event.order <= log.getLastIndex()) {
|
|
55591
55640
|
return;
|
|
55592
55641
|
}
|
|
55593
|
-
const
|
|
55594
|
-
const currentConnectionId = board.events.connection
|
|
55595
|
-
const isEventFromCurrentUser =
|
|
55642
|
+
const eventSessionId = getBoardEventSessionId(event.body);
|
|
55643
|
+
const currentConnectionId = getConnectionSessionId(board.events.connection);
|
|
55644
|
+
const isEventFromCurrentUser = eventSessionId !== undefined && eventSessionId === currentConnectionId;
|
|
55596
55645
|
if (isEventFromCurrentUser) {
|
|
55597
55646
|
return;
|
|
55598
55647
|
}
|
|
@@ -55606,6 +55655,7 @@ function handleBoardEventMessage(message, board) {
|
|
|
55606
55655
|
board.events.subject.publish(last);
|
|
55607
55656
|
}
|
|
55608
55657
|
}
|
|
55658
|
+
var init_handleBoardEventMessage = () => {};
|
|
55609
55659
|
|
|
55610
55660
|
// src/Events/MessageRouter/handleBoardSubscriptionCompletedMsg.ts
|
|
55611
55661
|
function handleBoardSubscriptionCompletedMsg(msg, board) {
|
|
@@ -55714,8 +55764,7 @@ function sendBoardEvent(board, batch, sequenceNumber) {
|
|
|
55714
55764
|
type: "BoardEvent",
|
|
55715
55765
|
boardId: board.getBoardId(),
|
|
55716
55766
|
event: toSend,
|
|
55717
|
-
sequenceNumber
|
|
55718
|
-
userId: conf.connection.getCurrentUser()
|
|
55767
|
+
sequenceNumber
|
|
55719
55768
|
});
|
|
55720
55769
|
const date = Date.now();
|
|
55721
55770
|
log.pendingEvent = {
|
|
@@ -55851,6 +55900,7 @@ function handleUserJoinMessage(message, board) {
|
|
|
55851
55900
|
var messageRouter;
|
|
55852
55901
|
var init_messageRouter = __esm(() => {
|
|
55853
55902
|
init_handleAiChatMassage();
|
|
55903
|
+
init_handleBoardEventMessage();
|
|
55854
55904
|
init_handleBoardSubscriptionCompletedMsg();
|
|
55855
55905
|
init_handleConfirmation();
|
|
55856
55906
|
init_handleCreateSnapshotRequestMessage();
|
|
@@ -57320,6 +57370,15 @@ var PRESENCE_CLEANUP_USER_TIMER = 180000;
|
|
|
57320
57370
|
var PRESENCE_CLEANUP_IDLE_TIMER = 60000;
|
|
57321
57371
|
var CURSORS_IDLE_CLEANUP_DELAY = 1e4;
|
|
57322
57372
|
var PING_CLEANUP = 15000;
|
|
57373
|
+
function getPresenceSessionId(message) {
|
|
57374
|
+
if (message.sessionId) {
|
|
57375
|
+
return message.sessionId;
|
|
57376
|
+
}
|
|
57377
|
+
if (message.userId === undefined || message.userId === null) {
|
|
57378
|
+
return;
|
|
57379
|
+
}
|
|
57380
|
+
return String(message.userId);
|
|
57381
|
+
}
|
|
57323
57382
|
var cleanupInterval = null;
|
|
57324
57383
|
|
|
57325
57384
|
class Presence {
|
|
@@ -57329,7 +57388,6 @@ class Presence {
|
|
|
57329
57388
|
trackedUser = null;
|
|
57330
57389
|
cursorsEnabled = true;
|
|
57331
57390
|
drawingContext = null;
|
|
57332
|
-
currentUserId = null;
|
|
57333
57391
|
users = new Map;
|
|
57334
57392
|
followers = [];
|
|
57335
57393
|
svgImageCache = {};
|
|
@@ -57355,7 +57413,7 @@ class Presence {
|
|
|
57355
57413
|
throttleSelectionEvent(this.board.selection);
|
|
57356
57414
|
});
|
|
57357
57415
|
if (typeof window !== "undefined") {
|
|
57358
|
-
window.addEventListener("storage", this.
|
|
57416
|
+
window.addEventListener("storage", this.onStorageChange);
|
|
57359
57417
|
}
|
|
57360
57418
|
}
|
|
57361
57419
|
clear() {
|
|
@@ -57394,19 +57452,30 @@ class Presence {
|
|
|
57394
57452
|
}
|
|
57395
57453
|
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));
|
|
57396
57454
|
}
|
|
57397
|
-
|
|
57398
|
-
|
|
57455
|
+
onStorageChange = (_event) => {};
|
|
57456
|
+
getCurrentSessionId() {
|
|
57457
|
+
return this.events?.connection?.getSessionId?.() || this.events?.connection?.sessionId || null;
|
|
57399
57458
|
}
|
|
57400
|
-
|
|
57401
|
-
if (
|
|
57402
|
-
|
|
57403
|
-
this.setCurrentUser(event.newValue);
|
|
57404
|
-
}
|
|
57459
|
+
getLegacyCurrentUserId() {
|
|
57460
|
+
if (typeof localStorage === "undefined") {
|
|
57461
|
+
return null;
|
|
57405
57462
|
}
|
|
57463
|
+
return localStorage.getItem("currentUser");
|
|
57464
|
+
}
|
|
57465
|
+
isCurrentSessionTarget(value) {
|
|
57466
|
+
if (value === undefined || value === null) {
|
|
57467
|
+
return false;
|
|
57468
|
+
}
|
|
57469
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57470
|
+
if (currentSessionId && String(value) === currentSessionId) {
|
|
57471
|
+
return true;
|
|
57472
|
+
}
|
|
57473
|
+
const currentUser = this.getLegacyCurrentUserId();
|
|
57474
|
+
return currentUser !== null && String(value) === currentUser;
|
|
57406
57475
|
}
|
|
57407
57476
|
cleanup() {
|
|
57408
57477
|
if (typeof window !== "undefined") {
|
|
57409
|
-
window.removeEventListener("storage", this.
|
|
57478
|
+
window.removeEventListener("storage", this.onStorageChange);
|
|
57410
57479
|
}
|
|
57411
57480
|
this.drawingContext = null;
|
|
57412
57481
|
this.clear();
|
|
@@ -57446,24 +57515,25 @@ class Presence {
|
|
|
57446
57515
|
}
|
|
57447
57516
|
join(msg) {
|
|
57448
57517
|
Object.entries(msg.snapshots).map(([userId, snapshot]) => {
|
|
57449
|
-
|
|
57518
|
+
const sessionId = snapshot.sessionId || userId;
|
|
57519
|
+
this.users.set(sessionId, {
|
|
57520
|
+
...snapshot,
|
|
57521
|
+
userId: snapshot.userId || sessionId,
|
|
57522
|
+
sessionId,
|
|
57523
|
+
authorUserId: snapshot.authorUserId || null
|
|
57524
|
+
});
|
|
57450
57525
|
});
|
|
57451
57526
|
this.subject.publish(this);
|
|
57452
57527
|
}
|
|
57453
57528
|
getUsers(boardId, excludeSelf = false) {
|
|
57454
57529
|
let filteredUsers = Array.from(this.users.values()).filter((user) => user.boardId === boardId && (user.lastPing > Date.now() - PING_CLEANUP || user.lastActivity > Date.now() - PING_CLEANUP));
|
|
57455
57530
|
if (excludeSelf) {
|
|
57456
|
-
const
|
|
57457
|
-
if (
|
|
57458
|
-
filteredUsers = filteredUsers.filter((user) => user.
|
|
57531
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57532
|
+
if (currentSessionId) {
|
|
57533
|
+
filteredUsers = filteredUsers.filter((user) => user.sessionId !== currentSessionId);
|
|
57459
57534
|
}
|
|
57460
57535
|
}
|
|
57461
|
-
|
|
57462
|
-
filteredUsers.forEach((user) => {
|
|
57463
|
-
const key = user.hardId === null ? Symbol() : user.hardId;
|
|
57464
|
-
uniqueUsers.set(key, user);
|
|
57465
|
-
});
|
|
57466
|
-
return Array.from(uniqueUsers.values());
|
|
57536
|
+
return filteredUsers;
|
|
57467
57537
|
}
|
|
57468
57538
|
getColors() {
|
|
57469
57539
|
return Array.from(this.users.values()).map((user) => user.color);
|
|
@@ -57472,8 +57542,12 @@ class Presence {
|
|
|
57472
57542
|
if (!this.drawingContext) {
|
|
57473
57543
|
return;
|
|
57474
57544
|
}
|
|
57475
|
-
const
|
|
57476
|
-
|
|
57545
|
+
const sessionId = getPresenceSessionId(event);
|
|
57546
|
+
if (!sessionId) {
|
|
57547
|
+
return;
|
|
57548
|
+
}
|
|
57549
|
+
const { event: eventData } = event;
|
|
57550
|
+
let user = this.users.get(sessionId);
|
|
57477
57551
|
if (!user) {
|
|
57478
57552
|
let color2 = null;
|
|
57479
57553
|
const storageColor = localStorage.getItem(`userColor`);
|
|
@@ -57484,8 +57558,10 @@ class Presence {
|
|
|
57484
57558
|
} else {
|
|
57485
57559
|
color2 = this.generateUserColor();
|
|
57486
57560
|
}
|
|
57487
|
-
this.users.set(
|
|
57488
|
-
userId:
|
|
57561
|
+
this.users.set(sessionId, {
|
|
57562
|
+
userId: sessionId,
|
|
57563
|
+
sessionId,
|
|
57564
|
+
authorUserId: event.authorUserId || null,
|
|
57489
57565
|
softId: event.softId,
|
|
57490
57566
|
hardId: event.hardId,
|
|
57491
57567
|
color: color2,
|
|
@@ -57500,7 +57576,7 @@ class Presence {
|
|
|
57500
57576
|
boardId: this.board.getBoardId(),
|
|
57501
57577
|
lastPointerActivity: eventData.timestamp
|
|
57502
57578
|
});
|
|
57503
|
-
user = this.users.get(
|
|
57579
|
+
user = this.users.get(sessionId);
|
|
57504
57580
|
}
|
|
57505
57581
|
switch (eventData.method) {
|
|
57506
57582
|
case "PointerMove":
|
|
@@ -57543,6 +57619,9 @@ class Presence {
|
|
|
57543
57619
|
if (msg.color) {
|
|
57544
57620
|
userCopy.color = msg.color;
|
|
57545
57621
|
}
|
|
57622
|
+
if (msg.authorUserId) {
|
|
57623
|
+
userCopy.authorUserId = msg.authorUserId;
|
|
57624
|
+
}
|
|
57546
57625
|
userCopy.nickname = msg.nickname;
|
|
57547
57626
|
userCopy.boardId = msg.boardId;
|
|
57548
57627
|
if (shouldUpdateActivity) {
|
|
@@ -57550,107 +57629,113 @@ class Presence {
|
|
|
57550
57629
|
}
|
|
57551
57630
|
}
|
|
57552
57631
|
processFollowEvent(msg) {
|
|
57553
|
-
|
|
57554
|
-
|
|
57555
|
-
|
|
57556
|
-
|
|
57557
|
-
|
|
57558
|
-
this.followers.push(
|
|
57632
|
+
if (this.isCurrentSessionTarget(msg.event.user)) {
|
|
57633
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57634
|
+
if (!sessionId) {
|
|
57635
|
+
return;
|
|
57636
|
+
}
|
|
57637
|
+
this.followers.push(sessionId);
|
|
57559
57638
|
this.followers = Array.from(new Set(this.followers));
|
|
57560
57639
|
}
|
|
57561
57640
|
}
|
|
57562
57641
|
processBringToMe(msg) {
|
|
57563
|
-
|
|
57564
|
-
|
|
57565
|
-
|
|
57566
|
-
|
|
57567
|
-
|
|
57568
|
-
const bringerId = msg.userId.toString();
|
|
57642
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57643
|
+
const bringerId = getPresenceSessionId(msg);
|
|
57644
|
+
if (!bringerId) {
|
|
57645
|
+
return;
|
|
57646
|
+
}
|
|
57569
57647
|
const userToTrack = this.users.get(bringerId);
|
|
57570
57648
|
if (userToTrack) {
|
|
57571
57649
|
this.trackedUser = userToTrack;
|
|
57572
|
-
this.enableTracking(userToTrack.userId);
|
|
57650
|
+
this.enableTracking(userToTrack.sessionId || userToTrack.userId);
|
|
57573
57651
|
}
|
|
57574
57652
|
}
|
|
57575
57653
|
}
|
|
57576
57654
|
processStopFollowing(msg) {
|
|
57577
|
-
const
|
|
57578
|
-
if (!
|
|
57655
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57656
|
+
if (!sessionId) {
|
|
57579
57657
|
return;
|
|
57580
57658
|
}
|
|
57581
|
-
if (msg.event.users.
|
|
57582
|
-
this.followers = this.followers.filter((follower) => follower !==
|
|
57659
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57660
|
+
this.followers = this.followers.filter((follower) => follower !== sessionId);
|
|
57583
57661
|
}
|
|
57584
57662
|
if (!this.trackedUser) {
|
|
57585
57663
|
return;
|
|
57586
57664
|
}
|
|
57587
|
-
if (this.trackedUser.
|
|
57665
|
+
if (this.trackedUser.sessionId !== sessionId) {
|
|
57588
57666
|
return;
|
|
57589
57667
|
}
|
|
57590
|
-
if (msg.event.users.
|
|
57668
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57591
57669
|
this.disableTracking();
|
|
57592
57670
|
}
|
|
57593
57671
|
}
|
|
57594
57672
|
processPing(msg) {
|
|
57595
|
-
const
|
|
57673
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57674
|
+
const user = this.users.get(sessionId);
|
|
57596
57675
|
user.lastPing = msg.event.timestamp;
|
|
57597
57676
|
const userCopy = { ...user };
|
|
57598
57677
|
this.updateUserMetaInfo(msg, userCopy, false);
|
|
57599
|
-
this.users.set(
|
|
57678
|
+
this.users.set(sessionId, userCopy);
|
|
57600
57679
|
}
|
|
57601
57680
|
processCameraEvent(msg) {
|
|
57602
|
-
const
|
|
57681
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57682
|
+
const user = this.users.get(sessionId);
|
|
57603
57683
|
const eventData = msg.event;
|
|
57604
57684
|
const userCopy = { ...user };
|
|
57605
57685
|
userCopy.camera = eventData;
|
|
57606
57686
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57607
|
-
this.users.set(
|
|
57608
|
-
if (this.trackedUser && this.trackedUser.
|
|
57687
|
+
this.users.set(sessionId, userCopy);
|
|
57688
|
+
if (this.trackedUser && this.trackedUser.sessionId === sessionId) {
|
|
57609
57689
|
this.trackedUser.camera = eventData;
|
|
57610
57690
|
this.board.camera.animateToMatrix(new Matrix(eventData.translateX, eventData.translateY, eventData.scaleX, eventData.scaleY, eventData.shearX, eventData.shearY));
|
|
57611
57691
|
}
|
|
57612
57692
|
}
|
|
57613
57693
|
processDrawSelect(msg) {
|
|
57614
|
-
const
|
|
57694
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57695
|
+
const user = this.users.get(sessionId);
|
|
57615
57696
|
const eventData = msg.event;
|
|
57616
57697
|
const userCopy = { ...user };
|
|
57617
57698
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57618
57699
|
userCopy.select = eventData.size;
|
|
57619
|
-
this.users.set(
|
|
57700
|
+
this.users.set(sessionId, userCopy);
|
|
57620
57701
|
}
|
|
57621
57702
|
processCancelDrawSelect(msg) {
|
|
57622
|
-
const
|
|
57703
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57704
|
+
const user = this.users.get(sessionId);
|
|
57623
57705
|
const userCopy = { ...user };
|
|
57624
57706
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57625
57707
|
userCopy.select = undefined;
|
|
57626
|
-
this.users.set(
|
|
57708
|
+
this.users.set(sessionId, userCopy);
|
|
57627
57709
|
}
|
|
57628
57710
|
processPointerMove(msg) {
|
|
57629
|
-
const
|
|
57711
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57712
|
+
const user = this.users.get(sessionId);
|
|
57630
57713
|
const eventData = msg.event;
|
|
57631
57714
|
const userCopy = { ...user };
|
|
57632
57715
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57633
57716
|
userCopy.lastPointerActivity = Date.now();
|
|
57634
57717
|
userCopy.pointer = { x: eventData.position.x, y: eventData.position.y };
|
|
57635
|
-
this.users.set(
|
|
57718
|
+
this.users.set(sessionId, userCopy);
|
|
57636
57719
|
}
|
|
57637
57720
|
processSelection(msg) {
|
|
57638
|
-
const
|
|
57721
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57722
|
+
const user = this.users.get(sessionId);
|
|
57639
57723
|
const eventData = msg.event;
|
|
57640
57724
|
const userCopy = { ...user };
|
|
57641
57725
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57642
57726
|
userCopy.selection = eventData.selectedItems;
|
|
57643
|
-
this.users.set(
|
|
57727
|
+
this.users.set(sessionId, userCopy);
|
|
57644
57728
|
}
|
|
57645
57729
|
processSetColor(msg) {
|
|
57646
|
-
const
|
|
57730
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57731
|
+
const user = this.users.get(sessionId);
|
|
57647
57732
|
const userCopy = { ...user };
|
|
57648
57733
|
userCopy.colorChangeable = false;
|
|
57649
57734
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57650
|
-
this.users.set(
|
|
57735
|
+
this.users.set(sessionId, userCopy);
|
|
57651
57736
|
}
|
|
57652
|
-
enableTracking(
|
|
57653
|
-
const user = this.users.get(
|
|
57737
|
+
enableTracking(sessionId) {
|
|
57738
|
+
const user = this.users.get(sessionId);
|
|
57654
57739
|
if (!user) {
|
|
57655
57740
|
this.trackedUser = null;
|
|
57656
57741
|
} else {
|
|
@@ -57660,7 +57745,7 @@ class Presence {
|
|
|
57660
57745
|
}
|
|
57661
57746
|
this.emit({
|
|
57662
57747
|
method: "Follow",
|
|
57663
|
-
user:
|
|
57748
|
+
user: sessionId,
|
|
57664
57749
|
timestamp: Date.now()
|
|
57665
57750
|
});
|
|
57666
57751
|
}
|
|
@@ -57673,7 +57758,7 @@ class Presence {
|
|
|
57673
57758
|
this.emit({
|
|
57674
57759
|
method: "StopFollowing",
|
|
57675
57760
|
timestamp: Date.now(),
|
|
57676
|
-
users: [this.trackedUser
|
|
57761
|
+
users: [this.trackedUser.sessionId || this.trackedUser.userId]
|
|
57677
57762
|
});
|
|
57678
57763
|
this.trackedUser = null;
|
|
57679
57764
|
}
|
|
@@ -57692,18 +57777,12 @@ class Presence {
|
|
|
57692
57777
|
return this.cursorsEnabled;
|
|
57693
57778
|
}
|
|
57694
57779
|
getSelects() {
|
|
57695
|
-
const
|
|
57780
|
+
const selects = [];
|
|
57781
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57696
57782
|
this.users.forEach((user) => {
|
|
57697
|
-
if (user.
|
|
57698
|
-
|
|
57699
|
-
const existingUser = uniqueUsers.get(key);
|
|
57700
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
57701
|
-
uniqueUsers.set(key, user);
|
|
57702
|
-
}
|
|
57783
|
+
if (currentSessionId && user.sessionId === currentSessionId) {
|
|
57784
|
+
return;
|
|
57703
57785
|
}
|
|
57704
|
-
});
|
|
57705
|
-
const selects = [];
|
|
57706
|
-
uniqueUsers.forEach((user) => {
|
|
57707
57786
|
if (user.select && Date.now() - user.lastActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57708
57787
|
selects.push({
|
|
57709
57788
|
...user.select,
|
|
@@ -57717,42 +57796,29 @@ class Presence {
|
|
|
57717
57796
|
getCursors() {
|
|
57718
57797
|
const currentBoardId = this.board.getBoardId();
|
|
57719
57798
|
const now = Date.now();
|
|
57720
|
-
const
|
|
57799
|
+
const cursors = [];
|
|
57800
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57721
57801
|
this.users.forEach((user) => {
|
|
57722
|
-
if (
|
|
57723
|
-
|
|
57724
|
-
|
|
57725
|
-
|
|
57726
|
-
|
|
57727
|
-
|
|
57802
|
+
if (currentSessionId !== user.sessionId && user.boardId === currentBoardId && now - user.lastPointerActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57803
|
+
cursors.push({
|
|
57804
|
+
...user.pointer,
|
|
57805
|
+
userId: user.sessionId || user.userId,
|
|
57806
|
+
color: user.color,
|
|
57807
|
+
nickname: user.nickname
|
|
57808
|
+
});
|
|
57728
57809
|
}
|
|
57729
57810
|
});
|
|
57730
|
-
const cursors = [];
|
|
57731
|
-
uniqueUsers.forEach((user) => {
|
|
57732
|
-
cursors.push({
|
|
57733
|
-
...user.pointer,
|
|
57734
|
-
userId: user.userId,
|
|
57735
|
-
color: user.color,
|
|
57736
|
-
nickname: user.nickname
|
|
57737
|
-
});
|
|
57738
|
-
});
|
|
57739
57811
|
return cursors;
|
|
57740
57812
|
}
|
|
57741
57813
|
getSelections() {
|
|
57742
57814
|
const currentBoardId = this.board.getBoardId();
|
|
57743
57815
|
const now = Date.now();
|
|
57744
|
-
const
|
|
57816
|
+
const selections = [];
|
|
57817
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57745
57818
|
this.users.forEach((user) => {
|
|
57746
|
-
if (
|
|
57747
|
-
|
|
57748
|
-
const existingUser = uniqueUsers.get(key);
|
|
57749
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
57750
|
-
uniqueUsers.set(key, user);
|
|
57751
|
-
}
|
|
57819
|
+
if (currentSessionId === user.sessionId || user.boardId !== currentBoardId || now - user.lastPointerActivity > CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57820
|
+
return;
|
|
57752
57821
|
}
|
|
57753
|
-
});
|
|
57754
|
-
const selections = [];
|
|
57755
|
-
uniqueUsers.forEach((user) => {
|
|
57756
57822
|
if (Date.now() - user.lastActivity >= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57757
57823
|
return;
|
|
57758
57824
|
}
|