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