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/node.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, 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);
@@ -14238,10 +14275,13 @@ class Events {
14238
14275
  console.error("[DEBUG] transformMany emitted from Events.emit!", JSON.stringify(operation));
14239
14276
  console.trace("[DEBUG] transformMany stack trace");
14240
14277
  }
14241
- const userId = this.getUserId();
14278
+ const sessionId = this.getSessionId();
14279
+ const authorUserId = this.getAuthorUserId();
14242
14280
  const body = {
14243
14281
  eventId: this.getNextEventId(),
14244
- userId,
14282
+ userId: sessionId,
14283
+ authorUserId,
14284
+ sessionId,
14245
14285
  boardId: this.board.getBoardId(),
14246
14286
  operation
14247
14287
  };
@@ -14251,7 +14291,7 @@ class Events {
14251
14291
  command: command || Events.createCommand(this.board, operation)
14252
14292
  };
14253
14293
  this.log.insertNewLocalEventRecordAfterEmit(record);
14254
- this.setLatestUserEvent(operation, userId);
14294
+ this.setLatestUserEvent(operation, sessionId);
14255
14295
  this.subject.publish(event);
14256
14296
  if (this.board.getBoardId().includes("local")) {
14257
14297
  if (this.log.saveFileTimeout) {
@@ -14272,13 +14312,13 @@ class Events {
14272
14312
  this.emit(operation, cmd);
14273
14313
  }
14274
14314
  undo() {
14275
- const currentUserId = this.getUserId();
14276
- const record = this.log.getUndoRecord(currentUserId);
14315
+ const currentSessionIds = this.getSessionIds();
14316
+ const record = this.log.getUndoRecord(currentSessionIds);
14277
14317
  if (!record) {
14278
14318
  return;
14279
14319
  }
14280
- const { operation, userId, eventId } = record.event.body;
14281
- const canUndo = this.canUndoEvent(operation, userId);
14320
+ const { operation, eventId } = record.event.body;
14321
+ const canUndo = this.canUndoEvent(operation, getBoardEventSessionId(record.event.body));
14282
14322
  if (!canUndo) {
14283
14323
  return;
14284
14324
  }
@@ -14289,8 +14329,8 @@ class Events {
14289
14329
  });
14290
14330
  }
14291
14331
  redo() {
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
  if (!record) {
14295
14335
  return;
14296
14336
  }
@@ -14301,22 +14341,22 @@ class Events {
14301
14341
  });
14302
14342
  }
14303
14343
  canUndo() {
14304
- const userId = this.getUserId();
14305
- const record = this.log.getUndoRecord(userId);
14344
+ const sessionIds = this.getSessionIds();
14345
+ const record = this.log.getUndoRecord(sessionIds);
14306
14346
  if (!record) {
14307
14347
  return false;
14308
14348
  }
14309
- return this.canUndoEvent(record.event.body.operation, record.event.body.userId);
14349
+ return this.canUndoEvent(record.event.body.operation, getBoardEventSessionId(record.event.body));
14310
14350
  }
14311
14351
  canRedo() {
14312
- const userId = this.getUserId();
14313
- const record = this.log.getRedoRecord(userId);
14352
+ const sessionIds = this.getSessionIds();
14353
+ const record = this.log.getRedoRecord(sessionIds);
14314
14354
  return record !== null;
14315
14355
  }
14316
14356
  sendPresenceEvent(event) {
14317
14357
  conf.connection.publishPresenceEvent(this.board.getBoardId(), event);
14318
14358
  }
14319
- canUndoEvent(op, byUserId) {
14359
+ canUndoEvent(op, bySessionId) {
14320
14360
  if (op.method === "undo") {
14321
14361
  return false;
14322
14362
  }
@@ -14326,24 +14366,30 @@ class Events {
14326
14366
  }
14327
14367
  const key = this.getOpKey(op);
14328
14368
  const latest = this.latestEvent[key];
14329
- return byUserId === undefined || byUserId === latest;
14369
+ return bySessionId === undefined || bySessionId === latest;
14330
14370
  }
14331
- setLatestUserEvent(op, userId) {
14371
+ setLatestUserEvent(op, sessionId) {
14332
14372
  if (op.class !== "Events" && op.method !== "paste" && op.method !== "duplicate") {
14333
14373
  const key = this.getOpKey(op);
14334
- this.latestEvent[key] = userId;
14374
+ this.latestEvent[key] = sessionId;
14335
14375
  }
14336
14376
  }
14337
14377
  getOpKey(op) {
14338
14378
  return op.method;
14339
14379
  }
14340
- getUserId() {
14341
- return this.connection?.connectionId || 0;
14380
+ getSessionId() {
14381
+ return getConnectionSessionId(this.connection);
14382
+ }
14383
+ getSessionIds() {
14384
+ return getConnectionSessionIds(this.connection);
14385
+ }
14386
+ getAuthorUserId() {
14387
+ return getConnectionAuthorUserId(this.connection);
14342
14388
  }
14343
14389
  getNextEventId() {
14344
14390
  const id = ++this.eventCounter;
14345
- const userId = this.getUserId();
14346
- return userId + ":" + id;
14391
+ const sessionId = this.getSessionId();
14392
+ return sessionId + ":" + id;
14347
14393
  }
14348
14394
  }
14349
14395
  function createEvents(board, connection, lastIndex) {
@@ -58010,9 +58056,9 @@ function handleBoardEventMessage(message, board) {
58010
58056
  if (event.order <= log.getLastIndex()) {
58011
58057
  return;
58012
58058
  }
58013
- const eventConnectionId = Number(event.body.eventId.split(":")[0]);
58014
- const currentConnectionId = board.events.connection?.connectionId;
58015
- const isEventFromCurrentUser = currentConnectionId !== undefined && eventConnectionId === currentConnectionId;
58059
+ const eventSessionId = getBoardEventSessionId(event.body);
58060
+ const currentConnectionId = getConnectionSessionId(board.events.connection);
58061
+ const isEventFromCurrentUser = eventSessionId !== undefined && eventSessionId === currentConnectionId;
58016
58062
  if (isEventFromCurrentUser) {
58017
58063
  return;
58018
58064
  }
@@ -58026,6 +58072,7 @@ function handleBoardEventMessage(message, board) {
58026
58072
  board.events.subject.publish(last);
58027
58073
  }
58028
58074
  }
58075
+ var init_handleBoardEventMessage = () => {};
58029
58076
 
58030
58077
  // src/Events/MessageRouter/handleBoardSubscriptionCompletedMsg.ts
58031
58078
  function handleBoardSubscriptionCompletedMsg(msg, board) {
@@ -58134,8 +58181,7 @@ function sendBoardEvent(board, batch, sequenceNumber) {
58134
58181
  type: "BoardEvent",
58135
58182
  boardId: board.getBoardId(),
58136
58183
  event: toSend,
58137
- sequenceNumber,
58138
- userId: conf.connection.getCurrentUser()
58184
+ sequenceNumber
58139
58185
  });
58140
58186
  const date = Date.now();
58141
58187
  log.pendingEvent = {
@@ -58271,6 +58317,7 @@ function handleUserJoinMessage(message, board) {
58271
58317
  var messageRouter;
58272
58318
  var init_messageRouter = __esm(() => {
58273
58319
  init_handleAiChatMassage();
58320
+ init_handleBoardEventMessage();
58274
58321
  init_handleBoardSubscriptionCompletedMsg();
58275
58322
  init_handleConfirmation();
58276
58323
  init_handleCreateSnapshotRequestMessage();
@@ -59795,6 +59842,15 @@ var PRESENCE_CLEANUP_USER_TIMER = 180000;
59795
59842
  var PRESENCE_CLEANUP_IDLE_TIMER = 60000;
59796
59843
  var CURSORS_IDLE_CLEANUP_DELAY = 1e4;
59797
59844
  var PING_CLEANUP = 15000;
59845
+ function getPresenceSessionId(message) {
59846
+ if (message.sessionId) {
59847
+ return message.sessionId;
59848
+ }
59849
+ if (message.userId === undefined || message.userId === null) {
59850
+ return;
59851
+ }
59852
+ return String(message.userId);
59853
+ }
59798
59854
  var cleanupInterval = null;
59799
59855
 
59800
59856
  class Presence {
@@ -59804,7 +59860,6 @@ class Presence {
59804
59860
  trackedUser = null;
59805
59861
  cursorsEnabled = true;
59806
59862
  drawingContext = null;
59807
- currentUserId = null;
59808
59863
  users = new Map;
59809
59864
  followers = [];
59810
59865
  svgImageCache = {};
@@ -59830,7 +59885,7 @@ class Presence {
59830
59885
  throttleSelectionEvent(this.board.selection);
59831
59886
  });
59832
59887
  if (typeof window !== "undefined") {
59833
- window.addEventListener("storage", this.updateCurrentUser.bind(this));
59888
+ window.addEventListener("storage", this.onStorageChange);
59834
59889
  }
59835
59890
  }
59836
59891
  clear() {
@@ -59869,19 +59924,30 @@ class Presence {
59869
59924
  }
59870
59925
  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));
59871
59926
  }
59872
- setCurrentUser(userId) {
59873
- this.currentUserId = userId;
59927
+ onStorageChange = (_event) => {};
59928
+ getCurrentSessionId() {
59929
+ return this.events?.connection?.getSessionId?.() || this.events?.connection?.sessionId || null;
59874
59930
  }
59875
- updateCurrentUser(event) {
59876
- if (event.key === "currentUser") {
59877
- if (event.newValue) {
59878
- this.setCurrentUser(event.newValue);
59879
- }
59931
+ getLegacyCurrentUserId() {
59932
+ if (typeof localStorage === "undefined") {
59933
+ return null;
59880
59934
  }
59935
+ return localStorage.getItem("currentUser");
59936
+ }
59937
+ isCurrentSessionTarget(value) {
59938
+ if (value === undefined || value === null) {
59939
+ return false;
59940
+ }
59941
+ const currentSessionId = this.getCurrentSessionId();
59942
+ if (currentSessionId && String(value) === currentSessionId) {
59943
+ return true;
59944
+ }
59945
+ const currentUser = this.getLegacyCurrentUserId();
59946
+ return currentUser !== null && String(value) === currentUser;
59881
59947
  }
59882
59948
  cleanup() {
59883
59949
  if (typeof window !== "undefined") {
59884
- window.removeEventListener("storage", this.updateCurrentUser.bind(this));
59950
+ window.removeEventListener("storage", this.onStorageChange);
59885
59951
  }
59886
59952
  this.drawingContext = null;
59887
59953
  this.clear();
@@ -59921,24 +59987,25 @@ class Presence {
59921
59987
  }
59922
59988
  join(msg) {
59923
59989
  Object.entries(msg.snapshots).map(([userId, snapshot]) => {
59924
- this.users.set(userId, snapshot);
59990
+ const sessionId = snapshot.sessionId || userId;
59991
+ this.users.set(sessionId, {
59992
+ ...snapshot,
59993
+ userId: snapshot.userId || sessionId,
59994
+ sessionId,
59995
+ authorUserId: snapshot.authorUserId || null
59996
+ });
59925
59997
  });
59926
59998
  this.subject.publish(this);
59927
59999
  }
59928
60000
  getUsers(boardId, excludeSelf = false) {
59929
60001
  let filteredUsers = Array.from(this.users.values()).filter((user) => user.boardId === boardId && (user.lastPing > Date.now() - PING_CLEANUP || user.lastActivity > Date.now() - PING_CLEANUP));
59930
60002
  if (excludeSelf) {
59931
- const currentUser = localStorage.getItem("currentUser");
59932
- if (currentUser) {
59933
- filteredUsers = filteredUsers.filter((user) => user.userId !== currentUser);
60003
+ const currentSessionId = this.getCurrentSessionId();
60004
+ if (currentSessionId) {
60005
+ filteredUsers = filteredUsers.filter((user) => user.sessionId !== currentSessionId);
59934
60006
  }
59935
60007
  }
59936
- const uniqueUsers = new Map;
59937
- filteredUsers.forEach((user) => {
59938
- const key = user.hardId === null ? Symbol() : user.hardId;
59939
- uniqueUsers.set(key, user);
59940
- });
59941
- return Array.from(uniqueUsers.values());
60008
+ return filteredUsers;
59942
60009
  }
59943
60010
  getColors() {
59944
60011
  return Array.from(this.users.values()).map((user) => user.color);
@@ -59947,8 +60014,12 @@ class Presence {
59947
60014
  if (!this.drawingContext) {
59948
60015
  return;
59949
60016
  }
59950
- const { userId, event: eventData } = event;
59951
- let user = this.users.get(userId);
60017
+ const sessionId = getPresenceSessionId(event);
60018
+ if (!sessionId) {
60019
+ return;
60020
+ }
60021
+ const { event: eventData } = event;
60022
+ let user = this.users.get(sessionId);
59952
60023
  if (!user) {
59953
60024
  let color2 = null;
59954
60025
  const storageColor = localStorage.getItem(`userColor`);
@@ -59959,8 +60030,10 @@ class Presence {
59959
60030
  } else {
59960
60031
  color2 = this.generateUserColor();
59961
60032
  }
59962
- this.users.set(userId.toString(), {
59963
- userId: userId.toString(),
60033
+ this.users.set(sessionId, {
60034
+ userId: sessionId,
60035
+ sessionId,
60036
+ authorUserId: event.authorUserId || null,
59964
60037
  softId: event.softId,
59965
60038
  hardId: event.hardId,
59966
60039
  color: color2,
@@ -59975,7 +60048,7 @@ class Presence {
59975
60048
  boardId: this.board.getBoardId(),
59976
60049
  lastPointerActivity: eventData.timestamp
59977
60050
  });
59978
- user = this.users.get(userId.toString());
60051
+ user = this.users.get(sessionId);
59979
60052
  }
59980
60053
  switch (eventData.method) {
59981
60054
  case "PointerMove":
@@ -60018,6 +60091,9 @@ class Presence {
60018
60091
  if (msg.color) {
60019
60092
  userCopy.color = msg.color;
60020
60093
  }
60094
+ if (msg.authorUserId) {
60095
+ userCopy.authorUserId = msg.authorUserId;
60096
+ }
60021
60097
  userCopy.nickname = msg.nickname;
60022
60098
  userCopy.boardId = msg.boardId;
60023
60099
  if (shouldUpdateActivity) {
@@ -60025,107 +60101,113 @@ class Presence {
60025
60101
  }
60026
60102
  }
60027
60103
  processFollowEvent(msg) {
60028
- const currentUser = localStorage.getItem(`currentUser`);
60029
- if (!currentUser) {
60030
- return;
60031
- }
60032
- if (msg.event.user === currentUser) {
60033
- this.followers.push(msg.userId.toString());
60104
+ if (this.isCurrentSessionTarget(msg.event.user)) {
60105
+ const sessionId = getPresenceSessionId(msg);
60106
+ if (!sessionId) {
60107
+ return;
60108
+ }
60109
+ this.followers.push(sessionId);
60034
60110
  this.followers = Array.from(new Set(this.followers));
60035
60111
  }
60036
60112
  }
60037
60113
  processBringToMe(msg) {
60038
- const currentUser = localStorage.getItem(`currentUser`);
60039
- if (!currentUser) {
60040
- return;
60041
- }
60042
- if (msg.event.users.includes(currentUser)) {
60043
- const bringerId = msg.userId.toString();
60114
+ if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
60115
+ const bringerId = getPresenceSessionId(msg);
60116
+ if (!bringerId) {
60117
+ return;
60118
+ }
60044
60119
  const userToTrack = this.users.get(bringerId);
60045
60120
  if (userToTrack) {
60046
60121
  this.trackedUser = userToTrack;
60047
- this.enableTracking(userToTrack.userId);
60122
+ this.enableTracking(userToTrack.sessionId || userToTrack.userId);
60048
60123
  }
60049
60124
  }
60050
60125
  }
60051
60126
  processStopFollowing(msg) {
60052
- const currentUser = localStorage.getItem(`currentUser`);
60053
- if (!currentUser) {
60127
+ const sessionId = getPresenceSessionId(msg);
60128
+ if (!sessionId) {
60054
60129
  return;
60055
60130
  }
60056
- if (msg.event.users.includes(currentUser)) {
60057
- this.followers = this.followers.filter((follower) => follower !== msg.userId.toString());
60131
+ if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
60132
+ this.followers = this.followers.filter((follower) => follower !== sessionId);
60058
60133
  }
60059
60134
  if (!this.trackedUser) {
60060
60135
  return;
60061
60136
  }
60062
- if (this.trackedUser.userId !== msg.userId) {
60137
+ if (this.trackedUser.sessionId !== sessionId) {
60063
60138
  return;
60064
60139
  }
60065
- if (msg.event.users.includes(currentUser) && this.trackedUser.userId === msg.userId) {
60140
+ if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
60066
60141
  this.disableTracking();
60067
60142
  }
60068
60143
  }
60069
60144
  processPing(msg) {
60070
- const user = this.users.get(msg.userId.toString());
60145
+ const sessionId = getPresenceSessionId(msg);
60146
+ const user = this.users.get(sessionId);
60071
60147
  user.lastPing = msg.event.timestamp;
60072
60148
  const userCopy = { ...user };
60073
60149
  this.updateUserMetaInfo(msg, userCopy, false);
60074
- this.users.set(msg.userId.toString(), userCopy);
60150
+ this.users.set(sessionId, userCopy);
60075
60151
  }
60076
60152
  processCameraEvent(msg) {
60077
- const user = this.users.get(msg.userId.toString());
60153
+ const sessionId = getPresenceSessionId(msg);
60154
+ const user = this.users.get(sessionId);
60078
60155
  const eventData = msg.event;
60079
60156
  const userCopy = { ...user };
60080
60157
  userCopy.camera = eventData;
60081
60158
  this.updateUserMetaInfo(msg, userCopy);
60082
- this.users.set(msg.userId.toString(), userCopy);
60083
- if (this.trackedUser && this.trackedUser.userId === msg.userId.toString()) {
60159
+ this.users.set(sessionId, userCopy);
60160
+ if (this.trackedUser && this.trackedUser.sessionId === sessionId) {
60084
60161
  this.trackedUser.camera = eventData;
60085
60162
  this.board.camera.animateToMatrix(new Matrix(eventData.translateX, eventData.translateY, eventData.scaleX, eventData.scaleY, eventData.shearX, eventData.shearY));
60086
60163
  }
60087
60164
  }
60088
60165
  processDrawSelect(msg) {
60089
- const user = this.users.get(msg.userId.toString());
60166
+ const sessionId = getPresenceSessionId(msg);
60167
+ const user = this.users.get(sessionId);
60090
60168
  const eventData = msg.event;
60091
60169
  const userCopy = { ...user };
60092
60170
  this.updateUserMetaInfo(msg, userCopy);
60093
60171
  userCopy.select = eventData.size;
60094
- this.users.set(msg.userId.toString(), userCopy);
60172
+ this.users.set(sessionId, userCopy);
60095
60173
  }
60096
60174
  processCancelDrawSelect(msg) {
60097
- const user = this.users.get(msg.userId.toString());
60175
+ const sessionId = getPresenceSessionId(msg);
60176
+ const user = this.users.get(sessionId);
60098
60177
  const userCopy = { ...user };
60099
60178
  this.updateUserMetaInfo(msg, userCopy);
60100
60179
  userCopy.select = undefined;
60101
- this.users.set(msg.userId.toString(), userCopy);
60180
+ this.users.set(sessionId, userCopy);
60102
60181
  }
60103
60182
  processPointerMove(msg) {
60104
- const user = this.users.get(msg.userId.toString());
60183
+ const sessionId = getPresenceSessionId(msg);
60184
+ const user = this.users.get(sessionId);
60105
60185
  const eventData = msg.event;
60106
60186
  const userCopy = { ...user };
60107
60187
  this.updateUserMetaInfo(msg, userCopy);
60108
60188
  userCopy.lastPointerActivity = Date.now();
60109
60189
  userCopy.pointer = { x: eventData.position.x, y: eventData.position.y };
60110
- this.users.set(msg.userId.toString(), userCopy);
60190
+ this.users.set(sessionId, userCopy);
60111
60191
  }
60112
60192
  processSelection(msg) {
60113
- const user = this.users.get(msg.userId.toString());
60193
+ const sessionId = getPresenceSessionId(msg);
60194
+ const user = this.users.get(sessionId);
60114
60195
  const eventData = msg.event;
60115
60196
  const userCopy = { ...user };
60116
60197
  this.updateUserMetaInfo(msg, userCopy);
60117
60198
  userCopy.selection = eventData.selectedItems;
60118
- this.users.set(msg.userId.toString(), userCopy);
60199
+ this.users.set(sessionId, userCopy);
60119
60200
  }
60120
60201
  processSetColor(msg) {
60121
- const user = this.users.get(msg.userId.toString());
60202
+ const sessionId = getPresenceSessionId(msg);
60203
+ const user = this.users.get(sessionId);
60122
60204
  const userCopy = { ...user };
60123
60205
  userCopy.colorChangeable = false;
60124
60206
  this.updateUserMetaInfo(msg, userCopy);
60125
- this.users.set(msg.userId.toString(), userCopy);
60207
+ this.users.set(sessionId, userCopy);
60126
60208
  }
60127
- enableTracking(userId) {
60128
- const user = this.users.get(userId);
60209
+ enableTracking(sessionId) {
60210
+ const user = this.users.get(sessionId);
60129
60211
  if (!user) {
60130
60212
  this.trackedUser = null;
60131
60213
  } else {
@@ -60135,7 +60217,7 @@ class Presence {
60135
60217
  }
60136
60218
  this.emit({
60137
60219
  method: "Follow",
60138
- user: userId,
60220
+ user: sessionId,
60139
60221
  timestamp: Date.now()
60140
60222
  });
60141
60223
  }
@@ -60148,7 +60230,7 @@ class Presence {
60148
60230
  this.emit({
60149
60231
  method: "StopFollowing",
60150
60232
  timestamp: Date.now(),
60151
- users: [this.trackedUser?.userId]
60233
+ users: [this.trackedUser.sessionId || this.trackedUser.userId]
60152
60234
  });
60153
60235
  this.trackedUser = null;
60154
60236
  }
@@ -60167,18 +60249,12 @@ class Presence {
60167
60249
  return this.cursorsEnabled;
60168
60250
  }
60169
60251
  getSelects() {
60170
- const uniqueUsers = new Map;
60252
+ const selects = [];
60253
+ const currentSessionId = this.getCurrentSessionId();
60171
60254
  this.users.forEach((user) => {
60172
- if (user.userId !== this.currentUserId) {
60173
- const key = user.hardId !== null ? `hardId:${user.hardId}` : `softId:${user.userId}`;
60174
- const existingUser = uniqueUsers.get(key);
60175
- if (!existingUser || user.lastActivity > existingUser.lastActivity) {
60176
- uniqueUsers.set(key, user);
60177
- }
60255
+ if (currentSessionId && user.sessionId === currentSessionId) {
60256
+ return;
60178
60257
  }
60179
- });
60180
- const selects = [];
60181
- uniqueUsers.forEach((user) => {
60182
60258
  if (user.select && Date.now() - user.lastActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
60183
60259
  selects.push({
60184
60260
  ...user.select,
@@ -60192,42 +60268,29 @@ class Presence {
60192
60268
  getCursors() {
60193
60269
  const currentBoardId = this.board.getBoardId();
60194
60270
  const now = Date.now();
60195
- const uniqueUsers = new Map;
60271
+ const cursors = [];
60272
+ const currentSessionId = this.getCurrentSessionId();
60196
60273
  this.users.forEach((user) => {
60197
- if (user.userId !== this.currentUserId && user.boardId === currentBoardId && now - user.lastPointerActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
60198
- const key = user.hardId !== null ? `hardId:${user.hardId}` : `softId:${user.userId}`;
60199
- const existingUser = uniqueUsers.get(key);
60200
- if (!existingUser || user.lastActivity > existingUser.lastActivity) {
60201
- uniqueUsers.set(key, user);
60202
- }
60274
+ if (currentSessionId !== user.sessionId && user.boardId === currentBoardId && now - user.lastPointerActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
60275
+ cursors.push({
60276
+ ...user.pointer,
60277
+ userId: user.sessionId || user.userId,
60278
+ color: user.color,
60279
+ nickname: user.nickname
60280
+ });
60203
60281
  }
60204
60282
  });
60205
- const cursors = [];
60206
- uniqueUsers.forEach((user) => {
60207
- cursors.push({
60208
- ...user.pointer,
60209
- userId: user.userId,
60210
- color: user.color,
60211
- nickname: user.nickname
60212
- });
60213
- });
60214
60283
  return cursors;
60215
60284
  }
60216
60285
  getSelections() {
60217
60286
  const currentBoardId = this.board.getBoardId();
60218
60287
  const now = Date.now();
60219
- const uniqueUsers = new Map;
60288
+ const selections = [];
60289
+ const currentSessionId = this.getCurrentSessionId();
60220
60290
  this.users.forEach((user) => {
60221
- if (user.userId !== this.currentUserId && user.boardId === currentBoardId && now - user.lastPointerActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
60222
- const key = user.hardId !== null ? `hardId:${user.hardId}` : `softId:${user.userId}`;
60223
- const existingUser = uniqueUsers.get(key);
60224
- if (!existingUser || user.lastActivity > existingUser.lastActivity) {
60225
- uniqueUsers.set(key, user);
60226
- }
60291
+ if (currentSessionId === user.sessionId || user.boardId !== currentBoardId || now - user.lastPointerActivity > CURSORS_IDLE_CLEANUP_DELAY) {
60292
+ return;
60227
60293
  }
60228
- });
60229
- const selections = [];
60230
- uniqueUsers.forEach((user) => {
60231
60294
  if (Date.now() - user.lastActivity >= CURSORS_IDLE_CLEANUP_DELAY) {
60232
60295
  return;
60233
60296
  }