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