microboard-temp 0.13.58 → 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.
@@ -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, userId) {
5894
+ function shouldSkipEvent(record, sessionIds) {
5864
5895
  const { operation } = record.event.body;
5865
- return record.event.body.userId !== userId || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
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(userId, list) {
5902
+ function getRedoRecordFromList(sessionIds, list) {
5870
5903
  let counter = 0;
5871
5904
  for (const record of list.backwardIterable()) {
5872
- if (shouldSkipEvent(record, userId)) {
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(userId, list) {
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, userId)) {
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(userId) {
6204
- return getUndoRecordFromList(userId, this.list);
6240
+ getUndoRecord(sessionIds) {
6241
+ return getUndoRecordFromList(sessionIds, this.list);
6205
6242
  }
6206
- getRedoRecord(userId) {
6207
- return getRedoRecordFromList(userId, this.list);
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 userId = this.getUserId();
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, userId);
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 currentUserId = this.getUserId();
14256
- const record = this.log.getUndoRecord(currentUserId);
14295
+ const currentSessionIds = this.getSessionIds();
14296
+ const record = this.log.getUndoRecord(currentSessionIds);
14257
14297
  if (!record) {
14258
14298
  return;
14259
14299
  }
14260
- const { operation, userId, eventId } = record.event.body;
14261
- const canUndo = this.canUndoEvent(operation, userId);
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 userId = this.getUserId();
14273
- const record = this.log.getRedoRecord(userId);
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 userId = this.getUserId();
14285
- const record = this.log.getUndoRecord(userId);
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.userId);
14329
+ return this.canUndoEvent(record.event.body.operation, getBoardEventSessionId(record.event.body));
14290
14330
  }
14291
14331
  canRedo() {
14292
- const userId = this.getUserId();
14293
- const record = this.log.getRedoRecord(userId);
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, byUserId) {
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 byUserId === undefined || byUserId === latest;
14349
+ return bySessionId === undefined || bySessionId === latest;
14310
14350
  }
14311
- setLatestUserEvent(op, userId) {
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] = userId;
14354
+ this.latestEvent[key] = sessionId;
14315
14355
  }
14316
14356
  }
14317
14357
  getOpKey(op) {
14318
14358
  return op.method;
14319
14359
  }
14320
- getUserId() {
14321
- return this.connection?.connectionId || 0;
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 userId = this.getUserId();
14326
- return userId + ":" + id;
14371
+ const sessionId = this.getSessionId();
14372
+ return sessionId + ":" + id;
14327
14373
  }
14328
14374
  }
14329
14375
  function createEvents(board, connection, lastIndex) {
@@ -42754,6 +42800,7 @@ var init_Connector = __esm(() => {
42754
42800
  transformation;
42755
42801
  middlePoint = new BoardPoint;
42756
42802
  lineColor;
42803
+ smartJump = true;
42757
42804
  linkTo;
42758
42805
  lineWidth;
42759
42806
  borderStyle;
@@ -42853,6 +42900,8 @@ var init_Connector = __esm(() => {
42853
42900
  }
42854
42901
  };
42855
42902
  smartJumpStartEdge() {
42903
+ if (!this.smartJump)
42904
+ return false;
42856
42905
  const start = this.startPoint;
42857
42906
  if (start.pointType !== "Fixed" && start.pointType !== "Floating")
42858
42907
  return false;
@@ -42889,6 +42938,8 @@ var init_Connector = __esm(() => {
42889
42938
  return true;
42890
42939
  }
42891
42940
  smartJumpEndEdge() {
42941
+ if (!this.smartJump)
42942
+ return false;
42892
42943
  const end = this.endPoint;
42893
42944
  if (end.pointType !== "Fixed" && end.pointType !== "Floating")
42894
42945
  return false;
@@ -42924,6 +42975,20 @@ var init_Connector = __esm(() => {
42924
42975
  this.setEndPoint(new FixedPoint(item, toRelativePoint(best, item)));
42925
42976
  return true;
42926
42977
  }
42978
+ setSmartJump(value) {
42979
+ this.emit({
42980
+ class: "Connector",
42981
+ method: "setSmartJump",
42982
+ item: [this.id],
42983
+ smartJump: value
42984
+ });
42985
+ }
42986
+ applySmartJump(value) {
42987
+ this.smartJump = value;
42988
+ }
42989
+ getSmartJump() {
42990
+ return this.smartJump;
42991
+ }
42927
42992
  clearObservedItems() {
42928
42993
  const startPoint = this.getStartPoint();
42929
42994
  const endPoint = this.getEndPoint();
@@ -43002,6 +43067,9 @@ var init_Connector = __esm(() => {
43002
43067
  case "switchPointers":
43003
43068
  this.applySwitchPointers();
43004
43069
  break;
43070
+ case "setSmartJump":
43071
+ this.applySmartJump(operation.smartJump);
43072
+ break;
43005
43073
  }
43006
43074
  break;
43007
43075
  case "LinkTo":
@@ -43437,6 +43505,7 @@ var init_Connector = __esm(() => {
43437
43505
  lineWidth: this.lineWidth,
43438
43506
  text: text5,
43439
43507
  borderStyle: this.borderStyle,
43508
+ smartJump: this.smartJump,
43440
43509
  linkTo: this.linkTo.serialize()
43441
43510
  };
43442
43511
  }
@@ -43471,6 +43540,9 @@ var init_Connector = __esm(() => {
43471
43540
  }
43472
43541
  this.lineWidth = data.lineWidth ?? this.lineWidth;
43473
43542
  this.borderStyle = data.borderStyle ?? this.borderStyle;
43543
+ if (data.smartJump != null) {
43544
+ this.smartJump = data.smartJump;
43545
+ }
43474
43546
  if (data.transformation) {
43475
43547
  this.transformation.deserialize(data.transformation);
43476
43548
  }
@@ -43659,6 +43731,7 @@ class ConnectorData {
43659
43731
  linkTo;
43660
43732
  lineWidth = 1;
43661
43733
  borderStyle = "solid";
43734
+ smartJump = true;
43662
43735
  transformation = new DefaultTransformationData;
43663
43736
  text = new DefaultRichTextData([], "center", undefined);
43664
43737
  optionalFindItemFn;
@@ -55563,9 +55636,9 @@ function handleBoardEventMessage(message, board) {
55563
55636
  if (event.order <= log.getLastIndex()) {
55564
55637
  return;
55565
55638
  }
55566
- const eventConnectionId = Number(event.body.eventId.split(":")[0]);
55567
- const currentConnectionId = board.events.connection?.connectionId;
55568
- const isEventFromCurrentUser = currentConnectionId !== undefined && eventConnectionId === currentConnectionId;
55639
+ const eventSessionId = getBoardEventSessionId(event.body);
55640
+ const currentConnectionId = getConnectionSessionId(board.events.connection);
55641
+ const isEventFromCurrentUser = eventSessionId !== undefined && eventSessionId === currentConnectionId;
55569
55642
  if (isEventFromCurrentUser) {
55570
55643
  return;
55571
55644
  }
@@ -55579,6 +55652,7 @@ function handleBoardEventMessage(message, board) {
55579
55652
  board.events.subject.publish(last);
55580
55653
  }
55581
55654
  }
55655
+ var init_handleBoardEventMessage = () => {};
55582
55656
 
55583
55657
  // src/Events/MessageRouter/handleBoardSubscriptionCompletedMsg.ts
55584
55658
  function handleBoardSubscriptionCompletedMsg(msg, board) {
@@ -55687,8 +55761,7 @@ function sendBoardEvent(board, batch, sequenceNumber) {
55687
55761
  type: "BoardEvent",
55688
55762
  boardId: board.getBoardId(),
55689
55763
  event: toSend,
55690
- sequenceNumber,
55691
- userId: conf.connection.getCurrentUser()
55764
+ sequenceNumber
55692
55765
  });
55693
55766
  const date = Date.now();
55694
55767
  log.pendingEvent = {
@@ -55824,6 +55897,7 @@ function handleUserJoinMessage(message, board) {
55824
55897
  var messageRouter;
55825
55898
  var init_messageRouter = __esm(() => {
55826
55899
  init_handleAiChatMassage();
55900
+ init_handleBoardEventMessage();
55827
55901
  init_handleBoardSubscriptionCompletedMsg();
55828
55902
  init_handleConfirmation();
55829
55903
  init_handleCreateSnapshotRequestMessage();
@@ -57293,6 +57367,15 @@ var PRESENCE_CLEANUP_USER_TIMER = 180000;
57293
57367
  var PRESENCE_CLEANUP_IDLE_TIMER = 60000;
57294
57368
  var CURSORS_IDLE_CLEANUP_DELAY = 1e4;
57295
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
+ }
57296
57379
  var cleanupInterval = null;
57297
57380
 
57298
57381
  class Presence {
@@ -57302,7 +57385,6 @@ class Presence {
57302
57385
  trackedUser = null;
57303
57386
  cursorsEnabled = true;
57304
57387
  drawingContext = null;
57305
- currentUserId = null;
57306
57388
  users = new Map;
57307
57389
  followers = [];
57308
57390
  svgImageCache = {};
@@ -57328,7 +57410,7 @@ class Presence {
57328
57410
  throttleSelectionEvent(this.board.selection);
57329
57411
  });
57330
57412
  if (typeof window !== "undefined") {
57331
- window.addEventListener("storage", this.updateCurrentUser.bind(this));
57413
+ window.addEventListener("storage", this.onStorageChange);
57332
57414
  }
57333
57415
  }
57334
57416
  clear() {
@@ -57367,19 +57449,30 @@ class Presence {
57367
57449
  }
57368
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));
57369
57451
  }
57370
- setCurrentUser(userId) {
57371
- this.currentUserId = userId;
57452
+ onStorageChange = (_event) => {};
57453
+ getCurrentSessionId() {
57454
+ return this.events?.connection?.getSessionId?.() || this.events?.connection?.sessionId || null;
57372
57455
  }
57373
- updateCurrentUser(event) {
57374
- if (event.key === "currentUser") {
57375
- if (event.newValue) {
57376
- this.setCurrentUser(event.newValue);
57377
- }
57456
+ getLegacyCurrentUserId() {
57457
+ if (typeof localStorage === "undefined") {
57458
+ return null;
57459
+ }
57460
+ return localStorage.getItem("currentUser");
57461
+ }
57462
+ isCurrentSessionTarget(value) {
57463
+ if (value === undefined || value === null) {
57464
+ return false;
57378
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;
57379
57472
  }
57380
57473
  cleanup() {
57381
57474
  if (typeof window !== "undefined") {
57382
- window.removeEventListener("storage", this.updateCurrentUser.bind(this));
57475
+ window.removeEventListener("storage", this.onStorageChange);
57383
57476
  }
57384
57477
  this.drawingContext = null;
57385
57478
  this.clear();
@@ -57419,24 +57512,25 @@ class Presence {
57419
57512
  }
57420
57513
  join(msg) {
57421
57514
  Object.entries(msg.snapshots).map(([userId, snapshot]) => {
57422
- this.users.set(userId, snapshot);
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
+ });
57423
57522
  });
57424
57523
  this.subject.publish(this);
57425
57524
  }
57426
57525
  getUsers(boardId, excludeSelf = false) {
57427
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));
57428
57527
  if (excludeSelf) {
57429
- const currentUser = localStorage.getItem("currentUser");
57430
- if (currentUser) {
57431
- filteredUsers = filteredUsers.filter((user) => user.userId !== currentUser);
57528
+ const currentSessionId = this.getCurrentSessionId();
57529
+ if (currentSessionId) {
57530
+ filteredUsers = filteredUsers.filter((user) => user.sessionId !== currentSessionId);
57432
57531
  }
57433
57532
  }
57434
- const uniqueUsers = new Map;
57435
- filteredUsers.forEach((user) => {
57436
- const key = user.hardId === null ? Symbol() : user.hardId;
57437
- uniqueUsers.set(key, user);
57438
- });
57439
- return Array.from(uniqueUsers.values());
57533
+ return filteredUsers;
57440
57534
  }
57441
57535
  getColors() {
57442
57536
  return Array.from(this.users.values()).map((user) => user.color);
@@ -57445,8 +57539,12 @@ class Presence {
57445
57539
  if (!this.drawingContext) {
57446
57540
  return;
57447
57541
  }
57448
- const { userId, event: eventData } = event;
57449
- let user = this.users.get(userId);
57542
+ const sessionId = getPresenceSessionId(event);
57543
+ if (!sessionId) {
57544
+ return;
57545
+ }
57546
+ const { event: eventData } = event;
57547
+ let user = this.users.get(sessionId);
57450
57548
  if (!user) {
57451
57549
  let color2 = null;
57452
57550
  const storageColor = localStorage.getItem(`userColor`);
@@ -57457,8 +57555,10 @@ class Presence {
57457
57555
  } else {
57458
57556
  color2 = this.generateUserColor();
57459
57557
  }
57460
- this.users.set(userId.toString(), {
57461
- userId: userId.toString(),
57558
+ this.users.set(sessionId, {
57559
+ userId: sessionId,
57560
+ sessionId,
57561
+ authorUserId: event.authorUserId || null,
57462
57562
  softId: event.softId,
57463
57563
  hardId: event.hardId,
57464
57564
  color: color2,
@@ -57473,7 +57573,7 @@ class Presence {
57473
57573
  boardId: this.board.getBoardId(),
57474
57574
  lastPointerActivity: eventData.timestamp
57475
57575
  });
57476
- user = this.users.get(userId.toString());
57576
+ user = this.users.get(sessionId);
57477
57577
  }
57478
57578
  switch (eventData.method) {
57479
57579
  case "PointerMove":
@@ -57516,6 +57616,9 @@ class Presence {
57516
57616
  if (msg.color) {
57517
57617
  userCopy.color = msg.color;
57518
57618
  }
57619
+ if (msg.authorUserId) {
57620
+ userCopy.authorUserId = msg.authorUserId;
57621
+ }
57519
57622
  userCopy.nickname = msg.nickname;
57520
57623
  userCopy.boardId = msg.boardId;
57521
57624
  if (shouldUpdateActivity) {
@@ -57523,107 +57626,113 @@ class Presence {
57523
57626
  }
57524
57627
  }
57525
57628
  processFollowEvent(msg) {
57526
- const currentUser = localStorage.getItem(`currentUser`);
57527
- if (!currentUser) {
57528
- return;
57529
- }
57530
- if (msg.event.user === currentUser) {
57531
- this.followers.push(msg.userId.toString());
57629
+ if (this.isCurrentSessionTarget(msg.event.user)) {
57630
+ const sessionId = getPresenceSessionId(msg);
57631
+ if (!sessionId) {
57632
+ return;
57633
+ }
57634
+ this.followers.push(sessionId);
57532
57635
  this.followers = Array.from(new Set(this.followers));
57533
57636
  }
57534
57637
  }
57535
57638
  processBringToMe(msg) {
57536
- const currentUser = localStorage.getItem(`currentUser`);
57537
- if (!currentUser) {
57538
- return;
57539
- }
57540
- if (msg.event.users.includes(currentUser)) {
57541
- 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
+ }
57542
57644
  const userToTrack = this.users.get(bringerId);
57543
57645
  if (userToTrack) {
57544
57646
  this.trackedUser = userToTrack;
57545
- this.enableTracking(userToTrack.userId);
57647
+ this.enableTracking(userToTrack.sessionId || userToTrack.userId);
57546
57648
  }
57547
57649
  }
57548
57650
  }
57549
57651
  processStopFollowing(msg) {
57550
- const currentUser = localStorage.getItem(`currentUser`);
57551
- if (!currentUser) {
57652
+ const sessionId = getPresenceSessionId(msg);
57653
+ if (!sessionId) {
57552
57654
  return;
57553
57655
  }
57554
- if (msg.event.users.includes(currentUser)) {
57555
- this.followers = this.followers.filter((follower) => follower !== msg.userId.toString());
57656
+ if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
57657
+ this.followers = this.followers.filter((follower) => follower !== sessionId);
57556
57658
  }
57557
57659
  if (!this.trackedUser) {
57558
57660
  return;
57559
57661
  }
57560
- if (this.trackedUser.userId !== msg.userId) {
57662
+ if (this.trackedUser.sessionId !== sessionId) {
57561
57663
  return;
57562
57664
  }
57563
- if (msg.event.users.includes(currentUser) && this.trackedUser.userId === msg.userId) {
57665
+ if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
57564
57666
  this.disableTracking();
57565
57667
  }
57566
57668
  }
57567
57669
  processPing(msg) {
57568
- const user = this.users.get(msg.userId.toString());
57670
+ const sessionId = getPresenceSessionId(msg);
57671
+ const user = this.users.get(sessionId);
57569
57672
  user.lastPing = msg.event.timestamp;
57570
57673
  const userCopy = { ...user };
57571
57674
  this.updateUserMetaInfo(msg, userCopy, false);
57572
- this.users.set(msg.userId.toString(), userCopy);
57675
+ this.users.set(sessionId, userCopy);
57573
57676
  }
57574
57677
  processCameraEvent(msg) {
57575
- const user = this.users.get(msg.userId.toString());
57678
+ const sessionId = getPresenceSessionId(msg);
57679
+ const user = this.users.get(sessionId);
57576
57680
  const eventData = msg.event;
57577
57681
  const userCopy = { ...user };
57578
57682
  userCopy.camera = eventData;
57579
57683
  this.updateUserMetaInfo(msg, userCopy);
57580
- this.users.set(msg.userId.toString(), userCopy);
57581
- if (this.trackedUser && this.trackedUser.userId === msg.userId.toString()) {
57684
+ this.users.set(sessionId, userCopy);
57685
+ if (this.trackedUser && this.trackedUser.sessionId === sessionId) {
57582
57686
  this.trackedUser.camera = eventData;
57583
57687
  this.board.camera.animateToMatrix(new Matrix(eventData.translateX, eventData.translateY, eventData.scaleX, eventData.scaleY, eventData.shearX, eventData.shearY));
57584
57688
  }
57585
57689
  }
57586
57690
  processDrawSelect(msg) {
57587
- const user = this.users.get(msg.userId.toString());
57691
+ const sessionId = getPresenceSessionId(msg);
57692
+ const user = this.users.get(sessionId);
57588
57693
  const eventData = msg.event;
57589
57694
  const userCopy = { ...user };
57590
57695
  this.updateUserMetaInfo(msg, userCopy);
57591
57696
  userCopy.select = eventData.size;
57592
- this.users.set(msg.userId.toString(), userCopy);
57697
+ this.users.set(sessionId, userCopy);
57593
57698
  }
57594
57699
  processCancelDrawSelect(msg) {
57595
- const user = this.users.get(msg.userId.toString());
57700
+ const sessionId = getPresenceSessionId(msg);
57701
+ const user = this.users.get(sessionId);
57596
57702
  const userCopy = { ...user };
57597
57703
  this.updateUserMetaInfo(msg, userCopy);
57598
57704
  userCopy.select = undefined;
57599
- this.users.set(msg.userId.toString(), userCopy);
57705
+ this.users.set(sessionId, userCopy);
57600
57706
  }
57601
57707
  processPointerMove(msg) {
57602
- const user = this.users.get(msg.userId.toString());
57708
+ const sessionId = getPresenceSessionId(msg);
57709
+ const user = this.users.get(sessionId);
57603
57710
  const eventData = msg.event;
57604
57711
  const userCopy = { ...user };
57605
57712
  this.updateUserMetaInfo(msg, userCopy);
57606
57713
  userCopy.lastPointerActivity = Date.now();
57607
57714
  userCopy.pointer = { x: eventData.position.x, y: eventData.position.y };
57608
- this.users.set(msg.userId.toString(), userCopy);
57715
+ this.users.set(sessionId, userCopy);
57609
57716
  }
57610
57717
  processSelection(msg) {
57611
- const user = this.users.get(msg.userId.toString());
57718
+ const sessionId = getPresenceSessionId(msg);
57719
+ const user = this.users.get(sessionId);
57612
57720
  const eventData = msg.event;
57613
57721
  const userCopy = { ...user };
57614
57722
  this.updateUserMetaInfo(msg, userCopy);
57615
57723
  userCopy.selection = eventData.selectedItems;
57616
- this.users.set(msg.userId.toString(), userCopy);
57724
+ this.users.set(sessionId, userCopy);
57617
57725
  }
57618
57726
  processSetColor(msg) {
57619
- const user = this.users.get(msg.userId.toString());
57727
+ const sessionId = getPresenceSessionId(msg);
57728
+ const user = this.users.get(sessionId);
57620
57729
  const userCopy = { ...user };
57621
57730
  userCopy.colorChangeable = false;
57622
57731
  this.updateUserMetaInfo(msg, userCopy);
57623
- this.users.set(msg.userId.toString(), userCopy);
57732
+ this.users.set(sessionId, userCopy);
57624
57733
  }
57625
- enableTracking(userId) {
57626
- const user = this.users.get(userId);
57734
+ enableTracking(sessionId) {
57735
+ const user = this.users.get(sessionId);
57627
57736
  if (!user) {
57628
57737
  this.trackedUser = null;
57629
57738
  } else {
@@ -57633,7 +57742,7 @@ class Presence {
57633
57742
  }
57634
57743
  this.emit({
57635
57744
  method: "Follow",
57636
- user: userId,
57745
+ user: sessionId,
57637
57746
  timestamp: Date.now()
57638
57747
  });
57639
57748
  }
@@ -57646,7 +57755,7 @@ class Presence {
57646
57755
  this.emit({
57647
57756
  method: "StopFollowing",
57648
57757
  timestamp: Date.now(),
57649
- users: [this.trackedUser?.userId]
57758
+ users: [this.trackedUser.sessionId || this.trackedUser.userId]
57650
57759
  });
57651
57760
  this.trackedUser = null;
57652
57761
  }
@@ -57665,18 +57774,12 @@ class Presence {
57665
57774
  return this.cursorsEnabled;
57666
57775
  }
57667
57776
  getSelects() {
57668
- const uniqueUsers = new Map;
57777
+ const selects = [];
57778
+ const currentSessionId = this.getCurrentSessionId();
57669
57779
  this.users.forEach((user) => {
57670
- if (user.userId !== this.currentUserId) {
57671
- const key = user.hardId !== null ? `hardId:${user.hardId}` : `softId:${user.userId}`;
57672
- const existingUser = uniqueUsers.get(key);
57673
- if (!existingUser || user.lastActivity > existingUser.lastActivity) {
57674
- uniqueUsers.set(key, user);
57675
- }
57780
+ if (currentSessionId && user.sessionId === currentSessionId) {
57781
+ return;
57676
57782
  }
57677
- });
57678
- const selects = [];
57679
- uniqueUsers.forEach((user) => {
57680
57783
  if (user.select && Date.now() - user.lastActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
57681
57784
  selects.push({
57682
57785
  ...user.select,
@@ -57690,42 +57793,29 @@ class Presence {
57690
57793
  getCursors() {
57691
57794
  const currentBoardId = this.board.getBoardId();
57692
57795
  const now = Date.now();
57693
- const uniqueUsers = new Map;
57796
+ const cursors = [];
57797
+ const currentSessionId = this.getCurrentSessionId();
57694
57798
  this.users.forEach((user) => {
57695
- if (user.userId !== this.currentUserId && user.boardId === currentBoardId && now - user.lastPointerActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
57696
- const key = user.hardId !== null ? `hardId:${user.hardId}` : `softId:${user.userId}`;
57697
- const existingUser = uniqueUsers.get(key);
57698
- if (!existingUser || user.lastActivity > existingUser.lastActivity) {
57699
- uniqueUsers.set(key, user);
57700
- }
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
+ });
57701
57806
  }
57702
57807
  });
57703
- const cursors = [];
57704
- uniqueUsers.forEach((user) => {
57705
- cursors.push({
57706
- ...user.pointer,
57707
- userId: user.userId,
57708
- color: user.color,
57709
- nickname: user.nickname
57710
- });
57711
- });
57712
57808
  return cursors;
57713
57809
  }
57714
57810
  getSelections() {
57715
57811
  const currentBoardId = this.board.getBoardId();
57716
57812
  const now = Date.now();
57717
- const uniqueUsers = new Map;
57813
+ const selections = [];
57814
+ const currentSessionId = this.getCurrentSessionId();
57718
57815
  this.users.forEach((user) => {
57719
- if (user.userId !== this.currentUserId && user.boardId === currentBoardId && now - user.lastPointerActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
57720
- const key = user.hardId !== null ? `hardId:${user.hardId}` : `softId:${user.userId}`;
57721
- const existingUser = uniqueUsers.get(key);
57722
- if (!existingUser || user.lastActivity > existingUser.lastActivity) {
57723
- uniqueUsers.set(key, user);
57724
- }
57816
+ if (currentSessionId === user.sessionId || user.boardId !== currentBoardId || now - user.lastPointerActivity > CURSORS_IDLE_CLEANUP_DELAY) {
57817
+ return;
57725
57818
  }
57726
- });
57727
- const selections = [];
57728
- uniqueUsers.forEach((user) => {
57729
57819
  if (Date.now() - user.lastActivity >= CURSORS_IDLE_CLEANUP_DELAY) {
57730
57820
  return;
57731
57821
  }