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/node.js
CHANGED
|
@@ -5826,17 +5826,50 @@ function getRecordByIdFromList(id, list) {
|
|
|
5826
5826
|
return;
|
|
5827
5827
|
}
|
|
5828
5828
|
|
|
5829
|
+
// src/Events/identity.ts
|
|
5830
|
+
function getBoardEventSessionId(body) {
|
|
5831
|
+
if (body.sessionId) {
|
|
5832
|
+
return body.sessionId;
|
|
5833
|
+
}
|
|
5834
|
+
if (body.userId === undefined || body.userId === null) {
|
|
5835
|
+
return;
|
|
5836
|
+
}
|
|
5837
|
+
return String(body.userId);
|
|
5838
|
+
}
|
|
5839
|
+
function getConnectionSessionId(connection) {
|
|
5840
|
+
return connection?.getSessionId?.() || connection?.sessionId || String(connection?.connectionId || 0);
|
|
5841
|
+
}
|
|
5842
|
+
function getConnectionSessionIds(connection) {
|
|
5843
|
+
const ids = new Set;
|
|
5844
|
+
const primary = connection?.getSessionId?.() || connection?.sessionId;
|
|
5845
|
+
if (primary) {
|
|
5846
|
+
ids.add(primary);
|
|
5847
|
+
}
|
|
5848
|
+
if (connection?.connectionId !== undefined) {
|
|
5849
|
+
ids.add(String(connection.connectionId));
|
|
5850
|
+
}
|
|
5851
|
+
if (ids.size === 0) {
|
|
5852
|
+
ids.add("0");
|
|
5853
|
+
}
|
|
5854
|
+
return Array.from(ids);
|
|
5855
|
+
}
|
|
5856
|
+
function getConnectionAuthorUserId(connection) {
|
|
5857
|
+
return connection?.getAuthorUserId?.() || connection?.authorUserId || connection?.getCurrentUser?.();
|
|
5858
|
+
}
|
|
5859
|
+
|
|
5829
5860
|
// src/Events/Log/shouldSkipEvent.ts
|
|
5830
|
-
function shouldSkipEvent(record,
|
|
5861
|
+
function shouldSkipEvent(record, sessionIds) {
|
|
5831
5862
|
const { operation } = record.event.body;
|
|
5832
|
-
|
|
5863
|
+
const eventSessionId = getBoardEventSessionId(record.event.body);
|
|
5864
|
+
return eventSessionId === undefined || !sessionIds.includes(eventSessionId) || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
|
|
5833
5865
|
}
|
|
5866
|
+
var init_shouldSkipEvent = () => {};
|
|
5834
5867
|
|
|
5835
5868
|
// src/Events/Log/getRedoRecordFromList.ts
|
|
5836
|
-
function getRedoRecordFromList(
|
|
5869
|
+
function getRedoRecordFromList(sessionIds, list) {
|
|
5837
5870
|
let counter = 0;
|
|
5838
5871
|
for (const record of list.backwardIterable()) {
|
|
5839
|
-
if (shouldSkipEvent(record,
|
|
5872
|
+
if (shouldSkipEvent(record, sessionIds)) {
|
|
5840
5873
|
continue;
|
|
5841
5874
|
}
|
|
5842
5875
|
if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
|
|
@@ -5855,17 +5888,19 @@ function getRedoRecordFromList(userId, list) {
|
|
|
5855
5888
|
}
|
|
5856
5889
|
return null;
|
|
5857
5890
|
}
|
|
5858
|
-
var init_getRedoRecordFromList = () => {
|
|
5891
|
+
var init_getRedoRecordFromList = __esm(() => {
|
|
5892
|
+
init_shouldSkipEvent();
|
|
5893
|
+
});
|
|
5859
5894
|
|
|
5860
5895
|
// src/Events/Log/getUndoRecordFromList.ts
|
|
5861
|
-
function getUndoRecordFromList(
|
|
5896
|
+
function getUndoRecordFromList(sessionIds, list) {
|
|
5862
5897
|
let counter = 0;
|
|
5863
5898
|
const isAllEventsConfirmed = list.isAllEventsConfirmed();
|
|
5864
5899
|
if (!isAllEventsConfirmed) {
|
|
5865
5900
|
return null;
|
|
5866
5901
|
}
|
|
5867
5902
|
for (const record of list.getConfirmedRecords().slice().reverse()) {
|
|
5868
|
-
if (shouldSkipEvent(record,
|
|
5903
|
+
if (shouldSkipEvent(record, sessionIds)) {
|
|
5869
5904
|
continue;
|
|
5870
5905
|
}
|
|
5871
5906
|
if (record.event.body.operation.method === "undo") {
|
|
@@ -5878,7 +5913,9 @@ function getUndoRecordFromList(userId, list) {
|
|
|
5878
5913
|
}
|
|
5879
5914
|
return null;
|
|
5880
5915
|
}
|
|
5881
|
-
var init_getUndoRecordFromList = () => {
|
|
5916
|
+
var init_getUndoRecordFromList = __esm(() => {
|
|
5917
|
+
init_shouldSkipEvent();
|
|
5918
|
+
});
|
|
5882
5919
|
|
|
5883
5920
|
// src/Events/Log/getUnpublishedEventFromList.ts
|
|
5884
5921
|
function getUnpublishedEventFromList(list) {
|
|
@@ -5957,11 +5994,12 @@ function expandEvents(events) {
|
|
|
5957
5994
|
order: event.order,
|
|
5958
5995
|
body: {
|
|
5959
5996
|
eventId: operation.actualId || bodyWithoutOps.eventId,
|
|
5997
|
+
authorUserId: bodyWithoutOps.authorUserId,
|
|
5998
|
+
sessionId: bodyWithoutOps.sessionId,
|
|
5960
5999
|
userId: bodyWithoutOps.userId,
|
|
5961
6000
|
boardId: bodyWithoutOps.boardId,
|
|
5962
6001
|
operation
|
|
5963
6002
|
},
|
|
5964
|
-
userId: bodyWithoutOps.userId,
|
|
5965
6003
|
lastKnownOrder
|
|
5966
6004
|
}));
|
|
5967
6005
|
} else {
|
|
@@ -6080,7 +6118,6 @@ function deserializeAndApplyToList(events, list, board) {
|
|
|
6080
6118
|
const singleEvent = {
|
|
6081
6119
|
order: event.order,
|
|
6082
6120
|
lastKnownOrder,
|
|
6083
|
-
userId: bodyWithoutOps.userId,
|
|
6084
6121
|
body: {
|
|
6085
6122
|
...bodyWithoutOps,
|
|
6086
6123
|
operation: op
|
|
@@ -6167,11 +6204,11 @@ class EventsLog {
|
|
|
6167
6204
|
getUnorderedRecords() {
|
|
6168
6205
|
return this.list.getRecordsToSend().concat(this.list.getNewRecords());
|
|
6169
6206
|
}
|
|
6170
|
-
getUndoRecord(
|
|
6171
|
-
return getUndoRecordFromList(
|
|
6207
|
+
getUndoRecord(sessionIds) {
|
|
6208
|
+
return getUndoRecordFromList(sessionIds, this.list);
|
|
6172
6209
|
}
|
|
6173
|
-
getRedoRecord(
|
|
6174
|
-
return getRedoRecordFromList(
|
|
6210
|
+
getRedoRecord(sessionIds) {
|
|
6211
|
+
return getRedoRecordFromList(sessionIds, this.list);
|
|
6175
6212
|
}
|
|
6176
6213
|
getRecordById(id) {
|
|
6177
6214
|
return getRecordByIdFromList(id, this.list);
|
|
@@ -14205,10 +14242,13 @@ class Events {
|
|
|
14205
14242
|
console.error("[DEBUG] transformMany emitted from Events.emit!", JSON.stringify(operation));
|
|
14206
14243
|
console.trace("[DEBUG] transformMany stack trace");
|
|
14207
14244
|
}
|
|
14208
|
-
const
|
|
14245
|
+
const sessionId = this.getSessionId();
|
|
14246
|
+
const authorUserId = this.getAuthorUserId();
|
|
14209
14247
|
const body = {
|
|
14210
14248
|
eventId: this.getNextEventId(),
|
|
14211
|
-
userId,
|
|
14249
|
+
userId: sessionId,
|
|
14250
|
+
authorUserId,
|
|
14251
|
+
sessionId,
|
|
14212
14252
|
boardId: this.board.getBoardId(),
|
|
14213
14253
|
operation
|
|
14214
14254
|
};
|
|
@@ -14218,7 +14258,7 @@ class Events {
|
|
|
14218
14258
|
command: command || Events.createCommand(this.board, operation)
|
|
14219
14259
|
};
|
|
14220
14260
|
this.log.insertNewLocalEventRecordAfterEmit(record);
|
|
14221
|
-
this.setLatestUserEvent(operation,
|
|
14261
|
+
this.setLatestUserEvent(operation, sessionId);
|
|
14222
14262
|
this.subject.publish(event);
|
|
14223
14263
|
if (this.board.getBoardId().includes("local")) {
|
|
14224
14264
|
if (this.log.saveFileTimeout) {
|
|
@@ -14239,13 +14279,13 @@ class Events {
|
|
|
14239
14279
|
this.emit(operation, cmd);
|
|
14240
14280
|
}
|
|
14241
14281
|
undo() {
|
|
14242
|
-
const
|
|
14243
|
-
const record = this.log.getUndoRecord(
|
|
14282
|
+
const currentSessionIds = this.getSessionIds();
|
|
14283
|
+
const record = this.log.getUndoRecord(currentSessionIds);
|
|
14244
14284
|
if (!record) {
|
|
14245
14285
|
return;
|
|
14246
14286
|
}
|
|
14247
|
-
const { operation,
|
|
14248
|
-
const canUndo = this.canUndoEvent(operation,
|
|
14287
|
+
const { operation, eventId } = record.event.body;
|
|
14288
|
+
const canUndo = this.canUndoEvent(operation, getBoardEventSessionId(record.event.body));
|
|
14249
14289
|
if (!canUndo) {
|
|
14250
14290
|
return;
|
|
14251
14291
|
}
|
|
@@ -14256,8 +14296,8 @@ class Events {
|
|
|
14256
14296
|
});
|
|
14257
14297
|
}
|
|
14258
14298
|
redo() {
|
|
14259
|
-
const
|
|
14260
|
-
const record = this.log.getRedoRecord(
|
|
14299
|
+
const sessionIds = this.getSessionIds();
|
|
14300
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14261
14301
|
if (!record) {
|
|
14262
14302
|
return;
|
|
14263
14303
|
}
|
|
@@ -14268,22 +14308,22 @@ class Events {
|
|
|
14268
14308
|
});
|
|
14269
14309
|
}
|
|
14270
14310
|
canUndo() {
|
|
14271
|
-
const
|
|
14272
|
-
const record = this.log.getUndoRecord(
|
|
14311
|
+
const sessionIds = this.getSessionIds();
|
|
14312
|
+
const record = this.log.getUndoRecord(sessionIds);
|
|
14273
14313
|
if (!record) {
|
|
14274
14314
|
return false;
|
|
14275
14315
|
}
|
|
14276
|
-
return this.canUndoEvent(record.event.body.operation, record.event.body
|
|
14316
|
+
return this.canUndoEvent(record.event.body.operation, getBoardEventSessionId(record.event.body));
|
|
14277
14317
|
}
|
|
14278
14318
|
canRedo() {
|
|
14279
|
-
const
|
|
14280
|
-
const record = this.log.getRedoRecord(
|
|
14319
|
+
const sessionIds = this.getSessionIds();
|
|
14320
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14281
14321
|
return record !== null;
|
|
14282
14322
|
}
|
|
14283
14323
|
sendPresenceEvent(event) {
|
|
14284
14324
|
conf.connection.publishPresenceEvent(this.board.getBoardId(), event);
|
|
14285
14325
|
}
|
|
14286
|
-
canUndoEvent(op,
|
|
14326
|
+
canUndoEvent(op, bySessionId) {
|
|
14287
14327
|
if (op.method === "undo") {
|
|
14288
14328
|
return false;
|
|
14289
14329
|
}
|
|
@@ -14293,24 +14333,30 @@ class Events {
|
|
|
14293
14333
|
}
|
|
14294
14334
|
const key = this.getOpKey(op);
|
|
14295
14335
|
const latest = this.latestEvent[key];
|
|
14296
|
-
return
|
|
14336
|
+
return bySessionId === undefined || bySessionId === latest;
|
|
14297
14337
|
}
|
|
14298
|
-
setLatestUserEvent(op,
|
|
14338
|
+
setLatestUserEvent(op, sessionId) {
|
|
14299
14339
|
if (op.class !== "Events" && op.method !== "paste" && op.method !== "duplicate") {
|
|
14300
14340
|
const key = this.getOpKey(op);
|
|
14301
|
-
this.latestEvent[key] =
|
|
14341
|
+
this.latestEvent[key] = sessionId;
|
|
14302
14342
|
}
|
|
14303
14343
|
}
|
|
14304
14344
|
getOpKey(op) {
|
|
14305
14345
|
return op.method;
|
|
14306
14346
|
}
|
|
14307
|
-
|
|
14308
|
-
return this.connection
|
|
14347
|
+
getSessionId() {
|
|
14348
|
+
return getConnectionSessionId(this.connection);
|
|
14349
|
+
}
|
|
14350
|
+
getSessionIds() {
|
|
14351
|
+
return getConnectionSessionIds(this.connection);
|
|
14352
|
+
}
|
|
14353
|
+
getAuthorUserId() {
|
|
14354
|
+
return getConnectionAuthorUserId(this.connection);
|
|
14309
14355
|
}
|
|
14310
14356
|
getNextEventId() {
|
|
14311
14357
|
const id = ++this.eventCounter;
|
|
14312
|
-
const
|
|
14313
|
-
return
|
|
14358
|
+
const sessionId = this.getSessionId();
|
|
14359
|
+
return sessionId + ":" + id;
|
|
14314
14360
|
}
|
|
14315
14361
|
}
|
|
14316
14362
|
function createEvents(board, connection, lastIndex) {
|
|
@@ -53711,6 +53757,9 @@ function validateItemsMap(parsedObject) {
|
|
|
53711
53757
|
}
|
|
53712
53758
|
return true;
|
|
53713
53759
|
}
|
|
53760
|
+
function isColorValue(v) {
|
|
53761
|
+
return typeof v === "string" || typeof v === "object" && v !== null;
|
|
53762
|
+
}
|
|
53714
53763
|
function validateItemData(itemData) {
|
|
53715
53764
|
if (typeof itemData !== "object" || itemData === null || !("itemType" in itemData) || typeof itemData.itemType !== "string") {
|
|
53716
53765
|
return false;
|
|
@@ -53723,7 +53772,7 @@ function validateFrameData(data) {
|
|
|
53723
53772
|
return false;
|
|
53724
53773
|
}
|
|
53725
53774
|
const frameData = data;
|
|
53726
|
-
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" &&
|
|
53775
|
+
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);
|
|
53727
53776
|
return isValid;
|
|
53728
53777
|
}
|
|
53729
53778
|
function validateShapeData(shapeData) {
|
|
@@ -53731,7 +53780,7 @@ function validateShapeData(shapeData) {
|
|
|
53731
53780
|
return false;
|
|
53732
53781
|
}
|
|
53733
53782
|
const data = shapeData;
|
|
53734
|
-
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" &&
|
|
53783
|
+
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);
|
|
53735
53784
|
return isValid;
|
|
53736
53785
|
}
|
|
53737
53786
|
function validateStickerData(shapeData) {
|
|
@@ -53739,7 +53788,7 @@ function validateStickerData(shapeData) {
|
|
|
53739
53788
|
return false;
|
|
53740
53789
|
}
|
|
53741
53790
|
const data = shapeData;
|
|
53742
|
-
const isValid = data.hasOwnProperty("itemType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") &&
|
|
53791
|
+
const isValid = data.hasOwnProperty("itemType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") && isColorValue(data.backgroundColor) && validateTransformationData(data.transformation) && validateRichTextData(data.text);
|
|
53743
53792
|
return isValid;
|
|
53744
53793
|
}
|
|
53745
53794
|
function validateTransformationData(transformationData) {
|
|
@@ -53763,7 +53812,7 @@ function validateConnectorData(connectorData) {
|
|
|
53763
53812
|
return false;
|
|
53764
53813
|
}
|
|
53765
53814
|
const data = connectorData;
|
|
53766
|
-
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" &&
|
|
53815
|
+
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);
|
|
53767
53816
|
return isValid;
|
|
53768
53817
|
}
|
|
53769
53818
|
function validateChildren(children) {
|
|
@@ -57930,9 +57979,9 @@ function handleBoardEventMessage(message, board) {
|
|
|
57930
57979
|
if (event.order <= log.getLastIndex()) {
|
|
57931
57980
|
return;
|
|
57932
57981
|
}
|
|
57933
|
-
const
|
|
57934
|
-
const currentConnectionId = board.events.connection
|
|
57935
|
-
const isEventFromCurrentUser =
|
|
57982
|
+
const eventSessionId = getBoardEventSessionId(event.body);
|
|
57983
|
+
const currentConnectionId = getConnectionSessionId(board.events.connection);
|
|
57984
|
+
const isEventFromCurrentUser = eventSessionId !== undefined && eventSessionId === currentConnectionId;
|
|
57936
57985
|
if (isEventFromCurrentUser) {
|
|
57937
57986
|
return;
|
|
57938
57987
|
}
|
|
@@ -57946,6 +57995,7 @@ function handleBoardEventMessage(message, board) {
|
|
|
57946
57995
|
board.events.subject.publish(last);
|
|
57947
57996
|
}
|
|
57948
57997
|
}
|
|
57998
|
+
var init_handleBoardEventMessage = () => {};
|
|
57949
57999
|
|
|
57950
58000
|
// src/Events/MessageRouter/handleBoardSubscriptionCompletedMsg.ts
|
|
57951
58001
|
function handleBoardSubscriptionCompletedMsg(msg, board) {
|
|
@@ -58054,8 +58104,7 @@ function sendBoardEvent(board, batch, sequenceNumber) {
|
|
|
58054
58104
|
type: "BoardEvent",
|
|
58055
58105
|
boardId: board.getBoardId(),
|
|
58056
58106
|
event: toSend,
|
|
58057
|
-
sequenceNumber
|
|
58058
|
-
userId: conf.connection.getCurrentUser()
|
|
58107
|
+
sequenceNumber
|
|
58059
58108
|
});
|
|
58060
58109
|
const date = Date.now();
|
|
58061
58110
|
log.pendingEvent = {
|
|
@@ -58191,6 +58240,7 @@ function handleUserJoinMessage(message, board) {
|
|
|
58191
58240
|
var messageRouter;
|
|
58192
58241
|
var init_messageRouter = __esm(() => {
|
|
58193
58242
|
init_handleAiChatMassage();
|
|
58243
|
+
init_handleBoardEventMessage();
|
|
58194
58244
|
init_handleBoardSubscriptionCompletedMsg();
|
|
58195
58245
|
init_handleConfirmation();
|
|
58196
58246
|
init_handleCreateSnapshotRequestMessage();
|
|
@@ -59520,6 +59570,15 @@ var PRESENCE_CLEANUP_USER_TIMER = 180000;
|
|
|
59520
59570
|
var PRESENCE_CLEANUP_IDLE_TIMER = 60000;
|
|
59521
59571
|
var CURSORS_IDLE_CLEANUP_DELAY = 1e4;
|
|
59522
59572
|
var PING_CLEANUP = 15000;
|
|
59573
|
+
function getPresenceSessionId(message) {
|
|
59574
|
+
if (message.sessionId) {
|
|
59575
|
+
return message.sessionId;
|
|
59576
|
+
}
|
|
59577
|
+
if (message.userId === undefined || message.userId === null) {
|
|
59578
|
+
return;
|
|
59579
|
+
}
|
|
59580
|
+
return String(message.userId);
|
|
59581
|
+
}
|
|
59523
59582
|
var cleanupInterval = null;
|
|
59524
59583
|
|
|
59525
59584
|
class Presence {
|
|
@@ -59529,7 +59588,6 @@ class Presence {
|
|
|
59529
59588
|
trackedUser = null;
|
|
59530
59589
|
cursorsEnabled = true;
|
|
59531
59590
|
drawingContext = null;
|
|
59532
|
-
currentUserId = null;
|
|
59533
59591
|
users = new Map;
|
|
59534
59592
|
followers = [];
|
|
59535
59593
|
svgImageCache = {};
|
|
@@ -59555,7 +59613,7 @@ class Presence {
|
|
|
59555
59613
|
throttleSelectionEvent(this.board.selection);
|
|
59556
59614
|
});
|
|
59557
59615
|
if (typeof window !== "undefined") {
|
|
59558
|
-
window.addEventListener("storage", this.
|
|
59616
|
+
window.addEventListener("storage", this.onStorageChange);
|
|
59559
59617
|
}
|
|
59560
59618
|
}
|
|
59561
59619
|
clear() {
|
|
@@ -59594,19 +59652,30 @@ class Presence {
|
|
|
59594
59652
|
}
|
|
59595
59653
|
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));
|
|
59596
59654
|
}
|
|
59597
|
-
|
|
59598
|
-
|
|
59655
|
+
onStorageChange = (_event) => {};
|
|
59656
|
+
getCurrentSessionId() {
|
|
59657
|
+
return this.events?.connection?.getSessionId?.() || this.events?.connection?.sessionId || null;
|
|
59599
59658
|
}
|
|
59600
|
-
|
|
59601
|
-
if (
|
|
59602
|
-
|
|
59603
|
-
this.setCurrentUser(event.newValue);
|
|
59604
|
-
}
|
|
59659
|
+
getLegacyCurrentUserId() {
|
|
59660
|
+
if (typeof localStorage === "undefined") {
|
|
59661
|
+
return null;
|
|
59605
59662
|
}
|
|
59663
|
+
return localStorage.getItem("currentUser");
|
|
59664
|
+
}
|
|
59665
|
+
isCurrentSessionTarget(value) {
|
|
59666
|
+
if (value === undefined || value === null) {
|
|
59667
|
+
return false;
|
|
59668
|
+
}
|
|
59669
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
59670
|
+
if (currentSessionId && String(value) === currentSessionId) {
|
|
59671
|
+
return true;
|
|
59672
|
+
}
|
|
59673
|
+
const currentUser = this.getLegacyCurrentUserId();
|
|
59674
|
+
return currentUser !== null && String(value) === currentUser;
|
|
59606
59675
|
}
|
|
59607
59676
|
cleanup() {
|
|
59608
59677
|
if (typeof window !== "undefined") {
|
|
59609
|
-
window.removeEventListener("storage", this.
|
|
59678
|
+
window.removeEventListener("storage", this.onStorageChange);
|
|
59610
59679
|
}
|
|
59611
59680
|
this.drawingContext = null;
|
|
59612
59681
|
this.clear();
|
|
@@ -59646,24 +59715,25 @@ class Presence {
|
|
|
59646
59715
|
}
|
|
59647
59716
|
join(msg) {
|
|
59648
59717
|
Object.entries(msg.snapshots).map(([userId, snapshot]) => {
|
|
59649
|
-
|
|
59718
|
+
const sessionId = snapshot.sessionId || userId;
|
|
59719
|
+
this.users.set(sessionId, {
|
|
59720
|
+
...snapshot,
|
|
59721
|
+
userId: snapshot.userId || sessionId,
|
|
59722
|
+
sessionId,
|
|
59723
|
+
authorUserId: snapshot.authorUserId || null
|
|
59724
|
+
});
|
|
59650
59725
|
});
|
|
59651
59726
|
this.subject.publish(this);
|
|
59652
59727
|
}
|
|
59653
59728
|
getUsers(boardId, excludeSelf = false) {
|
|
59654
59729
|
let filteredUsers = Array.from(this.users.values()).filter((user) => user.boardId === boardId && (user.lastPing > Date.now() - PING_CLEANUP || user.lastActivity > Date.now() - PING_CLEANUP));
|
|
59655
59730
|
if (excludeSelf) {
|
|
59656
|
-
const
|
|
59657
|
-
if (
|
|
59658
|
-
filteredUsers = filteredUsers.filter((user) => user.
|
|
59731
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
59732
|
+
if (currentSessionId) {
|
|
59733
|
+
filteredUsers = filteredUsers.filter((user) => user.sessionId !== currentSessionId);
|
|
59659
59734
|
}
|
|
59660
59735
|
}
|
|
59661
|
-
|
|
59662
|
-
filteredUsers.forEach((user) => {
|
|
59663
|
-
const key = user.hardId === null ? Symbol() : user.hardId;
|
|
59664
|
-
uniqueUsers.set(key, user);
|
|
59665
|
-
});
|
|
59666
|
-
return Array.from(uniqueUsers.values());
|
|
59736
|
+
return filteredUsers;
|
|
59667
59737
|
}
|
|
59668
59738
|
getColors() {
|
|
59669
59739
|
return Array.from(this.users.values()).map((user) => user.color);
|
|
@@ -59672,8 +59742,12 @@ class Presence {
|
|
|
59672
59742
|
if (!this.drawingContext) {
|
|
59673
59743
|
return;
|
|
59674
59744
|
}
|
|
59675
|
-
const
|
|
59676
|
-
|
|
59745
|
+
const sessionId = getPresenceSessionId(event);
|
|
59746
|
+
if (!sessionId) {
|
|
59747
|
+
return;
|
|
59748
|
+
}
|
|
59749
|
+
const { event: eventData } = event;
|
|
59750
|
+
let user = this.users.get(sessionId);
|
|
59677
59751
|
if (!user) {
|
|
59678
59752
|
let color2 = null;
|
|
59679
59753
|
const storageColor = localStorage.getItem(`userColor`);
|
|
@@ -59684,8 +59758,10 @@ class Presence {
|
|
|
59684
59758
|
} else {
|
|
59685
59759
|
color2 = this.generateUserColor();
|
|
59686
59760
|
}
|
|
59687
|
-
this.users.set(
|
|
59688
|
-
userId:
|
|
59761
|
+
this.users.set(sessionId, {
|
|
59762
|
+
userId: sessionId,
|
|
59763
|
+
sessionId,
|
|
59764
|
+
authorUserId: event.authorUserId || null,
|
|
59689
59765
|
softId: event.softId,
|
|
59690
59766
|
hardId: event.hardId,
|
|
59691
59767
|
color: color2,
|
|
@@ -59700,7 +59776,7 @@ class Presence {
|
|
|
59700
59776
|
boardId: this.board.getBoardId(),
|
|
59701
59777
|
lastPointerActivity: eventData.timestamp
|
|
59702
59778
|
});
|
|
59703
|
-
user = this.users.get(
|
|
59779
|
+
user = this.users.get(sessionId);
|
|
59704
59780
|
}
|
|
59705
59781
|
switch (eventData.method) {
|
|
59706
59782
|
case "PointerMove":
|
|
@@ -59743,6 +59819,9 @@ class Presence {
|
|
|
59743
59819
|
if (msg.color) {
|
|
59744
59820
|
userCopy.color = msg.color;
|
|
59745
59821
|
}
|
|
59822
|
+
if (msg.authorUserId) {
|
|
59823
|
+
userCopy.authorUserId = msg.authorUserId;
|
|
59824
|
+
}
|
|
59746
59825
|
userCopy.nickname = msg.nickname;
|
|
59747
59826
|
userCopy.boardId = msg.boardId;
|
|
59748
59827
|
if (shouldUpdateActivity) {
|
|
@@ -59750,107 +59829,113 @@ class Presence {
|
|
|
59750
59829
|
}
|
|
59751
59830
|
}
|
|
59752
59831
|
processFollowEvent(msg) {
|
|
59753
|
-
|
|
59754
|
-
|
|
59755
|
-
|
|
59756
|
-
|
|
59757
|
-
|
|
59758
|
-
this.followers.push(
|
|
59832
|
+
if (this.isCurrentSessionTarget(msg.event.user)) {
|
|
59833
|
+
const sessionId = getPresenceSessionId(msg);
|
|
59834
|
+
if (!sessionId) {
|
|
59835
|
+
return;
|
|
59836
|
+
}
|
|
59837
|
+
this.followers.push(sessionId);
|
|
59759
59838
|
this.followers = Array.from(new Set(this.followers));
|
|
59760
59839
|
}
|
|
59761
59840
|
}
|
|
59762
59841
|
processBringToMe(msg) {
|
|
59763
|
-
|
|
59764
|
-
|
|
59765
|
-
|
|
59766
|
-
|
|
59767
|
-
|
|
59768
|
-
const bringerId = msg.userId.toString();
|
|
59842
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
59843
|
+
const bringerId = getPresenceSessionId(msg);
|
|
59844
|
+
if (!bringerId) {
|
|
59845
|
+
return;
|
|
59846
|
+
}
|
|
59769
59847
|
const userToTrack = this.users.get(bringerId);
|
|
59770
59848
|
if (userToTrack) {
|
|
59771
59849
|
this.trackedUser = userToTrack;
|
|
59772
|
-
this.enableTracking(userToTrack.userId);
|
|
59850
|
+
this.enableTracking(userToTrack.sessionId || userToTrack.userId);
|
|
59773
59851
|
}
|
|
59774
59852
|
}
|
|
59775
59853
|
}
|
|
59776
59854
|
processStopFollowing(msg) {
|
|
59777
|
-
const
|
|
59778
|
-
if (!
|
|
59855
|
+
const sessionId = getPresenceSessionId(msg);
|
|
59856
|
+
if (!sessionId) {
|
|
59779
59857
|
return;
|
|
59780
59858
|
}
|
|
59781
|
-
if (msg.event.users.
|
|
59782
|
-
this.followers = this.followers.filter((follower) => follower !==
|
|
59859
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
59860
|
+
this.followers = this.followers.filter((follower) => follower !== sessionId);
|
|
59783
59861
|
}
|
|
59784
59862
|
if (!this.trackedUser) {
|
|
59785
59863
|
return;
|
|
59786
59864
|
}
|
|
59787
|
-
if (this.trackedUser.
|
|
59865
|
+
if (this.trackedUser.sessionId !== sessionId) {
|
|
59788
59866
|
return;
|
|
59789
59867
|
}
|
|
59790
|
-
if (msg.event.users.
|
|
59868
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
59791
59869
|
this.disableTracking();
|
|
59792
59870
|
}
|
|
59793
59871
|
}
|
|
59794
59872
|
processPing(msg) {
|
|
59795
|
-
const
|
|
59873
|
+
const sessionId = getPresenceSessionId(msg);
|
|
59874
|
+
const user = this.users.get(sessionId);
|
|
59796
59875
|
user.lastPing = msg.event.timestamp;
|
|
59797
59876
|
const userCopy = { ...user };
|
|
59798
59877
|
this.updateUserMetaInfo(msg, userCopy, false);
|
|
59799
|
-
this.users.set(
|
|
59878
|
+
this.users.set(sessionId, userCopy);
|
|
59800
59879
|
}
|
|
59801
59880
|
processCameraEvent(msg) {
|
|
59802
|
-
const
|
|
59881
|
+
const sessionId = getPresenceSessionId(msg);
|
|
59882
|
+
const user = this.users.get(sessionId);
|
|
59803
59883
|
const eventData = msg.event;
|
|
59804
59884
|
const userCopy = { ...user };
|
|
59805
59885
|
userCopy.camera = eventData;
|
|
59806
59886
|
this.updateUserMetaInfo(msg, userCopy);
|
|
59807
|
-
this.users.set(
|
|
59808
|
-
if (this.trackedUser && this.trackedUser.
|
|
59887
|
+
this.users.set(sessionId, userCopy);
|
|
59888
|
+
if (this.trackedUser && this.trackedUser.sessionId === sessionId) {
|
|
59809
59889
|
this.trackedUser.camera = eventData;
|
|
59810
59890
|
this.board.camera.animateToMatrix(new Matrix(eventData.translateX, eventData.translateY, eventData.scaleX, eventData.scaleY, eventData.shearX, eventData.shearY));
|
|
59811
59891
|
}
|
|
59812
59892
|
}
|
|
59813
59893
|
processDrawSelect(msg) {
|
|
59814
|
-
const
|
|
59894
|
+
const sessionId = getPresenceSessionId(msg);
|
|
59895
|
+
const user = this.users.get(sessionId);
|
|
59815
59896
|
const eventData = msg.event;
|
|
59816
59897
|
const userCopy = { ...user };
|
|
59817
59898
|
this.updateUserMetaInfo(msg, userCopy);
|
|
59818
59899
|
userCopy.select = eventData.size;
|
|
59819
|
-
this.users.set(
|
|
59900
|
+
this.users.set(sessionId, userCopy);
|
|
59820
59901
|
}
|
|
59821
59902
|
processCancelDrawSelect(msg) {
|
|
59822
|
-
const
|
|
59903
|
+
const sessionId = getPresenceSessionId(msg);
|
|
59904
|
+
const user = this.users.get(sessionId);
|
|
59823
59905
|
const userCopy = { ...user };
|
|
59824
59906
|
this.updateUserMetaInfo(msg, userCopy);
|
|
59825
59907
|
userCopy.select = undefined;
|
|
59826
|
-
this.users.set(
|
|
59908
|
+
this.users.set(sessionId, userCopy);
|
|
59827
59909
|
}
|
|
59828
59910
|
processPointerMove(msg) {
|
|
59829
|
-
const
|
|
59911
|
+
const sessionId = getPresenceSessionId(msg);
|
|
59912
|
+
const user = this.users.get(sessionId);
|
|
59830
59913
|
const eventData = msg.event;
|
|
59831
59914
|
const userCopy = { ...user };
|
|
59832
59915
|
this.updateUserMetaInfo(msg, userCopy);
|
|
59833
59916
|
userCopy.lastPointerActivity = Date.now();
|
|
59834
59917
|
userCopy.pointer = { x: eventData.position.x, y: eventData.position.y };
|
|
59835
|
-
this.users.set(
|
|
59918
|
+
this.users.set(sessionId, userCopy);
|
|
59836
59919
|
}
|
|
59837
59920
|
processSelection(msg) {
|
|
59838
|
-
const
|
|
59921
|
+
const sessionId = getPresenceSessionId(msg);
|
|
59922
|
+
const user = this.users.get(sessionId);
|
|
59839
59923
|
const eventData = msg.event;
|
|
59840
59924
|
const userCopy = { ...user };
|
|
59841
59925
|
this.updateUserMetaInfo(msg, userCopy);
|
|
59842
59926
|
userCopy.selection = eventData.selectedItems;
|
|
59843
|
-
this.users.set(
|
|
59927
|
+
this.users.set(sessionId, userCopy);
|
|
59844
59928
|
}
|
|
59845
59929
|
processSetColor(msg) {
|
|
59846
|
-
const
|
|
59930
|
+
const sessionId = getPresenceSessionId(msg);
|
|
59931
|
+
const user = this.users.get(sessionId);
|
|
59847
59932
|
const userCopy = { ...user };
|
|
59848
59933
|
userCopy.colorChangeable = false;
|
|
59849
59934
|
this.updateUserMetaInfo(msg, userCopy);
|
|
59850
|
-
this.users.set(
|
|
59935
|
+
this.users.set(sessionId, userCopy);
|
|
59851
59936
|
}
|
|
59852
|
-
enableTracking(
|
|
59853
|
-
const user = this.users.get(
|
|
59937
|
+
enableTracking(sessionId) {
|
|
59938
|
+
const user = this.users.get(sessionId);
|
|
59854
59939
|
if (!user) {
|
|
59855
59940
|
this.trackedUser = null;
|
|
59856
59941
|
} else {
|
|
@@ -59860,7 +59945,7 @@ class Presence {
|
|
|
59860
59945
|
}
|
|
59861
59946
|
this.emit({
|
|
59862
59947
|
method: "Follow",
|
|
59863
|
-
user:
|
|
59948
|
+
user: sessionId,
|
|
59864
59949
|
timestamp: Date.now()
|
|
59865
59950
|
});
|
|
59866
59951
|
}
|
|
@@ -59873,7 +59958,7 @@ class Presence {
|
|
|
59873
59958
|
this.emit({
|
|
59874
59959
|
method: "StopFollowing",
|
|
59875
59960
|
timestamp: Date.now(),
|
|
59876
|
-
users: [this.trackedUser
|
|
59961
|
+
users: [this.trackedUser.sessionId || this.trackedUser.userId]
|
|
59877
59962
|
});
|
|
59878
59963
|
this.trackedUser = null;
|
|
59879
59964
|
}
|
|
@@ -59892,18 +59977,12 @@ class Presence {
|
|
|
59892
59977
|
return this.cursorsEnabled;
|
|
59893
59978
|
}
|
|
59894
59979
|
getSelects() {
|
|
59895
|
-
const
|
|
59980
|
+
const selects = [];
|
|
59981
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
59896
59982
|
this.users.forEach((user) => {
|
|
59897
|
-
if (user.
|
|
59898
|
-
|
|
59899
|
-
const existingUser = uniqueUsers.get(key);
|
|
59900
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
59901
|
-
uniqueUsers.set(key, user);
|
|
59902
|
-
}
|
|
59983
|
+
if (currentSessionId && user.sessionId === currentSessionId) {
|
|
59984
|
+
return;
|
|
59903
59985
|
}
|
|
59904
|
-
});
|
|
59905
|
-
const selects = [];
|
|
59906
|
-
uniqueUsers.forEach((user) => {
|
|
59907
59986
|
if (user.select && Date.now() - user.lastActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
59908
59987
|
selects.push({
|
|
59909
59988
|
...user.select,
|
|
@@ -59917,42 +59996,29 @@ class Presence {
|
|
|
59917
59996
|
getCursors() {
|
|
59918
59997
|
const currentBoardId = this.board.getBoardId();
|
|
59919
59998
|
const now = Date.now();
|
|
59920
|
-
const
|
|
59999
|
+
const cursors = [];
|
|
60000
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
59921
60001
|
this.users.forEach((user) => {
|
|
59922
|
-
if (
|
|
59923
|
-
|
|
59924
|
-
|
|
59925
|
-
|
|
59926
|
-
|
|
59927
|
-
|
|
60002
|
+
if (currentSessionId !== user.sessionId && user.boardId === currentBoardId && now - user.lastPointerActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
60003
|
+
cursors.push({
|
|
60004
|
+
...user.pointer,
|
|
60005
|
+
userId: user.sessionId || user.userId,
|
|
60006
|
+
color: user.color,
|
|
60007
|
+
nickname: user.nickname
|
|
60008
|
+
});
|
|
59928
60009
|
}
|
|
59929
60010
|
});
|
|
59930
|
-
const cursors = [];
|
|
59931
|
-
uniqueUsers.forEach((user) => {
|
|
59932
|
-
cursors.push({
|
|
59933
|
-
...user.pointer,
|
|
59934
|
-
userId: user.userId,
|
|
59935
|
-
color: user.color,
|
|
59936
|
-
nickname: user.nickname
|
|
59937
|
-
});
|
|
59938
|
-
});
|
|
59939
60011
|
return cursors;
|
|
59940
60012
|
}
|
|
59941
60013
|
getSelections() {
|
|
59942
60014
|
const currentBoardId = this.board.getBoardId();
|
|
59943
60015
|
const now = Date.now();
|
|
59944
|
-
const
|
|
60016
|
+
const selections = [];
|
|
60017
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
59945
60018
|
this.users.forEach((user) => {
|
|
59946
|
-
if (
|
|
59947
|
-
|
|
59948
|
-
const existingUser = uniqueUsers.get(key);
|
|
59949
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
59950
|
-
uniqueUsers.set(key, user);
|
|
59951
|
-
}
|
|
60019
|
+
if (currentSessionId === user.sessionId || user.boardId !== currentBoardId || now - user.lastPointerActivity > CURSORS_IDLE_CLEANUP_DELAY) {
|
|
60020
|
+
return;
|
|
59952
60021
|
}
|
|
59953
|
-
});
|
|
59954
|
-
const selections = [];
|
|
59955
|
-
uniqueUsers.forEach((user) => {
|
|
59956
60022
|
if (Date.now() - user.lastActivity >= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
59957
60023
|
return;
|
|
59958
60024
|
}
|