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/index.js
CHANGED
|
@@ -5824,17 +5824,50 @@ function getRecordByIdFromList(id, list) {
|
|
|
5824
5824
|
return;
|
|
5825
5825
|
}
|
|
5826
5826
|
|
|
5827
|
+
// src/Events/identity.ts
|
|
5828
|
+
function getBoardEventSessionId(body) {
|
|
5829
|
+
if (body.sessionId) {
|
|
5830
|
+
return body.sessionId;
|
|
5831
|
+
}
|
|
5832
|
+
if (body.userId === undefined || body.userId === null) {
|
|
5833
|
+
return;
|
|
5834
|
+
}
|
|
5835
|
+
return String(body.userId);
|
|
5836
|
+
}
|
|
5837
|
+
function getConnectionSessionId(connection) {
|
|
5838
|
+
return connection?.getSessionId?.() || connection?.sessionId || String(connection?.connectionId || 0);
|
|
5839
|
+
}
|
|
5840
|
+
function getConnectionSessionIds(connection) {
|
|
5841
|
+
const ids = new Set;
|
|
5842
|
+
const primary = connection?.getSessionId?.() || connection?.sessionId;
|
|
5843
|
+
if (primary) {
|
|
5844
|
+
ids.add(primary);
|
|
5845
|
+
}
|
|
5846
|
+
if (connection?.connectionId !== undefined) {
|
|
5847
|
+
ids.add(String(connection.connectionId));
|
|
5848
|
+
}
|
|
5849
|
+
if (ids.size === 0) {
|
|
5850
|
+
ids.add("0");
|
|
5851
|
+
}
|
|
5852
|
+
return Array.from(ids);
|
|
5853
|
+
}
|
|
5854
|
+
function getConnectionAuthorUserId(connection) {
|
|
5855
|
+
return connection?.getAuthorUserId?.() || connection?.authorUserId || connection?.getCurrentUser?.();
|
|
5856
|
+
}
|
|
5857
|
+
|
|
5827
5858
|
// src/Events/Log/shouldSkipEvent.ts
|
|
5828
|
-
function shouldSkipEvent(record,
|
|
5859
|
+
function shouldSkipEvent(record, sessionIds) {
|
|
5829
5860
|
const { operation } = record.event.body;
|
|
5830
|
-
|
|
5861
|
+
const eventSessionId = getBoardEventSessionId(record.event.body);
|
|
5862
|
+
return eventSessionId === undefined || !sessionIds.includes(eventSessionId) || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
|
|
5831
5863
|
}
|
|
5864
|
+
var init_shouldSkipEvent = () => {};
|
|
5832
5865
|
|
|
5833
5866
|
// src/Events/Log/getRedoRecordFromList.ts
|
|
5834
|
-
function getRedoRecordFromList(
|
|
5867
|
+
function getRedoRecordFromList(sessionIds, list) {
|
|
5835
5868
|
let counter = 0;
|
|
5836
5869
|
for (const record of list.backwardIterable()) {
|
|
5837
|
-
if (shouldSkipEvent(record,
|
|
5870
|
+
if (shouldSkipEvent(record, sessionIds)) {
|
|
5838
5871
|
continue;
|
|
5839
5872
|
}
|
|
5840
5873
|
if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
|
|
@@ -5853,17 +5886,19 @@ function getRedoRecordFromList(userId, list) {
|
|
|
5853
5886
|
}
|
|
5854
5887
|
return null;
|
|
5855
5888
|
}
|
|
5856
|
-
var init_getRedoRecordFromList = () => {
|
|
5889
|
+
var init_getRedoRecordFromList = __esm(() => {
|
|
5890
|
+
init_shouldSkipEvent();
|
|
5891
|
+
});
|
|
5857
5892
|
|
|
5858
5893
|
// src/Events/Log/getUndoRecordFromList.ts
|
|
5859
|
-
function getUndoRecordFromList(
|
|
5894
|
+
function getUndoRecordFromList(sessionIds, list) {
|
|
5860
5895
|
let counter = 0;
|
|
5861
5896
|
const isAllEventsConfirmed = list.isAllEventsConfirmed();
|
|
5862
5897
|
if (!isAllEventsConfirmed) {
|
|
5863
5898
|
return null;
|
|
5864
5899
|
}
|
|
5865
5900
|
for (const record of list.getConfirmedRecords().slice().reverse()) {
|
|
5866
|
-
if (shouldSkipEvent(record,
|
|
5901
|
+
if (shouldSkipEvent(record, sessionIds)) {
|
|
5867
5902
|
continue;
|
|
5868
5903
|
}
|
|
5869
5904
|
if (record.event.body.operation.method === "undo") {
|
|
@@ -5876,7 +5911,9 @@ function getUndoRecordFromList(userId, list) {
|
|
|
5876
5911
|
}
|
|
5877
5912
|
return null;
|
|
5878
5913
|
}
|
|
5879
|
-
var init_getUndoRecordFromList = () => {
|
|
5914
|
+
var init_getUndoRecordFromList = __esm(() => {
|
|
5915
|
+
init_shouldSkipEvent();
|
|
5916
|
+
});
|
|
5880
5917
|
|
|
5881
5918
|
// src/Events/Log/getUnpublishedEventFromList.ts
|
|
5882
5919
|
function getUnpublishedEventFromList(list) {
|
|
@@ -5955,11 +5992,12 @@ function expandEvents(events) {
|
|
|
5955
5992
|
order: event.order,
|
|
5956
5993
|
body: {
|
|
5957
5994
|
eventId: operation.actualId || bodyWithoutOps.eventId,
|
|
5995
|
+
authorUserId: bodyWithoutOps.authorUserId,
|
|
5996
|
+
sessionId: bodyWithoutOps.sessionId,
|
|
5958
5997
|
userId: bodyWithoutOps.userId,
|
|
5959
5998
|
boardId: bodyWithoutOps.boardId,
|
|
5960
5999
|
operation
|
|
5961
6000
|
},
|
|
5962
|
-
userId: bodyWithoutOps.userId,
|
|
5963
6001
|
lastKnownOrder
|
|
5964
6002
|
}));
|
|
5965
6003
|
} else {
|
|
@@ -6078,7 +6116,6 @@ function deserializeAndApplyToList(events, list, board) {
|
|
|
6078
6116
|
const singleEvent = {
|
|
6079
6117
|
order: event.order,
|
|
6080
6118
|
lastKnownOrder,
|
|
6081
|
-
userId: bodyWithoutOps.userId,
|
|
6082
6119
|
body: {
|
|
6083
6120
|
...bodyWithoutOps,
|
|
6084
6121
|
operation: op
|
|
@@ -6165,11 +6202,11 @@ class EventsLog {
|
|
|
6165
6202
|
getUnorderedRecords() {
|
|
6166
6203
|
return this.list.getRecordsToSend().concat(this.list.getNewRecords());
|
|
6167
6204
|
}
|
|
6168
|
-
getUndoRecord(
|
|
6169
|
-
return getUndoRecordFromList(
|
|
6205
|
+
getUndoRecord(sessionIds) {
|
|
6206
|
+
return getUndoRecordFromList(sessionIds, this.list);
|
|
6170
6207
|
}
|
|
6171
|
-
getRedoRecord(
|
|
6172
|
-
return getRedoRecordFromList(
|
|
6208
|
+
getRedoRecord(sessionIds) {
|
|
6209
|
+
return getRedoRecordFromList(sessionIds, this.list);
|
|
6173
6210
|
}
|
|
6174
6211
|
getRecordById(id) {
|
|
6175
6212
|
return getRecordByIdFromList(id, this.list);
|
|
@@ -14183,10 +14220,13 @@ class Events {
|
|
|
14183
14220
|
console.error("[DEBUG] transformMany emitted from Events.emit!", JSON.stringify(operation));
|
|
14184
14221
|
console.trace("[DEBUG] transformMany stack trace");
|
|
14185
14222
|
}
|
|
14186
|
-
const
|
|
14223
|
+
const sessionId = this.getSessionId();
|
|
14224
|
+
const authorUserId = this.getAuthorUserId();
|
|
14187
14225
|
const body = {
|
|
14188
14226
|
eventId: this.getNextEventId(),
|
|
14189
|
-
userId,
|
|
14227
|
+
userId: sessionId,
|
|
14228
|
+
authorUserId,
|
|
14229
|
+
sessionId,
|
|
14190
14230
|
boardId: this.board.getBoardId(),
|
|
14191
14231
|
operation
|
|
14192
14232
|
};
|
|
@@ -14196,7 +14236,7 @@ class Events {
|
|
|
14196
14236
|
command: command || Events.createCommand(this.board, operation)
|
|
14197
14237
|
};
|
|
14198
14238
|
this.log.insertNewLocalEventRecordAfterEmit(record);
|
|
14199
|
-
this.setLatestUserEvent(operation,
|
|
14239
|
+
this.setLatestUserEvent(operation, sessionId);
|
|
14200
14240
|
this.subject.publish(event);
|
|
14201
14241
|
if (this.board.getBoardId().includes("local")) {
|
|
14202
14242
|
if (this.log.saveFileTimeout) {
|
|
@@ -14217,13 +14257,13 @@ class Events {
|
|
|
14217
14257
|
this.emit(operation, cmd);
|
|
14218
14258
|
}
|
|
14219
14259
|
undo() {
|
|
14220
|
-
const
|
|
14221
|
-
const record = this.log.getUndoRecord(
|
|
14260
|
+
const currentSessionIds = this.getSessionIds();
|
|
14261
|
+
const record = this.log.getUndoRecord(currentSessionIds);
|
|
14222
14262
|
if (!record) {
|
|
14223
14263
|
return;
|
|
14224
14264
|
}
|
|
14225
|
-
const { operation,
|
|
14226
|
-
const canUndo = this.canUndoEvent(operation,
|
|
14265
|
+
const { operation, eventId } = record.event.body;
|
|
14266
|
+
const canUndo = this.canUndoEvent(operation, getBoardEventSessionId(record.event.body));
|
|
14227
14267
|
if (!canUndo) {
|
|
14228
14268
|
return;
|
|
14229
14269
|
}
|
|
@@ -14234,8 +14274,8 @@ class Events {
|
|
|
14234
14274
|
});
|
|
14235
14275
|
}
|
|
14236
14276
|
redo() {
|
|
14237
|
-
const
|
|
14238
|
-
const record = this.log.getRedoRecord(
|
|
14277
|
+
const sessionIds = this.getSessionIds();
|
|
14278
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14239
14279
|
if (!record) {
|
|
14240
14280
|
return;
|
|
14241
14281
|
}
|
|
@@ -14246,22 +14286,22 @@ class Events {
|
|
|
14246
14286
|
});
|
|
14247
14287
|
}
|
|
14248
14288
|
canUndo() {
|
|
14249
|
-
const
|
|
14250
|
-
const record = this.log.getUndoRecord(
|
|
14289
|
+
const sessionIds = this.getSessionIds();
|
|
14290
|
+
const record = this.log.getUndoRecord(sessionIds);
|
|
14251
14291
|
if (!record) {
|
|
14252
14292
|
return false;
|
|
14253
14293
|
}
|
|
14254
|
-
return this.canUndoEvent(record.event.body.operation, record.event.body
|
|
14294
|
+
return this.canUndoEvent(record.event.body.operation, getBoardEventSessionId(record.event.body));
|
|
14255
14295
|
}
|
|
14256
14296
|
canRedo() {
|
|
14257
|
-
const
|
|
14258
|
-
const record = this.log.getRedoRecord(
|
|
14297
|
+
const sessionIds = this.getSessionIds();
|
|
14298
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14259
14299
|
return record !== null;
|
|
14260
14300
|
}
|
|
14261
14301
|
sendPresenceEvent(event) {
|
|
14262
14302
|
conf.connection.publishPresenceEvent(this.board.getBoardId(), event);
|
|
14263
14303
|
}
|
|
14264
|
-
canUndoEvent(op,
|
|
14304
|
+
canUndoEvent(op, bySessionId) {
|
|
14265
14305
|
if (op.method === "undo") {
|
|
14266
14306
|
return false;
|
|
14267
14307
|
}
|
|
@@ -14271,24 +14311,30 @@ class Events {
|
|
|
14271
14311
|
}
|
|
14272
14312
|
const key = this.getOpKey(op);
|
|
14273
14313
|
const latest = this.latestEvent[key];
|
|
14274
|
-
return
|
|
14314
|
+
return bySessionId === undefined || bySessionId === latest;
|
|
14275
14315
|
}
|
|
14276
|
-
setLatestUserEvent(op,
|
|
14316
|
+
setLatestUserEvent(op, sessionId) {
|
|
14277
14317
|
if (op.class !== "Events" && op.method !== "paste" && op.method !== "duplicate") {
|
|
14278
14318
|
const key = this.getOpKey(op);
|
|
14279
|
-
this.latestEvent[key] =
|
|
14319
|
+
this.latestEvent[key] = sessionId;
|
|
14280
14320
|
}
|
|
14281
14321
|
}
|
|
14282
14322
|
getOpKey(op) {
|
|
14283
14323
|
return op.method;
|
|
14284
14324
|
}
|
|
14285
|
-
|
|
14286
|
-
return this.connection
|
|
14325
|
+
getSessionId() {
|
|
14326
|
+
return getConnectionSessionId(this.connection);
|
|
14327
|
+
}
|
|
14328
|
+
getSessionIds() {
|
|
14329
|
+
return getConnectionSessionIds(this.connection);
|
|
14330
|
+
}
|
|
14331
|
+
getAuthorUserId() {
|
|
14332
|
+
return getConnectionAuthorUserId(this.connection);
|
|
14287
14333
|
}
|
|
14288
14334
|
getNextEventId() {
|
|
14289
14335
|
const id = ++this.eventCounter;
|
|
14290
|
-
const
|
|
14291
|
-
return
|
|
14336
|
+
const sessionId = this.getSessionId();
|
|
14337
|
+
return sessionId + ":" + id;
|
|
14292
14338
|
}
|
|
14293
14339
|
}
|
|
14294
14340
|
function createEvents(board, connection, lastIndex) {
|
|
@@ -51302,6 +51348,9 @@ function validateItemsMap(parsedObject) {
|
|
|
51302
51348
|
}
|
|
51303
51349
|
return true;
|
|
51304
51350
|
}
|
|
51351
|
+
function isColorValue(v) {
|
|
51352
|
+
return typeof v === "string" || typeof v === "object" && v !== null;
|
|
51353
|
+
}
|
|
51305
51354
|
function validateItemData(itemData) {
|
|
51306
51355
|
if (typeof itemData !== "object" || itemData === null || !("itemType" in itemData) || typeof itemData.itemType !== "string") {
|
|
51307
51356
|
return false;
|
|
@@ -51314,7 +51363,7 @@ function validateFrameData(data) {
|
|
|
51314
51363
|
return false;
|
|
51315
51364
|
}
|
|
51316
51365
|
const frameData = data;
|
|
51317
|
-
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" &&
|
|
51366
|
+
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);
|
|
51318
51367
|
return isValid;
|
|
51319
51368
|
}
|
|
51320
51369
|
function validateShapeData(shapeData) {
|
|
@@ -51322,7 +51371,7 @@ function validateShapeData(shapeData) {
|
|
|
51322
51371
|
return false;
|
|
51323
51372
|
}
|
|
51324
51373
|
const data = shapeData;
|
|
51325
|
-
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" &&
|
|
51374
|
+
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);
|
|
51326
51375
|
return isValid;
|
|
51327
51376
|
}
|
|
51328
51377
|
function validateStickerData(shapeData) {
|
|
@@ -51330,7 +51379,7 @@ function validateStickerData(shapeData) {
|
|
|
51330
51379
|
return false;
|
|
51331
51380
|
}
|
|
51332
51381
|
const data = shapeData;
|
|
51333
|
-
const isValid = data.hasOwnProperty("itemType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") &&
|
|
51382
|
+
const isValid = data.hasOwnProperty("itemType") && data.hasOwnProperty("backgroundColor") && data.hasOwnProperty("transformation") && data.hasOwnProperty("text") && isColorValue(data.backgroundColor) && validateTransformationData(data.transformation) && validateRichTextData(data.text);
|
|
51334
51383
|
return isValid;
|
|
51335
51384
|
}
|
|
51336
51385
|
function validateTransformationData(transformationData) {
|
|
@@ -51354,7 +51403,7 @@ function validateConnectorData(connectorData) {
|
|
|
51354
51403
|
return false;
|
|
51355
51404
|
}
|
|
51356
51405
|
const data = connectorData;
|
|
51357
|
-
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" &&
|
|
51406
|
+
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);
|
|
51358
51407
|
return isValid;
|
|
51359
51408
|
}
|
|
51360
51409
|
function validateChildren(children) {
|
|
@@ -55521,9 +55570,9 @@ function handleBoardEventMessage(message, board) {
|
|
|
55521
55570
|
if (event.order <= log.getLastIndex()) {
|
|
55522
55571
|
return;
|
|
55523
55572
|
}
|
|
55524
|
-
const
|
|
55525
|
-
const currentConnectionId = board.events.connection
|
|
55526
|
-
const isEventFromCurrentUser =
|
|
55573
|
+
const eventSessionId = getBoardEventSessionId(event.body);
|
|
55574
|
+
const currentConnectionId = getConnectionSessionId(board.events.connection);
|
|
55575
|
+
const isEventFromCurrentUser = eventSessionId !== undefined && eventSessionId === currentConnectionId;
|
|
55527
55576
|
if (isEventFromCurrentUser) {
|
|
55528
55577
|
return;
|
|
55529
55578
|
}
|
|
@@ -55537,6 +55586,7 @@ function handleBoardEventMessage(message, board) {
|
|
|
55537
55586
|
board.events.subject.publish(last);
|
|
55538
55587
|
}
|
|
55539
55588
|
}
|
|
55589
|
+
var init_handleBoardEventMessage = () => {};
|
|
55540
55590
|
|
|
55541
55591
|
// src/Events/MessageRouter/handleBoardSubscriptionCompletedMsg.ts
|
|
55542
55592
|
function handleBoardSubscriptionCompletedMsg(msg, board) {
|
|
@@ -55645,8 +55695,7 @@ function sendBoardEvent(board, batch, sequenceNumber) {
|
|
|
55645
55695
|
type: "BoardEvent",
|
|
55646
55696
|
boardId: board.getBoardId(),
|
|
55647
55697
|
event: toSend,
|
|
55648
|
-
sequenceNumber
|
|
55649
|
-
userId: conf.connection.getCurrentUser()
|
|
55698
|
+
sequenceNumber
|
|
55650
55699
|
});
|
|
55651
55700
|
const date = Date.now();
|
|
55652
55701
|
log.pendingEvent = {
|
|
@@ -55782,6 +55831,7 @@ function handleUserJoinMessage(message, board) {
|
|
|
55782
55831
|
var messageRouter;
|
|
55783
55832
|
var init_messageRouter = __esm(() => {
|
|
55784
55833
|
init_handleAiChatMassage();
|
|
55834
|
+
init_handleBoardEventMessage();
|
|
55785
55835
|
init_handleBoardSubscriptionCompletedMsg();
|
|
55786
55836
|
init_handleConfirmation();
|
|
55787
55837
|
init_handleCreateSnapshotRequestMessage();
|
|
@@ -57056,6 +57106,15 @@ var PRESENCE_CLEANUP_USER_TIMER = 180000;
|
|
|
57056
57106
|
var PRESENCE_CLEANUP_IDLE_TIMER = 60000;
|
|
57057
57107
|
var CURSORS_IDLE_CLEANUP_DELAY = 1e4;
|
|
57058
57108
|
var PING_CLEANUP = 15000;
|
|
57109
|
+
function getPresenceSessionId(message) {
|
|
57110
|
+
if (message.sessionId) {
|
|
57111
|
+
return message.sessionId;
|
|
57112
|
+
}
|
|
57113
|
+
if (message.userId === undefined || message.userId === null) {
|
|
57114
|
+
return;
|
|
57115
|
+
}
|
|
57116
|
+
return String(message.userId);
|
|
57117
|
+
}
|
|
57059
57118
|
var cleanupInterval = null;
|
|
57060
57119
|
|
|
57061
57120
|
class Presence {
|
|
@@ -57065,7 +57124,6 @@ class Presence {
|
|
|
57065
57124
|
trackedUser = null;
|
|
57066
57125
|
cursorsEnabled = true;
|
|
57067
57126
|
drawingContext = null;
|
|
57068
|
-
currentUserId = null;
|
|
57069
57127
|
users = new Map;
|
|
57070
57128
|
followers = [];
|
|
57071
57129
|
svgImageCache = {};
|
|
@@ -57091,7 +57149,7 @@ class Presence {
|
|
|
57091
57149
|
throttleSelectionEvent(this.board.selection);
|
|
57092
57150
|
});
|
|
57093
57151
|
if (typeof window !== "undefined") {
|
|
57094
|
-
window.addEventListener("storage", this.
|
|
57152
|
+
window.addEventListener("storage", this.onStorageChange);
|
|
57095
57153
|
}
|
|
57096
57154
|
}
|
|
57097
57155
|
clear() {
|
|
@@ -57130,19 +57188,30 @@ class Presence {
|
|
|
57130
57188
|
}
|
|
57131
57189
|
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));
|
|
57132
57190
|
}
|
|
57133
|
-
|
|
57134
|
-
|
|
57191
|
+
onStorageChange = (_event) => {};
|
|
57192
|
+
getCurrentSessionId() {
|
|
57193
|
+
return this.events?.connection?.getSessionId?.() || this.events?.connection?.sessionId || null;
|
|
57135
57194
|
}
|
|
57136
|
-
|
|
57137
|
-
if (
|
|
57138
|
-
|
|
57139
|
-
this.setCurrentUser(event.newValue);
|
|
57140
|
-
}
|
|
57195
|
+
getLegacyCurrentUserId() {
|
|
57196
|
+
if (typeof localStorage === "undefined") {
|
|
57197
|
+
return null;
|
|
57141
57198
|
}
|
|
57199
|
+
return localStorage.getItem("currentUser");
|
|
57200
|
+
}
|
|
57201
|
+
isCurrentSessionTarget(value) {
|
|
57202
|
+
if (value === undefined || value === null) {
|
|
57203
|
+
return false;
|
|
57204
|
+
}
|
|
57205
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57206
|
+
if (currentSessionId && String(value) === currentSessionId) {
|
|
57207
|
+
return true;
|
|
57208
|
+
}
|
|
57209
|
+
const currentUser = this.getLegacyCurrentUserId();
|
|
57210
|
+
return currentUser !== null && String(value) === currentUser;
|
|
57142
57211
|
}
|
|
57143
57212
|
cleanup() {
|
|
57144
57213
|
if (typeof window !== "undefined") {
|
|
57145
|
-
window.removeEventListener("storage", this.
|
|
57214
|
+
window.removeEventListener("storage", this.onStorageChange);
|
|
57146
57215
|
}
|
|
57147
57216
|
this.drawingContext = null;
|
|
57148
57217
|
this.clear();
|
|
@@ -57182,24 +57251,25 @@ class Presence {
|
|
|
57182
57251
|
}
|
|
57183
57252
|
join(msg) {
|
|
57184
57253
|
Object.entries(msg.snapshots).map(([userId, snapshot]) => {
|
|
57185
|
-
|
|
57254
|
+
const sessionId = snapshot.sessionId || userId;
|
|
57255
|
+
this.users.set(sessionId, {
|
|
57256
|
+
...snapshot,
|
|
57257
|
+
userId: snapshot.userId || sessionId,
|
|
57258
|
+
sessionId,
|
|
57259
|
+
authorUserId: snapshot.authorUserId || null
|
|
57260
|
+
});
|
|
57186
57261
|
});
|
|
57187
57262
|
this.subject.publish(this);
|
|
57188
57263
|
}
|
|
57189
57264
|
getUsers(boardId, excludeSelf = false) {
|
|
57190
57265
|
let filteredUsers = Array.from(this.users.values()).filter((user) => user.boardId === boardId && (user.lastPing > Date.now() - PING_CLEANUP || user.lastActivity > Date.now() - PING_CLEANUP));
|
|
57191
57266
|
if (excludeSelf) {
|
|
57192
|
-
const
|
|
57193
|
-
if (
|
|
57194
|
-
filteredUsers = filteredUsers.filter((user) => user.
|
|
57267
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57268
|
+
if (currentSessionId) {
|
|
57269
|
+
filteredUsers = filteredUsers.filter((user) => user.sessionId !== currentSessionId);
|
|
57195
57270
|
}
|
|
57196
57271
|
}
|
|
57197
|
-
|
|
57198
|
-
filteredUsers.forEach((user) => {
|
|
57199
|
-
const key = user.hardId === null ? Symbol() : user.hardId;
|
|
57200
|
-
uniqueUsers.set(key, user);
|
|
57201
|
-
});
|
|
57202
|
-
return Array.from(uniqueUsers.values());
|
|
57272
|
+
return filteredUsers;
|
|
57203
57273
|
}
|
|
57204
57274
|
getColors() {
|
|
57205
57275
|
return Array.from(this.users.values()).map((user) => user.color);
|
|
@@ -57208,8 +57278,12 @@ class Presence {
|
|
|
57208
57278
|
if (!this.drawingContext) {
|
|
57209
57279
|
return;
|
|
57210
57280
|
}
|
|
57211
|
-
const
|
|
57212
|
-
|
|
57281
|
+
const sessionId = getPresenceSessionId(event);
|
|
57282
|
+
if (!sessionId) {
|
|
57283
|
+
return;
|
|
57284
|
+
}
|
|
57285
|
+
const { event: eventData } = event;
|
|
57286
|
+
let user = this.users.get(sessionId);
|
|
57213
57287
|
if (!user) {
|
|
57214
57288
|
let color2 = null;
|
|
57215
57289
|
const storageColor = localStorage.getItem(`userColor`);
|
|
@@ -57220,8 +57294,10 @@ class Presence {
|
|
|
57220
57294
|
} else {
|
|
57221
57295
|
color2 = this.generateUserColor();
|
|
57222
57296
|
}
|
|
57223
|
-
this.users.set(
|
|
57224
|
-
userId:
|
|
57297
|
+
this.users.set(sessionId, {
|
|
57298
|
+
userId: sessionId,
|
|
57299
|
+
sessionId,
|
|
57300
|
+
authorUserId: event.authorUserId || null,
|
|
57225
57301
|
softId: event.softId,
|
|
57226
57302
|
hardId: event.hardId,
|
|
57227
57303
|
color: color2,
|
|
@@ -57236,7 +57312,7 @@ class Presence {
|
|
|
57236
57312
|
boardId: this.board.getBoardId(),
|
|
57237
57313
|
lastPointerActivity: eventData.timestamp
|
|
57238
57314
|
});
|
|
57239
|
-
user = this.users.get(
|
|
57315
|
+
user = this.users.get(sessionId);
|
|
57240
57316
|
}
|
|
57241
57317
|
switch (eventData.method) {
|
|
57242
57318
|
case "PointerMove":
|
|
@@ -57279,6 +57355,9 @@ class Presence {
|
|
|
57279
57355
|
if (msg.color) {
|
|
57280
57356
|
userCopy.color = msg.color;
|
|
57281
57357
|
}
|
|
57358
|
+
if (msg.authorUserId) {
|
|
57359
|
+
userCopy.authorUserId = msg.authorUserId;
|
|
57360
|
+
}
|
|
57282
57361
|
userCopy.nickname = msg.nickname;
|
|
57283
57362
|
userCopy.boardId = msg.boardId;
|
|
57284
57363
|
if (shouldUpdateActivity) {
|
|
@@ -57286,107 +57365,113 @@ class Presence {
|
|
|
57286
57365
|
}
|
|
57287
57366
|
}
|
|
57288
57367
|
processFollowEvent(msg) {
|
|
57289
|
-
|
|
57290
|
-
|
|
57291
|
-
|
|
57292
|
-
|
|
57293
|
-
|
|
57294
|
-
this.followers.push(
|
|
57368
|
+
if (this.isCurrentSessionTarget(msg.event.user)) {
|
|
57369
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57370
|
+
if (!sessionId) {
|
|
57371
|
+
return;
|
|
57372
|
+
}
|
|
57373
|
+
this.followers.push(sessionId);
|
|
57295
57374
|
this.followers = Array.from(new Set(this.followers));
|
|
57296
57375
|
}
|
|
57297
57376
|
}
|
|
57298
57377
|
processBringToMe(msg) {
|
|
57299
|
-
|
|
57300
|
-
|
|
57301
|
-
|
|
57302
|
-
|
|
57303
|
-
|
|
57304
|
-
const bringerId = msg.userId.toString();
|
|
57378
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57379
|
+
const bringerId = getPresenceSessionId(msg);
|
|
57380
|
+
if (!bringerId) {
|
|
57381
|
+
return;
|
|
57382
|
+
}
|
|
57305
57383
|
const userToTrack = this.users.get(bringerId);
|
|
57306
57384
|
if (userToTrack) {
|
|
57307
57385
|
this.trackedUser = userToTrack;
|
|
57308
|
-
this.enableTracking(userToTrack.userId);
|
|
57386
|
+
this.enableTracking(userToTrack.sessionId || userToTrack.userId);
|
|
57309
57387
|
}
|
|
57310
57388
|
}
|
|
57311
57389
|
}
|
|
57312
57390
|
processStopFollowing(msg) {
|
|
57313
|
-
const
|
|
57314
|
-
if (!
|
|
57391
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57392
|
+
if (!sessionId) {
|
|
57315
57393
|
return;
|
|
57316
57394
|
}
|
|
57317
|
-
if (msg.event.users.
|
|
57318
|
-
this.followers = this.followers.filter((follower) => follower !==
|
|
57395
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57396
|
+
this.followers = this.followers.filter((follower) => follower !== sessionId);
|
|
57319
57397
|
}
|
|
57320
57398
|
if (!this.trackedUser) {
|
|
57321
57399
|
return;
|
|
57322
57400
|
}
|
|
57323
|
-
if (this.trackedUser.
|
|
57401
|
+
if (this.trackedUser.sessionId !== sessionId) {
|
|
57324
57402
|
return;
|
|
57325
57403
|
}
|
|
57326
|
-
if (msg.event.users.
|
|
57404
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57327
57405
|
this.disableTracking();
|
|
57328
57406
|
}
|
|
57329
57407
|
}
|
|
57330
57408
|
processPing(msg) {
|
|
57331
|
-
const
|
|
57409
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57410
|
+
const user = this.users.get(sessionId);
|
|
57332
57411
|
user.lastPing = msg.event.timestamp;
|
|
57333
57412
|
const userCopy = { ...user };
|
|
57334
57413
|
this.updateUserMetaInfo(msg, userCopy, false);
|
|
57335
|
-
this.users.set(
|
|
57414
|
+
this.users.set(sessionId, userCopy);
|
|
57336
57415
|
}
|
|
57337
57416
|
processCameraEvent(msg) {
|
|
57338
|
-
const
|
|
57417
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57418
|
+
const user = this.users.get(sessionId);
|
|
57339
57419
|
const eventData = msg.event;
|
|
57340
57420
|
const userCopy = { ...user };
|
|
57341
57421
|
userCopy.camera = eventData;
|
|
57342
57422
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57343
|
-
this.users.set(
|
|
57344
|
-
if (this.trackedUser && this.trackedUser.
|
|
57423
|
+
this.users.set(sessionId, userCopy);
|
|
57424
|
+
if (this.trackedUser && this.trackedUser.sessionId === sessionId) {
|
|
57345
57425
|
this.trackedUser.camera = eventData;
|
|
57346
57426
|
this.board.camera.animateToMatrix(new Matrix(eventData.translateX, eventData.translateY, eventData.scaleX, eventData.scaleY, eventData.shearX, eventData.shearY));
|
|
57347
57427
|
}
|
|
57348
57428
|
}
|
|
57349
57429
|
processDrawSelect(msg) {
|
|
57350
|
-
const
|
|
57430
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57431
|
+
const user = this.users.get(sessionId);
|
|
57351
57432
|
const eventData = msg.event;
|
|
57352
57433
|
const userCopy = { ...user };
|
|
57353
57434
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57354
57435
|
userCopy.select = eventData.size;
|
|
57355
|
-
this.users.set(
|
|
57436
|
+
this.users.set(sessionId, userCopy);
|
|
57356
57437
|
}
|
|
57357
57438
|
processCancelDrawSelect(msg) {
|
|
57358
|
-
const
|
|
57439
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57440
|
+
const user = this.users.get(sessionId);
|
|
57359
57441
|
const userCopy = { ...user };
|
|
57360
57442
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57361
57443
|
userCopy.select = undefined;
|
|
57362
|
-
this.users.set(
|
|
57444
|
+
this.users.set(sessionId, userCopy);
|
|
57363
57445
|
}
|
|
57364
57446
|
processPointerMove(msg) {
|
|
57365
|
-
const
|
|
57447
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57448
|
+
const user = this.users.get(sessionId);
|
|
57366
57449
|
const eventData = msg.event;
|
|
57367
57450
|
const userCopy = { ...user };
|
|
57368
57451
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57369
57452
|
userCopy.lastPointerActivity = Date.now();
|
|
57370
57453
|
userCopy.pointer = { x: eventData.position.x, y: eventData.position.y };
|
|
57371
|
-
this.users.set(
|
|
57454
|
+
this.users.set(sessionId, userCopy);
|
|
57372
57455
|
}
|
|
57373
57456
|
processSelection(msg) {
|
|
57374
|
-
const
|
|
57457
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57458
|
+
const user = this.users.get(sessionId);
|
|
57375
57459
|
const eventData = msg.event;
|
|
57376
57460
|
const userCopy = { ...user };
|
|
57377
57461
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57378
57462
|
userCopy.selection = eventData.selectedItems;
|
|
57379
|
-
this.users.set(
|
|
57463
|
+
this.users.set(sessionId, userCopy);
|
|
57380
57464
|
}
|
|
57381
57465
|
processSetColor(msg) {
|
|
57382
|
-
const
|
|
57466
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57467
|
+
const user = this.users.get(sessionId);
|
|
57383
57468
|
const userCopy = { ...user };
|
|
57384
57469
|
userCopy.colorChangeable = false;
|
|
57385
57470
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57386
|
-
this.users.set(
|
|
57471
|
+
this.users.set(sessionId, userCopy);
|
|
57387
57472
|
}
|
|
57388
|
-
enableTracking(
|
|
57389
|
-
const user = this.users.get(
|
|
57473
|
+
enableTracking(sessionId) {
|
|
57474
|
+
const user = this.users.get(sessionId);
|
|
57390
57475
|
if (!user) {
|
|
57391
57476
|
this.trackedUser = null;
|
|
57392
57477
|
} else {
|
|
@@ -57396,7 +57481,7 @@ class Presence {
|
|
|
57396
57481
|
}
|
|
57397
57482
|
this.emit({
|
|
57398
57483
|
method: "Follow",
|
|
57399
|
-
user:
|
|
57484
|
+
user: sessionId,
|
|
57400
57485
|
timestamp: Date.now()
|
|
57401
57486
|
});
|
|
57402
57487
|
}
|
|
@@ -57409,7 +57494,7 @@ class Presence {
|
|
|
57409
57494
|
this.emit({
|
|
57410
57495
|
method: "StopFollowing",
|
|
57411
57496
|
timestamp: Date.now(),
|
|
57412
|
-
users: [this.trackedUser
|
|
57497
|
+
users: [this.trackedUser.sessionId || this.trackedUser.userId]
|
|
57413
57498
|
});
|
|
57414
57499
|
this.trackedUser = null;
|
|
57415
57500
|
}
|
|
@@ -57428,18 +57513,12 @@ class Presence {
|
|
|
57428
57513
|
return this.cursorsEnabled;
|
|
57429
57514
|
}
|
|
57430
57515
|
getSelects() {
|
|
57431
|
-
const
|
|
57516
|
+
const selects = [];
|
|
57517
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57432
57518
|
this.users.forEach((user) => {
|
|
57433
|
-
if (user.
|
|
57434
|
-
|
|
57435
|
-
const existingUser = uniqueUsers.get(key);
|
|
57436
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
57437
|
-
uniqueUsers.set(key, user);
|
|
57438
|
-
}
|
|
57519
|
+
if (currentSessionId && user.sessionId === currentSessionId) {
|
|
57520
|
+
return;
|
|
57439
57521
|
}
|
|
57440
|
-
});
|
|
57441
|
-
const selects = [];
|
|
57442
|
-
uniqueUsers.forEach((user) => {
|
|
57443
57522
|
if (user.select && Date.now() - user.lastActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57444
57523
|
selects.push({
|
|
57445
57524
|
...user.select,
|
|
@@ -57453,42 +57532,29 @@ class Presence {
|
|
|
57453
57532
|
getCursors() {
|
|
57454
57533
|
const currentBoardId = this.board.getBoardId();
|
|
57455
57534
|
const now = Date.now();
|
|
57456
|
-
const
|
|
57535
|
+
const cursors = [];
|
|
57536
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57457
57537
|
this.users.forEach((user) => {
|
|
57458
|
-
if (
|
|
57459
|
-
|
|
57460
|
-
|
|
57461
|
-
|
|
57462
|
-
|
|
57463
|
-
|
|
57538
|
+
if (currentSessionId !== user.sessionId && user.boardId === currentBoardId && now - user.lastPointerActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57539
|
+
cursors.push({
|
|
57540
|
+
...user.pointer,
|
|
57541
|
+
userId: user.sessionId || user.userId,
|
|
57542
|
+
color: user.color,
|
|
57543
|
+
nickname: user.nickname
|
|
57544
|
+
});
|
|
57464
57545
|
}
|
|
57465
57546
|
});
|
|
57466
|
-
const cursors = [];
|
|
57467
|
-
uniqueUsers.forEach((user) => {
|
|
57468
|
-
cursors.push({
|
|
57469
|
-
...user.pointer,
|
|
57470
|
-
userId: user.userId,
|
|
57471
|
-
color: user.color,
|
|
57472
|
-
nickname: user.nickname
|
|
57473
|
-
});
|
|
57474
|
-
});
|
|
57475
57547
|
return cursors;
|
|
57476
57548
|
}
|
|
57477
57549
|
getSelections() {
|
|
57478
57550
|
const currentBoardId = this.board.getBoardId();
|
|
57479
57551
|
const now = Date.now();
|
|
57480
|
-
const
|
|
57552
|
+
const selections = [];
|
|
57553
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57481
57554
|
this.users.forEach((user) => {
|
|
57482
|
-
if (
|
|
57483
|
-
|
|
57484
|
-
const existingUser = uniqueUsers.get(key);
|
|
57485
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
57486
|
-
uniqueUsers.set(key, user);
|
|
57487
|
-
}
|
|
57555
|
+
if (currentSessionId === user.sessionId || user.boardId !== currentBoardId || now - user.lastPointerActivity > CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57556
|
+
return;
|
|
57488
57557
|
}
|
|
57489
|
-
});
|
|
57490
|
-
const selections = [];
|
|
57491
|
-
uniqueUsers.forEach((user) => {
|
|
57492
57558
|
if (Date.now() - user.lastActivity >= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57493
57559
|
return;
|
|
57494
57560
|
}
|