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