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/node.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);
|
|
@@ -14238,10 +14275,13 @@ class Events {
|
|
|
14238
14275
|
console.error("[DEBUG] transformMany emitted from Events.emit!", JSON.stringify(operation));
|
|
14239
14276
|
console.trace("[DEBUG] transformMany stack trace");
|
|
14240
14277
|
}
|
|
14241
|
-
const
|
|
14278
|
+
const sessionId = this.getSessionId();
|
|
14279
|
+
const authorUserId = this.getAuthorUserId();
|
|
14242
14280
|
const body = {
|
|
14243
14281
|
eventId: this.getNextEventId(),
|
|
14244
|
-
userId,
|
|
14282
|
+
userId: sessionId,
|
|
14283
|
+
authorUserId,
|
|
14284
|
+
sessionId,
|
|
14245
14285
|
boardId: this.board.getBoardId(),
|
|
14246
14286
|
operation
|
|
14247
14287
|
};
|
|
@@ -14251,7 +14291,7 @@ class Events {
|
|
|
14251
14291
|
command: command || Events.createCommand(this.board, operation)
|
|
14252
14292
|
};
|
|
14253
14293
|
this.log.insertNewLocalEventRecordAfterEmit(record);
|
|
14254
|
-
this.setLatestUserEvent(operation,
|
|
14294
|
+
this.setLatestUserEvent(operation, sessionId);
|
|
14255
14295
|
this.subject.publish(event);
|
|
14256
14296
|
if (this.board.getBoardId().includes("local")) {
|
|
14257
14297
|
if (this.log.saveFileTimeout) {
|
|
@@ -14272,13 +14312,13 @@ class Events {
|
|
|
14272
14312
|
this.emit(operation, cmd);
|
|
14273
14313
|
}
|
|
14274
14314
|
undo() {
|
|
14275
|
-
const
|
|
14276
|
-
const record = this.log.getUndoRecord(
|
|
14315
|
+
const currentSessionIds = this.getSessionIds();
|
|
14316
|
+
const record = this.log.getUndoRecord(currentSessionIds);
|
|
14277
14317
|
if (!record) {
|
|
14278
14318
|
return;
|
|
14279
14319
|
}
|
|
14280
|
-
const { operation,
|
|
14281
|
-
const canUndo = this.canUndoEvent(operation,
|
|
14320
|
+
const { operation, eventId } = record.event.body;
|
|
14321
|
+
const canUndo = this.canUndoEvent(operation, getBoardEventSessionId(record.event.body));
|
|
14282
14322
|
if (!canUndo) {
|
|
14283
14323
|
return;
|
|
14284
14324
|
}
|
|
@@ -14289,8 +14329,8 @@ class Events {
|
|
|
14289
14329
|
});
|
|
14290
14330
|
}
|
|
14291
14331
|
redo() {
|
|
14292
|
-
const
|
|
14293
|
-
const record = this.log.getRedoRecord(
|
|
14332
|
+
const sessionIds = this.getSessionIds();
|
|
14333
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14294
14334
|
if (!record) {
|
|
14295
14335
|
return;
|
|
14296
14336
|
}
|
|
@@ -14301,22 +14341,22 @@ class Events {
|
|
|
14301
14341
|
});
|
|
14302
14342
|
}
|
|
14303
14343
|
canUndo() {
|
|
14304
|
-
const
|
|
14305
|
-
const record = this.log.getUndoRecord(
|
|
14344
|
+
const sessionIds = this.getSessionIds();
|
|
14345
|
+
const record = this.log.getUndoRecord(sessionIds);
|
|
14306
14346
|
if (!record) {
|
|
14307
14347
|
return false;
|
|
14308
14348
|
}
|
|
14309
|
-
return this.canUndoEvent(record.event.body.operation, record.event.body
|
|
14349
|
+
return this.canUndoEvent(record.event.body.operation, getBoardEventSessionId(record.event.body));
|
|
14310
14350
|
}
|
|
14311
14351
|
canRedo() {
|
|
14312
|
-
const
|
|
14313
|
-
const record = this.log.getRedoRecord(
|
|
14352
|
+
const sessionIds = this.getSessionIds();
|
|
14353
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14314
14354
|
return record !== null;
|
|
14315
14355
|
}
|
|
14316
14356
|
sendPresenceEvent(event) {
|
|
14317
14357
|
conf.connection.publishPresenceEvent(this.board.getBoardId(), event);
|
|
14318
14358
|
}
|
|
14319
|
-
canUndoEvent(op,
|
|
14359
|
+
canUndoEvent(op, bySessionId) {
|
|
14320
14360
|
if (op.method === "undo") {
|
|
14321
14361
|
return false;
|
|
14322
14362
|
}
|
|
@@ -14326,24 +14366,30 @@ class Events {
|
|
|
14326
14366
|
}
|
|
14327
14367
|
const key = this.getOpKey(op);
|
|
14328
14368
|
const latest = this.latestEvent[key];
|
|
14329
|
-
return
|
|
14369
|
+
return bySessionId === undefined || bySessionId === latest;
|
|
14330
14370
|
}
|
|
14331
|
-
setLatestUserEvent(op,
|
|
14371
|
+
setLatestUserEvent(op, sessionId) {
|
|
14332
14372
|
if (op.class !== "Events" && op.method !== "paste" && op.method !== "duplicate") {
|
|
14333
14373
|
const key = this.getOpKey(op);
|
|
14334
|
-
this.latestEvent[key] =
|
|
14374
|
+
this.latestEvent[key] = sessionId;
|
|
14335
14375
|
}
|
|
14336
14376
|
}
|
|
14337
14377
|
getOpKey(op) {
|
|
14338
14378
|
return op.method;
|
|
14339
14379
|
}
|
|
14340
|
-
|
|
14341
|
-
return this.connection
|
|
14380
|
+
getSessionId() {
|
|
14381
|
+
return getConnectionSessionId(this.connection);
|
|
14382
|
+
}
|
|
14383
|
+
getSessionIds() {
|
|
14384
|
+
return getConnectionSessionIds(this.connection);
|
|
14385
|
+
}
|
|
14386
|
+
getAuthorUserId() {
|
|
14387
|
+
return getConnectionAuthorUserId(this.connection);
|
|
14342
14388
|
}
|
|
14343
14389
|
getNextEventId() {
|
|
14344
14390
|
const id = ++this.eventCounter;
|
|
14345
|
-
const
|
|
14346
|
-
return
|
|
14391
|
+
const sessionId = this.getSessionId();
|
|
14392
|
+
return sessionId + ":" + id;
|
|
14347
14393
|
}
|
|
14348
14394
|
}
|
|
14349
14395
|
function createEvents(board, connection, lastIndex) {
|
|
@@ -53791,6 +53837,9 @@ function validateItemsMap(parsedObject) {
|
|
|
53791
53837
|
}
|
|
53792
53838
|
return true;
|
|
53793
53839
|
}
|
|
53840
|
+
function isColorValue(v) {
|
|
53841
|
+
return typeof v === "string" || typeof v === "object" && v !== null;
|
|
53842
|
+
}
|
|
53794
53843
|
function validateItemData(itemData) {
|
|
53795
53844
|
if (typeof itemData !== "object" || itemData === null || !("itemType" in itemData) || typeof itemData.itemType !== "string") {
|
|
53796
53845
|
return false;
|
|
@@ -53803,7 +53852,7 @@ function validateFrameData(data) {
|
|
|
53803
53852
|
return false;
|
|
53804
53853
|
}
|
|
53805
53854
|
const frameData = data;
|
|
53806
|
-
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" &&
|
|
53855
|
+
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);
|
|
53807
53856
|
return isValid;
|
|
53808
53857
|
}
|
|
53809
53858
|
function validateShapeData(shapeData) {
|
|
@@ -53811,7 +53860,7 @@ function validateShapeData(shapeData) {
|
|
|
53811
53860
|
return false;
|
|
53812
53861
|
}
|
|
53813
53862
|
const data = shapeData;
|
|
53814
|
-
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" &&
|
|
53863
|
+
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);
|
|
53815
53864
|
return isValid;
|
|
53816
53865
|
}
|
|
53817
53866
|
function validateStickerData(shapeData) {
|
|
@@ -53819,7 +53868,7 @@ function validateStickerData(shapeData) {
|
|
|
53819
53868
|
return false;
|
|
53820
53869
|
}
|
|
53821
53870
|
const data = shapeData;
|
|
53822
|
-
const isValid = data.hasOwnProperty("itemType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") &&
|
|
53871
|
+
const isValid = data.hasOwnProperty("itemType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") && isColorValue(data.backgroundColor) && validateTransformationData(data.transformation) && validateRichTextData(data.text);
|
|
53823
53872
|
return isValid;
|
|
53824
53873
|
}
|
|
53825
53874
|
function validateTransformationData(transformationData) {
|
|
@@ -53843,7 +53892,7 @@ function validateConnectorData(connectorData) {
|
|
|
53843
53892
|
return false;
|
|
53844
53893
|
}
|
|
53845
53894
|
const data = connectorData;
|
|
53846
|
-
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" &&
|
|
53895
|
+
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);
|
|
53847
53896
|
return isValid;
|
|
53848
53897
|
}
|
|
53849
53898
|
function validateChildren(children) {
|
|
@@ -58010,9 +58059,9 @@ function handleBoardEventMessage(message, board) {
|
|
|
58010
58059
|
if (event.order <= log.getLastIndex()) {
|
|
58011
58060
|
return;
|
|
58012
58061
|
}
|
|
58013
|
-
const
|
|
58014
|
-
const currentConnectionId = board.events.connection
|
|
58015
|
-
const isEventFromCurrentUser =
|
|
58062
|
+
const eventSessionId = getBoardEventSessionId(event.body);
|
|
58063
|
+
const currentConnectionId = getConnectionSessionId(board.events.connection);
|
|
58064
|
+
const isEventFromCurrentUser = eventSessionId !== undefined && eventSessionId === currentConnectionId;
|
|
58016
58065
|
if (isEventFromCurrentUser) {
|
|
58017
58066
|
return;
|
|
58018
58067
|
}
|
|
@@ -58026,6 +58075,7 @@ function handleBoardEventMessage(message, board) {
|
|
|
58026
58075
|
board.events.subject.publish(last);
|
|
58027
58076
|
}
|
|
58028
58077
|
}
|
|
58078
|
+
var init_handleBoardEventMessage = () => {};
|
|
58029
58079
|
|
|
58030
58080
|
// src/Events/MessageRouter/handleBoardSubscriptionCompletedMsg.ts
|
|
58031
58081
|
function handleBoardSubscriptionCompletedMsg(msg, board) {
|
|
@@ -58134,8 +58184,7 @@ function sendBoardEvent(board, batch, sequenceNumber) {
|
|
|
58134
58184
|
type: "BoardEvent",
|
|
58135
58185
|
boardId: board.getBoardId(),
|
|
58136
58186
|
event: toSend,
|
|
58137
|
-
sequenceNumber
|
|
58138
|
-
userId: conf.connection.getCurrentUser()
|
|
58187
|
+
sequenceNumber
|
|
58139
58188
|
});
|
|
58140
58189
|
const date = Date.now();
|
|
58141
58190
|
log.pendingEvent = {
|
|
@@ -58271,6 +58320,7 @@ function handleUserJoinMessage(message, board) {
|
|
|
58271
58320
|
var messageRouter;
|
|
58272
58321
|
var init_messageRouter = __esm(() => {
|
|
58273
58322
|
init_handleAiChatMassage();
|
|
58323
|
+
init_handleBoardEventMessage();
|
|
58274
58324
|
init_handleBoardSubscriptionCompletedMsg();
|
|
58275
58325
|
init_handleConfirmation();
|
|
58276
58326
|
init_handleCreateSnapshotRequestMessage();
|
|
@@ -59795,6 +59845,15 @@ var PRESENCE_CLEANUP_USER_TIMER = 180000;
|
|
|
59795
59845
|
var PRESENCE_CLEANUP_IDLE_TIMER = 60000;
|
|
59796
59846
|
var CURSORS_IDLE_CLEANUP_DELAY = 1e4;
|
|
59797
59847
|
var PING_CLEANUP = 15000;
|
|
59848
|
+
function getPresenceSessionId(message) {
|
|
59849
|
+
if (message.sessionId) {
|
|
59850
|
+
return message.sessionId;
|
|
59851
|
+
}
|
|
59852
|
+
if (message.userId === undefined || message.userId === null) {
|
|
59853
|
+
return;
|
|
59854
|
+
}
|
|
59855
|
+
return String(message.userId);
|
|
59856
|
+
}
|
|
59798
59857
|
var cleanupInterval = null;
|
|
59799
59858
|
|
|
59800
59859
|
class Presence {
|
|
@@ -59804,7 +59863,6 @@ class Presence {
|
|
|
59804
59863
|
trackedUser = null;
|
|
59805
59864
|
cursorsEnabled = true;
|
|
59806
59865
|
drawingContext = null;
|
|
59807
|
-
currentUserId = null;
|
|
59808
59866
|
users = new Map;
|
|
59809
59867
|
followers = [];
|
|
59810
59868
|
svgImageCache = {};
|
|
@@ -59830,7 +59888,7 @@ class Presence {
|
|
|
59830
59888
|
throttleSelectionEvent(this.board.selection);
|
|
59831
59889
|
});
|
|
59832
59890
|
if (typeof window !== "undefined") {
|
|
59833
|
-
window.addEventListener("storage", this.
|
|
59891
|
+
window.addEventListener("storage", this.onStorageChange);
|
|
59834
59892
|
}
|
|
59835
59893
|
}
|
|
59836
59894
|
clear() {
|
|
@@ -59869,19 +59927,30 @@ class Presence {
|
|
|
59869
59927
|
}
|
|
59870
59928
|
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));
|
|
59871
59929
|
}
|
|
59872
|
-
|
|
59873
|
-
|
|
59930
|
+
onStorageChange = (_event) => {};
|
|
59931
|
+
getCurrentSessionId() {
|
|
59932
|
+
return this.events?.connection?.getSessionId?.() || this.events?.connection?.sessionId || null;
|
|
59874
59933
|
}
|
|
59875
|
-
|
|
59876
|
-
if (
|
|
59877
|
-
|
|
59878
|
-
this.setCurrentUser(event.newValue);
|
|
59879
|
-
}
|
|
59934
|
+
getLegacyCurrentUserId() {
|
|
59935
|
+
if (typeof localStorage === "undefined") {
|
|
59936
|
+
return null;
|
|
59880
59937
|
}
|
|
59938
|
+
return localStorage.getItem("currentUser");
|
|
59939
|
+
}
|
|
59940
|
+
isCurrentSessionTarget(value) {
|
|
59941
|
+
if (value === undefined || value === null) {
|
|
59942
|
+
return false;
|
|
59943
|
+
}
|
|
59944
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
59945
|
+
if (currentSessionId && String(value) === currentSessionId) {
|
|
59946
|
+
return true;
|
|
59947
|
+
}
|
|
59948
|
+
const currentUser = this.getLegacyCurrentUserId();
|
|
59949
|
+
return currentUser !== null && String(value) === currentUser;
|
|
59881
59950
|
}
|
|
59882
59951
|
cleanup() {
|
|
59883
59952
|
if (typeof window !== "undefined") {
|
|
59884
|
-
window.removeEventListener("storage", this.
|
|
59953
|
+
window.removeEventListener("storage", this.onStorageChange);
|
|
59885
59954
|
}
|
|
59886
59955
|
this.drawingContext = null;
|
|
59887
59956
|
this.clear();
|
|
@@ -59921,24 +59990,25 @@ class Presence {
|
|
|
59921
59990
|
}
|
|
59922
59991
|
join(msg) {
|
|
59923
59992
|
Object.entries(msg.snapshots).map(([userId, snapshot]) => {
|
|
59924
|
-
|
|
59993
|
+
const sessionId = snapshot.sessionId || userId;
|
|
59994
|
+
this.users.set(sessionId, {
|
|
59995
|
+
...snapshot,
|
|
59996
|
+
userId: snapshot.userId || sessionId,
|
|
59997
|
+
sessionId,
|
|
59998
|
+
authorUserId: snapshot.authorUserId || null
|
|
59999
|
+
});
|
|
59925
60000
|
});
|
|
59926
60001
|
this.subject.publish(this);
|
|
59927
60002
|
}
|
|
59928
60003
|
getUsers(boardId, excludeSelf = false) {
|
|
59929
60004
|
let filteredUsers = Array.from(this.users.values()).filter((user) => user.boardId === boardId && (user.lastPing > Date.now() - PING_CLEANUP || user.lastActivity > Date.now() - PING_CLEANUP));
|
|
59930
60005
|
if (excludeSelf) {
|
|
59931
|
-
const
|
|
59932
|
-
if (
|
|
59933
|
-
filteredUsers = filteredUsers.filter((user) => user.
|
|
60006
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
60007
|
+
if (currentSessionId) {
|
|
60008
|
+
filteredUsers = filteredUsers.filter((user) => user.sessionId !== currentSessionId);
|
|
59934
60009
|
}
|
|
59935
60010
|
}
|
|
59936
|
-
|
|
59937
|
-
filteredUsers.forEach((user) => {
|
|
59938
|
-
const key = user.hardId === null ? Symbol() : user.hardId;
|
|
59939
|
-
uniqueUsers.set(key, user);
|
|
59940
|
-
});
|
|
59941
|
-
return Array.from(uniqueUsers.values());
|
|
60011
|
+
return filteredUsers;
|
|
59942
60012
|
}
|
|
59943
60013
|
getColors() {
|
|
59944
60014
|
return Array.from(this.users.values()).map((user) => user.color);
|
|
@@ -59947,8 +60017,12 @@ class Presence {
|
|
|
59947
60017
|
if (!this.drawingContext) {
|
|
59948
60018
|
return;
|
|
59949
60019
|
}
|
|
59950
|
-
const
|
|
59951
|
-
|
|
60020
|
+
const sessionId = getPresenceSessionId(event);
|
|
60021
|
+
if (!sessionId) {
|
|
60022
|
+
return;
|
|
60023
|
+
}
|
|
60024
|
+
const { event: eventData } = event;
|
|
60025
|
+
let user = this.users.get(sessionId);
|
|
59952
60026
|
if (!user) {
|
|
59953
60027
|
let color2 = null;
|
|
59954
60028
|
const storageColor = localStorage.getItem(`userColor`);
|
|
@@ -59959,8 +60033,10 @@ class Presence {
|
|
|
59959
60033
|
} else {
|
|
59960
60034
|
color2 = this.generateUserColor();
|
|
59961
60035
|
}
|
|
59962
|
-
this.users.set(
|
|
59963
|
-
userId:
|
|
60036
|
+
this.users.set(sessionId, {
|
|
60037
|
+
userId: sessionId,
|
|
60038
|
+
sessionId,
|
|
60039
|
+
authorUserId: event.authorUserId || null,
|
|
59964
60040
|
softId: event.softId,
|
|
59965
60041
|
hardId: event.hardId,
|
|
59966
60042
|
color: color2,
|
|
@@ -59975,7 +60051,7 @@ class Presence {
|
|
|
59975
60051
|
boardId: this.board.getBoardId(),
|
|
59976
60052
|
lastPointerActivity: eventData.timestamp
|
|
59977
60053
|
});
|
|
59978
|
-
user = this.users.get(
|
|
60054
|
+
user = this.users.get(sessionId);
|
|
59979
60055
|
}
|
|
59980
60056
|
switch (eventData.method) {
|
|
59981
60057
|
case "PointerMove":
|
|
@@ -60018,6 +60094,9 @@ class Presence {
|
|
|
60018
60094
|
if (msg.color) {
|
|
60019
60095
|
userCopy.color = msg.color;
|
|
60020
60096
|
}
|
|
60097
|
+
if (msg.authorUserId) {
|
|
60098
|
+
userCopy.authorUserId = msg.authorUserId;
|
|
60099
|
+
}
|
|
60021
60100
|
userCopy.nickname = msg.nickname;
|
|
60022
60101
|
userCopy.boardId = msg.boardId;
|
|
60023
60102
|
if (shouldUpdateActivity) {
|
|
@@ -60025,107 +60104,113 @@ class Presence {
|
|
|
60025
60104
|
}
|
|
60026
60105
|
}
|
|
60027
60106
|
processFollowEvent(msg) {
|
|
60028
|
-
|
|
60029
|
-
|
|
60030
|
-
|
|
60031
|
-
|
|
60032
|
-
|
|
60033
|
-
this.followers.push(
|
|
60107
|
+
if (this.isCurrentSessionTarget(msg.event.user)) {
|
|
60108
|
+
const sessionId = getPresenceSessionId(msg);
|
|
60109
|
+
if (!sessionId) {
|
|
60110
|
+
return;
|
|
60111
|
+
}
|
|
60112
|
+
this.followers.push(sessionId);
|
|
60034
60113
|
this.followers = Array.from(new Set(this.followers));
|
|
60035
60114
|
}
|
|
60036
60115
|
}
|
|
60037
60116
|
processBringToMe(msg) {
|
|
60038
|
-
|
|
60039
|
-
|
|
60040
|
-
|
|
60041
|
-
|
|
60042
|
-
|
|
60043
|
-
const bringerId = msg.userId.toString();
|
|
60117
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
60118
|
+
const bringerId = getPresenceSessionId(msg);
|
|
60119
|
+
if (!bringerId) {
|
|
60120
|
+
return;
|
|
60121
|
+
}
|
|
60044
60122
|
const userToTrack = this.users.get(bringerId);
|
|
60045
60123
|
if (userToTrack) {
|
|
60046
60124
|
this.trackedUser = userToTrack;
|
|
60047
|
-
this.enableTracking(userToTrack.userId);
|
|
60125
|
+
this.enableTracking(userToTrack.sessionId || userToTrack.userId);
|
|
60048
60126
|
}
|
|
60049
60127
|
}
|
|
60050
60128
|
}
|
|
60051
60129
|
processStopFollowing(msg) {
|
|
60052
|
-
const
|
|
60053
|
-
if (!
|
|
60130
|
+
const sessionId = getPresenceSessionId(msg);
|
|
60131
|
+
if (!sessionId) {
|
|
60054
60132
|
return;
|
|
60055
60133
|
}
|
|
60056
|
-
if (msg.event.users.
|
|
60057
|
-
this.followers = this.followers.filter((follower) => follower !==
|
|
60134
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
60135
|
+
this.followers = this.followers.filter((follower) => follower !== sessionId);
|
|
60058
60136
|
}
|
|
60059
60137
|
if (!this.trackedUser) {
|
|
60060
60138
|
return;
|
|
60061
60139
|
}
|
|
60062
|
-
if (this.trackedUser.
|
|
60140
|
+
if (this.trackedUser.sessionId !== sessionId) {
|
|
60063
60141
|
return;
|
|
60064
60142
|
}
|
|
60065
|
-
if (msg.event.users.
|
|
60143
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
60066
60144
|
this.disableTracking();
|
|
60067
60145
|
}
|
|
60068
60146
|
}
|
|
60069
60147
|
processPing(msg) {
|
|
60070
|
-
const
|
|
60148
|
+
const sessionId = getPresenceSessionId(msg);
|
|
60149
|
+
const user = this.users.get(sessionId);
|
|
60071
60150
|
user.lastPing = msg.event.timestamp;
|
|
60072
60151
|
const userCopy = { ...user };
|
|
60073
60152
|
this.updateUserMetaInfo(msg, userCopy, false);
|
|
60074
|
-
this.users.set(
|
|
60153
|
+
this.users.set(sessionId, userCopy);
|
|
60075
60154
|
}
|
|
60076
60155
|
processCameraEvent(msg) {
|
|
60077
|
-
const
|
|
60156
|
+
const sessionId = getPresenceSessionId(msg);
|
|
60157
|
+
const user = this.users.get(sessionId);
|
|
60078
60158
|
const eventData = msg.event;
|
|
60079
60159
|
const userCopy = { ...user };
|
|
60080
60160
|
userCopy.camera = eventData;
|
|
60081
60161
|
this.updateUserMetaInfo(msg, userCopy);
|
|
60082
|
-
this.users.set(
|
|
60083
|
-
if (this.trackedUser && this.trackedUser.
|
|
60162
|
+
this.users.set(sessionId, userCopy);
|
|
60163
|
+
if (this.trackedUser && this.trackedUser.sessionId === sessionId) {
|
|
60084
60164
|
this.trackedUser.camera = eventData;
|
|
60085
60165
|
this.board.camera.animateToMatrix(new Matrix(eventData.translateX, eventData.translateY, eventData.scaleX, eventData.scaleY, eventData.shearX, eventData.shearY));
|
|
60086
60166
|
}
|
|
60087
60167
|
}
|
|
60088
60168
|
processDrawSelect(msg) {
|
|
60089
|
-
const
|
|
60169
|
+
const sessionId = getPresenceSessionId(msg);
|
|
60170
|
+
const user = this.users.get(sessionId);
|
|
60090
60171
|
const eventData = msg.event;
|
|
60091
60172
|
const userCopy = { ...user };
|
|
60092
60173
|
this.updateUserMetaInfo(msg, userCopy);
|
|
60093
60174
|
userCopy.select = eventData.size;
|
|
60094
|
-
this.users.set(
|
|
60175
|
+
this.users.set(sessionId, userCopy);
|
|
60095
60176
|
}
|
|
60096
60177
|
processCancelDrawSelect(msg) {
|
|
60097
|
-
const
|
|
60178
|
+
const sessionId = getPresenceSessionId(msg);
|
|
60179
|
+
const user = this.users.get(sessionId);
|
|
60098
60180
|
const userCopy = { ...user };
|
|
60099
60181
|
this.updateUserMetaInfo(msg, userCopy);
|
|
60100
60182
|
userCopy.select = undefined;
|
|
60101
|
-
this.users.set(
|
|
60183
|
+
this.users.set(sessionId, userCopy);
|
|
60102
60184
|
}
|
|
60103
60185
|
processPointerMove(msg) {
|
|
60104
|
-
const
|
|
60186
|
+
const sessionId = getPresenceSessionId(msg);
|
|
60187
|
+
const user = this.users.get(sessionId);
|
|
60105
60188
|
const eventData = msg.event;
|
|
60106
60189
|
const userCopy = { ...user };
|
|
60107
60190
|
this.updateUserMetaInfo(msg, userCopy);
|
|
60108
60191
|
userCopy.lastPointerActivity = Date.now();
|
|
60109
60192
|
userCopy.pointer = { x: eventData.position.x, y: eventData.position.y };
|
|
60110
|
-
this.users.set(
|
|
60193
|
+
this.users.set(sessionId, userCopy);
|
|
60111
60194
|
}
|
|
60112
60195
|
processSelection(msg) {
|
|
60113
|
-
const
|
|
60196
|
+
const sessionId = getPresenceSessionId(msg);
|
|
60197
|
+
const user = this.users.get(sessionId);
|
|
60114
60198
|
const eventData = msg.event;
|
|
60115
60199
|
const userCopy = { ...user };
|
|
60116
60200
|
this.updateUserMetaInfo(msg, userCopy);
|
|
60117
60201
|
userCopy.selection = eventData.selectedItems;
|
|
60118
|
-
this.users.set(
|
|
60202
|
+
this.users.set(sessionId, userCopy);
|
|
60119
60203
|
}
|
|
60120
60204
|
processSetColor(msg) {
|
|
60121
|
-
const
|
|
60205
|
+
const sessionId = getPresenceSessionId(msg);
|
|
60206
|
+
const user = this.users.get(sessionId);
|
|
60122
60207
|
const userCopy = { ...user };
|
|
60123
60208
|
userCopy.colorChangeable = false;
|
|
60124
60209
|
this.updateUserMetaInfo(msg, userCopy);
|
|
60125
|
-
this.users.set(
|
|
60210
|
+
this.users.set(sessionId, userCopy);
|
|
60126
60211
|
}
|
|
60127
|
-
enableTracking(
|
|
60128
|
-
const user = this.users.get(
|
|
60212
|
+
enableTracking(sessionId) {
|
|
60213
|
+
const user = this.users.get(sessionId);
|
|
60129
60214
|
if (!user) {
|
|
60130
60215
|
this.trackedUser = null;
|
|
60131
60216
|
} else {
|
|
@@ -60135,7 +60220,7 @@ class Presence {
|
|
|
60135
60220
|
}
|
|
60136
60221
|
this.emit({
|
|
60137
60222
|
method: "Follow",
|
|
60138
|
-
user:
|
|
60223
|
+
user: sessionId,
|
|
60139
60224
|
timestamp: Date.now()
|
|
60140
60225
|
});
|
|
60141
60226
|
}
|
|
@@ -60148,7 +60233,7 @@ class Presence {
|
|
|
60148
60233
|
this.emit({
|
|
60149
60234
|
method: "StopFollowing",
|
|
60150
60235
|
timestamp: Date.now(),
|
|
60151
|
-
users: [this.trackedUser
|
|
60236
|
+
users: [this.trackedUser.sessionId || this.trackedUser.userId]
|
|
60152
60237
|
});
|
|
60153
60238
|
this.trackedUser = null;
|
|
60154
60239
|
}
|
|
@@ -60167,18 +60252,12 @@ class Presence {
|
|
|
60167
60252
|
return this.cursorsEnabled;
|
|
60168
60253
|
}
|
|
60169
60254
|
getSelects() {
|
|
60170
|
-
const
|
|
60255
|
+
const selects = [];
|
|
60256
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
60171
60257
|
this.users.forEach((user) => {
|
|
60172
|
-
if (user.
|
|
60173
|
-
|
|
60174
|
-
const existingUser = uniqueUsers.get(key);
|
|
60175
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
60176
|
-
uniqueUsers.set(key, user);
|
|
60177
|
-
}
|
|
60258
|
+
if (currentSessionId && user.sessionId === currentSessionId) {
|
|
60259
|
+
return;
|
|
60178
60260
|
}
|
|
60179
|
-
});
|
|
60180
|
-
const selects = [];
|
|
60181
|
-
uniqueUsers.forEach((user) => {
|
|
60182
60261
|
if (user.select && Date.now() - user.lastActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
60183
60262
|
selects.push({
|
|
60184
60263
|
...user.select,
|
|
@@ -60192,42 +60271,29 @@ class Presence {
|
|
|
60192
60271
|
getCursors() {
|
|
60193
60272
|
const currentBoardId = this.board.getBoardId();
|
|
60194
60273
|
const now = Date.now();
|
|
60195
|
-
const
|
|
60274
|
+
const cursors = [];
|
|
60275
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
60196
60276
|
this.users.forEach((user) => {
|
|
60197
|
-
if (
|
|
60198
|
-
|
|
60199
|
-
|
|
60200
|
-
|
|
60201
|
-
|
|
60202
|
-
|
|
60277
|
+
if (currentSessionId !== user.sessionId && user.boardId === currentBoardId && now - user.lastPointerActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
60278
|
+
cursors.push({
|
|
60279
|
+
...user.pointer,
|
|
60280
|
+
userId: user.sessionId || user.userId,
|
|
60281
|
+
color: user.color,
|
|
60282
|
+
nickname: user.nickname
|
|
60283
|
+
});
|
|
60203
60284
|
}
|
|
60204
60285
|
});
|
|
60205
|
-
const cursors = [];
|
|
60206
|
-
uniqueUsers.forEach((user) => {
|
|
60207
|
-
cursors.push({
|
|
60208
|
-
...user.pointer,
|
|
60209
|
-
userId: user.userId,
|
|
60210
|
-
color: user.color,
|
|
60211
|
-
nickname: user.nickname
|
|
60212
|
-
});
|
|
60213
|
-
});
|
|
60214
60286
|
return cursors;
|
|
60215
60287
|
}
|
|
60216
60288
|
getSelections() {
|
|
60217
60289
|
const currentBoardId = this.board.getBoardId();
|
|
60218
60290
|
const now = Date.now();
|
|
60219
|
-
const
|
|
60291
|
+
const selections = [];
|
|
60292
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
60220
60293
|
this.users.forEach((user) => {
|
|
60221
|
-
if (
|
|
60222
|
-
|
|
60223
|
-
const existingUser = uniqueUsers.get(key);
|
|
60224
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
60225
|
-
uniqueUsers.set(key, user);
|
|
60226
|
-
}
|
|
60294
|
+
if (currentSessionId === user.sessionId || user.boardId !== currentBoardId || now - user.lastPointerActivity > CURSORS_IDLE_CLEANUP_DELAY) {
|
|
60295
|
+
return;
|
|
60227
60296
|
}
|
|
60228
|
-
});
|
|
60229
|
-
const selections = [];
|
|
60230
|
-
uniqueUsers.forEach((user) => {
|
|
60231
60297
|
if (Date.now() - user.lastActivity >= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
60232
60298
|
return;
|
|
60233
60299
|
}
|