microboard-temp 0.13.59 → 0.13.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/browser.js +203 -140
- package/dist/cjs/index.js +203 -140
- package/dist/cjs/node.js +203 -140
- package/dist/esm/browser.js +203 -140
- package/dist/esm/index.js +203 -140
- package/dist/esm/node.js +203 -140
- package/dist/types/Events/Events.d.ts +9 -4
- package/dist/types/Events/Log/EventsLog.d.ts +2 -2
- package/dist/types/Events/Log/getRedoRecordFromList.d.ts +1 -1
- package/dist/types/Events/Log/getUndoRecordFromList.d.ts +1 -1
- package/dist/types/Events/Log/shouldSkipEvent.d.ts +1 -1
- package/dist/types/Events/MessageRouter/boardMessageInterface.d.ts +7 -3
- package/dist/types/Events/identity.d.ts +9 -0
- package/dist/types/Presence/Presence.d.ts +7 -4
- package/dist/types/Settings.d.ts +4 -0
- package/package.json +1 -1
package/dist/esm/browser.js
CHANGED
|
@@ -5831,17 +5831,50 @@ function getRecordByIdFromList(id, list) {
|
|
|
5831
5831
|
return;
|
|
5832
5832
|
}
|
|
5833
5833
|
|
|
5834
|
+
// src/Events/identity.ts
|
|
5835
|
+
function getBoardEventSessionId(body) {
|
|
5836
|
+
if (body.sessionId) {
|
|
5837
|
+
return body.sessionId;
|
|
5838
|
+
}
|
|
5839
|
+
if (body.userId === undefined || body.userId === null) {
|
|
5840
|
+
return;
|
|
5841
|
+
}
|
|
5842
|
+
return String(body.userId);
|
|
5843
|
+
}
|
|
5844
|
+
function getConnectionSessionId(connection) {
|
|
5845
|
+
return connection?.getSessionId?.() || connection?.sessionId || String(connection?.connectionId || 0);
|
|
5846
|
+
}
|
|
5847
|
+
function getConnectionSessionIds(connection) {
|
|
5848
|
+
const ids = new Set;
|
|
5849
|
+
const primary = connection?.getSessionId?.() || connection?.sessionId;
|
|
5850
|
+
if (primary) {
|
|
5851
|
+
ids.add(primary);
|
|
5852
|
+
}
|
|
5853
|
+
if (connection?.connectionId !== undefined) {
|
|
5854
|
+
ids.add(String(connection.connectionId));
|
|
5855
|
+
}
|
|
5856
|
+
if (ids.size === 0) {
|
|
5857
|
+
ids.add("0");
|
|
5858
|
+
}
|
|
5859
|
+
return Array.from(ids);
|
|
5860
|
+
}
|
|
5861
|
+
function getConnectionAuthorUserId(connection) {
|
|
5862
|
+
return connection?.getAuthorUserId?.() || connection?.authorUserId || connection?.getCurrentUser?.();
|
|
5863
|
+
}
|
|
5864
|
+
|
|
5834
5865
|
// src/Events/Log/shouldSkipEvent.ts
|
|
5835
|
-
function shouldSkipEvent(record,
|
|
5866
|
+
function shouldSkipEvent(record, sessionIds) {
|
|
5836
5867
|
const { operation } = record.event.body;
|
|
5837
|
-
|
|
5868
|
+
const eventSessionId = getBoardEventSessionId(record.event.body);
|
|
5869
|
+
return eventSessionId === undefined || !sessionIds.includes(eventSessionId) || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
|
|
5838
5870
|
}
|
|
5871
|
+
var init_shouldSkipEvent = () => {};
|
|
5839
5872
|
|
|
5840
5873
|
// src/Events/Log/getRedoRecordFromList.ts
|
|
5841
|
-
function getRedoRecordFromList(
|
|
5874
|
+
function getRedoRecordFromList(sessionIds, list) {
|
|
5842
5875
|
let counter = 0;
|
|
5843
5876
|
for (const record of list.backwardIterable()) {
|
|
5844
|
-
if (shouldSkipEvent(record,
|
|
5877
|
+
if (shouldSkipEvent(record, sessionIds)) {
|
|
5845
5878
|
continue;
|
|
5846
5879
|
}
|
|
5847
5880
|
if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
|
|
@@ -5860,17 +5893,19 @@ function getRedoRecordFromList(userId, list) {
|
|
|
5860
5893
|
}
|
|
5861
5894
|
return null;
|
|
5862
5895
|
}
|
|
5863
|
-
var init_getRedoRecordFromList = () => {
|
|
5896
|
+
var init_getRedoRecordFromList = __esm(() => {
|
|
5897
|
+
init_shouldSkipEvent();
|
|
5898
|
+
});
|
|
5864
5899
|
|
|
5865
5900
|
// src/Events/Log/getUndoRecordFromList.ts
|
|
5866
|
-
function getUndoRecordFromList(
|
|
5901
|
+
function getUndoRecordFromList(sessionIds, list) {
|
|
5867
5902
|
let counter = 0;
|
|
5868
5903
|
const isAllEventsConfirmed = list.isAllEventsConfirmed();
|
|
5869
5904
|
if (!isAllEventsConfirmed) {
|
|
5870
5905
|
return null;
|
|
5871
5906
|
}
|
|
5872
5907
|
for (const record of list.getConfirmedRecords().slice().reverse()) {
|
|
5873
|
-
if (shouldSkipEvent(record,
|
|
5908
|
+
if (shouldSkipEvent(record, sessionIds)) {
|
|
5874
5909
|
continue;
|
|
5875
5910
|
}
|
|
5876
5911
|
if (record.event.body.operation.method === "undo") {
|
|
@@ -5883,7 +5918,9 @@ function getUndoRecordFromList(userId, list) {
|
|
|
5883
5918
|
}
|
|
5884
5919
|
return null;
|
|
5885
5920
|
}
|
|
5886
|
-
var init_getUndoRecordFromList = () => {
|
|
5921
|
+
var init_getUndoRecordFromList = __esm(() => {
|
|
5922
|
+
init_shouldSkipEvent();
|
|
5923
|
+
});
|
|
5887
5924
|
|
|
5888
5925
|
// src/Events/Log/getUnpublishedEventFromList.ts
|
|
5889
5926
|
function getUnpublishedEventFromList(list) {
|
|
@@ -5962,11 +5999,12 @@ function expandEvents(events) {
|
|
|
5962
5999
|
order: event.order,
|
|
5963
6000
|
body: {
|
|
5964
6001
|
eventId: operation.actualId || bodyWithoutOps.eventId,
|
|
6002
|
+
authorUserId: bodyWithoutOps.authorUserId,
|
|
6003
|
+
sessionId: bodyWithoutOps.sessionId,
|
|
5965
6004
|
userId: bodyWithoutOps.userId,
|
|
5966
6005
|
boardId: bodyWithoutOps.boardId,
|
|
5967
6006
|
operation
|
|
5968
6007
|
},
|
|
5969
|
-
userId: bodyWithoutOps.userId,
|
|
5970
6008
|
lastKnownOrder
|
|
5971
6009
|
}));
|
|
5972
6010
|
} else {
|
|
@@ -6085,7 +6123,6 @@ function deserializeAndApplyToList(events, list, board) {
|
|
|
6085
6123
|
const singleEvent = {
|
|
6086
6124
|
order: event.order,
|
|
6087
6125
|
lastKnownOrder,
|
|
6088
|
-
userId: bodyWithoutOps.userId,
|
|
6089
6126
|
body: {
|
|
6090
6127
|
...bodyWithoutOps,
|
|
6091
6128
|
operation: op
|
|
@@ -6172,11 +6209,11 @@ class EventsLog {
|
|
|
6172
6209
|
getUnorderedRecords() {
|
|
6173
6210
|
return this.list.getRecordsToSend().concat(this.list.getNewRecords());
|
|
6174
6211
|
}
|
|
6175
|
-
getUndoRecord(
|
|
6176
|
-
return getUndoRecordFromList(
|
|
6212
|
+
getUndoRecord(sessionIds) {
|
|
6213
|
+
return getUndoRecordFromList(sessionIds, this.list);
|
|
6177
6214
|
}
|
|
6178
|
-
getRedoRecord(
|
|
6179
|
-
return getRedoRecordFromList(
|
|
6215
|
+
getRedoRecord(sessionIds) {
|
|
6216
|
+
return getRedoRecordFromList(sessionIds, this.list);
|
|
6180
6217
|
}
|
|
6181
6218
|
getRecordById(id) {
|
|
6182
6219
|
return getRecordByIdFromList(id, this.list);
|
|
@@ -14190,10 +14227,13 @@ class Events {
|
|
|
14190
14227
|
console.error("[DEBUG] transformMany emitted from Events.emit!", JSON.stringify(operation));
|
|
14191
14228
|
console.trace("[DEBUG] transformMany stack trace");
|
|
14192
14229
|
}
|
|
14193
|
-
const
|
|
14230
|
+
const sessionId = this.getSessionId();
|
|
14231
|
+
const authorUserId = this.getAuthorUserId();
|
|
14194
14232
|
const body = {
|
|
14195
14233
|
eventId: this.getNextEventId(),
|
|
14196
|
-
userId,
|
|
14234
|
+
userId: sessionId,
|
|
14235
|
+
authorUserId,
|
|
14236
|
+
sessionId,
|
|
14197
14237
|
boardId: this.board.getBoardId(),
|
|
14198
14238
|
operation
|
|
14199
14239
|
};
|
|
@@ -14203,7 +14243,7 @@ class Events {
|
|
|
14203
14243
|
command: command || Events.createCommand(this.board, operation)
|
|
14204
14244
|
};
|
|
14205
14245
|
this.log.insertNewLocalEventRecordAfterEmit(record);
|
|
14206
|
-
this.setLatestUserEvent(operation,
|
|
14246
|
+
this.setLatestUserEvent(operation, sessionId);
|
|
14207
14247
|
this.subject.publish(event);
|
|
14208
14248
|
if (this.board.getBoardId().includes("local")) {
|
|
14209
14249
|
if (this.log.saveFileTimeout) {
|
|
@@ -14224,13 +14264,13 @@ class Events {
|
|
|
14224
14264
|
this.emit(operation, cmd);
|
|
14225
14265
|
}
|
|
14226
14266
|
undo() {
|
|
14227
|
-
const
|
|
14228
|
-
const record = this.log.getUndoRecord(
|
|
14267
|
+
const currentSessionIds = this.getSessionIds();
|
|
14268
|
+
const record = this.log.getUndoRecord(currentSessionIds);
|
|
14229
14269
|
if (!record) {
|
|
14230
14270
|
return;
|
|
14231
14271
|
}
|
|
14232
|
-
const { operation,
|
|
14233
|
-
const canUndo = this.canUndoEvent(operation,
|
|
14272
|
+
const { operation, eventId } = record.event.body;
|
|
14273
|
+
const canUndo = this.canUndoEvent(operation, getBoardEventSessionId(record.event.body));
|
|
14234
14274
|
if (!canUndo) {
|
|
14235
14275
|
return;
|
|
14236
14276
|
}
|
|
@@ -14241,8 +14281,8 @@ class Events {
|
|
|
14241
14281
|
});
|
|
14242
14282
|
}
|
|
14243
14283
|
redo() {
|
|
14244
|
-
const
|
|
14245
|
-
const record = this.log.getRedoRecord(
|
|
14284
|
+
const sessionIds = this.getSessionIds();
|
|
14285
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14246
14286
|
if (!record) {
|
|
14247
14287
|
return;
|
|
14248
14288
|
}
|
|
@@ -14253,22 +14293,22 @@ class Events {
|
|
|
14253
14293
|
});
|
|
14254
14294
|
}
|
|
14255
14295
|
canUndo() {
|
|
14256
|
-
const
|
|
14257
|
-
const record = this.log.getUndoRecord(
|
|
14296
|
+
const sessionIds = this.getSessionIds();
|
|
14297
|
+
const record = this.log.getUndoRecord(sessionIds);
|
|
14258
14298
|
if (!record) {
|
|
14259
14299
|
return false;
|
|
14260
14300
|
}
|
|
14261
|
-
return this.canUndoEvent(record.event.body.operation, record.event.body
|
|
14301
|
+
return this.canUndoEvent(record.event.body.operation, getBoardEventSessionId(record.event.body));
|
|
14262
14302
|
}
|
|
14263
14303
|
canRedo() {
|
|
14264
|
-
const
|
|
14265
|
-
const record = this.log.getRedoRecord(
|
|
14304
|
+
const sessionIds = this.getSessionIds();
|
|
14305
|
+
const record = this.log.getRedoRecord(sessionIds);
|
|
14266
14306
|
return record !== null;
|
|
14267
14307
|
}
|
|
14268
14308
|
sendPresenceEvent(event) {
|
|
14269
14309
|
conf.connection.publishPresenceEvent(this.board.getBoardId(), event);
|
|
14270
14310
|
}
|
|
14271
|
-
canUndoEvent(op,
|
|
14311
|
+
canUndoEvent(op, bySessionId) {
|
|
14272
14312
|
if (op.method === "undo") {
|
|
14273
14313
|
return false;
|
|
14274
14314
|
}
|
|
@@ -14278,24 +14318,30 @@ class Events {
|
|
|
14278
14318
|
}
|
|
14279
14319
|
const key = this.getOpKey(op);
|
|
14280
14320
|
const latest = this.latestEvent[key];
|
|
14281
|
-
return
|
|
14321
|
+
return bySessionId === undefined || bySessionId === latest;
|
|
14282
14322
|
}
|
|
14283
|
-
setLatestUserEvent(op,
|
|
14323
|
+
setLatestUserEvent(op, sessionId) {
|
|
14284
14324
|
if (op.class !== "Events" && op.method !== "paste" && op.method !== "duplicate") {
|
|
14285
14325
|
const key = this.getOpKey(op);
|
|
14286
|
-
this.latestEvent[key] =
|
|
14326
|
+
this.latestEvent[key] = sessionId;
|
|
14287
14327
|
}
|
|
14288
14328
|
}
|
|
14289
14329
|
getOpKey(op) {
|
|
14290
14330
|
return op.method;
|
|
14291
14331
|
}
|
|
14292
|
-
|
|
14293
|
-
return this.connection
|
|
14332
|
+
getSessionId() {
|
|
14333
|
+
return getConnectionSessionId(this.connection);
|
|
14334
|
+
}
|
|
14335
|
+
getSessionIds() {
|
|
14336
|
+
return getConnectionSessionIds(this.connection);
|
|
14337
|
+
}
|
|
14338
|
+
getAuthorUserId() {
|
|
14339
|
+
return getConnectionAuthorUserId(this.connection);
|
|
14294
14340
|
}
|
|
14295
14341
|
getNextEventId() {
|
|
14296
14342
|
const id = ++this.eventCounter;
|
|
14297
|
-
const
|
|
14298
|
-
return
|
|
14343
|
+
const sessionId = this.getSessionId();
|
|
14344
|
+
return sessionId + ":" + id;
|
|
14299
14345
|
}
|
|
14300
14346
|
}
|
|
14301
14347
|
function createEvents(board, connection, lastIndex) {
|
|
@@ -55528,9 +55574,9 @@ function handleBoardEventMessage(message, board) {
|
|
|
55528
55574
|
if (event.order <= log.getLastIndex()) {
|
|
55529
55575
|
return;
|
|
55530
55576
|
}
|
|
55531
|
-
const
|
|
55532
|
-
const currentConnectionId = board.events.connection
|
|
55533
|
-
const isEventFromCurrentUser =
|
|
55577
|
+
const eventSessionId = getBoardEventSessionId(event.body);
|
|
55578
|
+
const currentConnectionId = getConnectionSessionId(board.events.connection);
|
|
55579
|
+
const isEventFromCurrentUser = eventSessionId !== undefined && eventSessionId === currentConnectionId;
|
|
55534
55580
|
if (isEventFromCurrentUser) {
|
|
55535
55581
|
return;
|
|
55536
55582
|
}
|
|
@@ -55544,6 +55590,7 @@ function handleBoardEventMessage(message, board) {
|
|
|
55544
55590
|
board.events.subject.publish(last);
|
|
55545
55591
|
}
|
|
55546
55592
|
}
|
|
55593
|
+
var init_handleBoardEventMessage = () => {};
|
|
55547
55594
|
|
|
55548
55595
|
// src/Events/MessageRouter/handleBoardSubscriptionCompletedMsg.ts
|
|
55549
55596
|
function handleBoardSubscriptionCompletedMsg(msg, board) {
|
|
@@ -55652,8 +55699,7 @@ function sendBoardEvent(board, batch, sequenceNumber) {
|
|
|
55652
55699
|
type: "BoardEvent",
|
|
55653
55700
|
boardId: board.getBoardId(),
|
|
55654
55701
|
event: toSend,
|
|
55655
|
-
sequenceNumber
|
|
55656
|
-
userId: conf.connection.getCurrentUser()
|
|
55702
|
+
sequenceNumber
|
|
55657
55703
|
});
|
|
55658
55704
|
const date = Date.now();
|
|
55659
55705
|
log.pendingEvent = {
|
|
@@ -55789,6 +55835,7 @@ function handleUserJoinMessage(message, board) {
|
|
|
55789
55835
|
var messageRouter;
|
|
55790
55836
|
var init_messageRouter = __esm(() => {
|
|
55791
55837
|
init_handleAiChatMassage();
|
|
55838
|
+
init_handleBoardEventMessage();
|
|
55792
55839
|
init_handleBoardSubscriptionCompletedMsg();
|
|
55793
55840
|
init_handleConfirmation();
|
|
55794
55841
|
init_handleCreateSnapshotRequestMessage();
|
|
@@ -57063,6 +57110,15 @@ var PRESENCE_CLEANUP_USER_TIMER = 180000;
|
|
|
57063
57110
|
var PRESENCE_CLEANUP_IDLE_TIMER = 60000;
|
|
57064
57111
|
var CURSORS_IDLE_CLEANUP_DELAY = 1e4;
|
|
57065
57112
|
var PING_CLEANUP = 15000;
|
|
57113
|
+
function getPresenceSessionId(message) {
|
|
57114
|
+
if (message.sessionId) {
|
|
57115
|
+
return message.sessionId;
|
|
57116
|
+
}
|
|
57117
|
+
if (message.userId === undefined || message.userId === null) {
|
|
57118
|
+
return;
|
|
57119
|
+
}
|
|
57120
|
+
return String(message.userId);
|
|
57121
|
+
}
|
|
57066
57122
|
var cleanupInterval = null;
|
|
57067
57123
|
|
|
57068
57124
|
class Presence {
|
|
@@ -57072,7 +57128,6 @@ class Presence {
|
|
|
57072
57128
|
trackedUser = null;
|
|
57073
57129
|
cursorsEnabled = true;
|
|
57074
57130
|
drawingContext = null;
|
|
57075
|
-
currentUserId = null;
|
|
57076
57131
|
users = new Map;
|
|
57077
57132
|
followers = [];
|
|
57078
57133
|
svgImageCache = {};
|
|
@@ -57098,7 +57153,7 @@ class Presence {
|
|
|
57098
57153
|
throttleSelectionEvent(this.board.selection);
|
|
57099
57154
|
});
|
|
57100
57155
|
if (typeof window !== "undefined") {
|
|
57101
|
-
window.addEventListener("storage", this.
|
|
57156
|
+
window.addEventListener("storage", this.onStorageChange);
|
|
57102
57157
|
}
|
|
57103
57158
|
}
|
|
57104
57159
|
clear() {
|
|
@@ -57137,19 +57192,30 @@ class Presence {
|
|
|
57137
57192
|
}
|
|
57138
57193
|
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));
|
|
57139
57194
|
}
|
|
57140
|
-
|
|
57141
|
-
|
|
57195
|
+
onStorageChange = (_event) => {};
|
|
57196
|
+
getCurrentSessionId() {
|
|
57197
|
+
return this.events?.connection?.getSessionId?.() || this.events?.connection?.sessionId || null;
|
|
57142
57198
|
}
|
|
57143
|
-
|
|
57144
|
-
if (
|
|
57145
|
-
|
|
57146
|
-
this.setCurrentUser(event.newValue);
|
|
57147
|
-
}
|
|
57199
|
+
getLegacyCurrentUserId() {
|
|
57200
|
+
if (typeof localStorage === "undefined") {
|
|
57201
|
+
return null;
|
|
57148
57202
|
}
|
|
57203
|
+
return localStorage.getItem("currentUser");
|
|
57204
|
+
}
|
|
57205
|
+
isCurrentSessionTarget(value) {
|
|
57206
|
+
if (value === undefined || value === null) {
|
|
57207
|
+
return false;
|
|
57208
|
+
}
|
|
57209
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57210
|
+
if (currentSessionId && String(value) === currentSessionId) {
|
|
57211
|
+
return true;
|
|
57212
|
+
}
|
|
57213
|
+
const currentUser = this.getLegacyCurrentUserId();
|
|
57214
|
+
return currentUser !== null && String(value) === currentUser;
|
|
57149
57215
|
}
|
|
57150
57216
|
cleanup() {
|
|
57151
57217
|
if (typeof window !== "undefined") {
|
|
57152
|
-
window.removeEventListener("storage", this.
|
|
57218
|
+
window.removeEventListener("storage", this.onStorageChange);
|
|
57153
57219
|
}
|
|
57154
57220
|
this.drawingContext = null;
|
|
57155
57221
|
this.clear();
|
|
@@ -57189,24 +57255,25 @@ class Presence {
|
|
|
57189
57255
|
}
|
|
57190
57256
|
join(msg) {
|
|
57191
57257
|
Object.entries(msg.snapshots).map(([userId, snapshot]) => {
|
|
57192
|
-
|
|
57258
|
+
const sessionId = snapshot.sessionId || userId;
|
|
57259
|
+
this.users.set(sessionId, {
|
|
57260
|
+
...snapshot,
|
|
57261
|
+
userId: snapshot.userId || sessionId,
|
|
57262
|
+
sessionId,
|
|
57263
|
+
authorUserId: snapshot.authorUserId || null
|
|
57264
|
+
});
|
|
57193
57265
|
});
|
|
57194
57266
|
this.subject.publish(this);
|
|
57195
57267
|
}
|
|
57196
57268
|
getUsers(boardId, excludeSelf = false) {
|
|
57197
57269
|
let filteredUsers = Array.from(this.users.values()).filter((user) => user.boardId === boardId && (user.lastPing > Date.now() - PING_CLEANUP || user.lastActivity > Date.now() - PING_CLEANUP));
|
|
57198
57270
|
if (excludeSelf) {
|
|
57199
|
-
const
|
|
57200
|
-
if (
|
|
57201
|
-
filteredUsers = filteredUsers.filter((user) => user.
|
|
57271
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57272
|
+
if (currentSessionId) {
|
|
57273
|
+
filteredUsers = filteredUsers.filter((user) => user.sessionId !== currentSessionId);
|
|
57202
57274
|
}
|
|
57203
57275
|
}
|
|
57204
|
-
|
|
57205
|
-
filteredUsers.forEach((user) => {
|
|
57206
|
-
const key = user.hardId === null ? Symbol() : user.hardId;
|
|
57207
|
-
uniqueUsers.set(key, user);
|
|
57208
|
-
});
|
|
57209
|
-
return Array.from(uniqueUsers.values());
|
|
57276
|
+
return filteredUsers;
|
|
57210
57277
|
}
|
|
57211
57278
|
getColors() {
|
|
57212
57279
|
return Array.from(this.users.values()).map((user) => user.color);
|
|
@@ -57215,8 +57282,12 @@ class Presence {
|
|
|
57215
57282
|
if (!this.drawingContext) {
|
|
57216
57283
|
return;
|
|
57217
57284
|
}
|
|
57218
|
-
const
|
|
57219
|
-
|
|
57285
|
+
const sessionId = getPresenceSessionId(event);
|
|
57286
|
+
if (!sessionId) {
|
|
57287
|
+
return;
|
|
57288
|
+
}
|
|
57289
|
+
const { event: eventData } = event;
|
|
57290
|
+
let user = this.users.get(sessionId);
|
|
57220
57291
|
if (!user) {
|
|
57221
57292
|
let color2 = null;
|
|
57222
57293
|
const storageColor = localStorage.getItem(`userColor`);
|
|
@@ -57227,8 +57298,10 @@ class Presence {
|
|
|
57227
57298
|
} else {
|
|
57228
57299
|
color2 = this.generateUserColor();
|
|
57229
57300
|
}
|
|
57230
|
-
this.users.set(
|
|
57231
|
-
userId:
|
|
57301
|
+
this.users.set(sessionId, {
|
|
57302
|
+
userId: sessionId,
|
|
57303
|
+
sessionId,
|
|
57304
|
+
authorUserId: event.authorUserId || null,
|
|
57232
57305
|
softId: event.softId,
|
|
57233
57306
|
hardId: event.hardId,
|
|
57234
57307
|
color: color2,
|
|
@@ -57243,7 +57316,7 @@ class Presence {
|
|
|
57243
57316
|
boardId: this.board.getBoardId(),
|
|
57244
57317
|
lastPointerActivity: eventData.timestamp
|
|
57245
57318
|
});
|
|
57246
|
-
user = this.users.get(
|
|
57319
|
+
user = this.users.get(sessionId);
|
|
57247
57320
|
}
|
|
57248
57321
|
switch (eventData.method) {
|
|
57249
57322
|
case "PointerMove":
|
|
@@ -57286,6 +57359,9 @@ class Presence {
|
|
|
57286
57359
|
if (msg.color) {
|
|
57287
57360
|
userCopy.color = msg.color;
|
|
57288
57361
|
}
|
|
57362
|
+
if (msg.authorUserId) {
|
|
57363
|
+
userCopy.authorUserId = msg.authorUserId;
|
|
57364
|
+
}
|
|
57289
57365
|
userCopy.nickname = msg.nickname;
|
|
57290
57366
|
userCopy.boardId = msg.boardId;
|
|
57291
57367
|
if (shouldUpdateActivity) {
|
|
@@ -57293,107 +57369,113 @@ class Presence {
|
|
|
57293
57369
|
}
|
|
57294
57370
|
}
|
|
57295
57371
|
processFollowEvent(msg) {
|
|
57296
|
-
|
|
57297
|
-
|
|
57298
|
-
|
|
57299
|
-
|
|
57300
|
-
|
|
57301
|
-
this.followers.push(
|
|
57372
|
+
if (this.isCurrentSessionTarget(msg.event.user)) {
|
|
57373
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57374
|
+
if (!sessionId) {
|
|
57375
|
+
return;
|
|
57376
|
+
}
|
|
57377
|
+
this.followers.push(sessionId);
|
|
57302
57378
|
this.followers = Array.from(new Set(this.followers));
|
|
57303
57379
|
}
|
|
57304
57380
|
}
|
|
57305
57381
|
processBringToMe(msg) {
|
|
57306
|
-
|
|
57307
|
-
|
|
57308
|
-
|
|
57309
|
-
|
|
57310
|
-
|
|
57311
|
-
const bringerId = msg.userId.toString();
|
|
57382
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57383
|
+
const bringerId = getPresenceSessionId(msg);
|
|
57384
|
+
if (!bringerId) {
|
|
57385
|
+
return;
|
|
57386
|
+
}
|
|
57312
57387
|
const userToTrack = this.users.get(bringerId);
|
|
57313
57388
|
if (userToTrack) {
|
|
57314
57389
|
this.trackedUser = userToTrack;
|
|
57315
|
-
this.enableTracking(userToTrack.userId);
|
|
57390
|
+
this.enableTracking(userToTrack.sessionId || userToTrack.userId);
|
|
57316
57391
|
}
|
|
57317
57392
|
}
|
|
57318
57393
|
}
|
|
57319
57394
|
processStopFollowing(msg) {
|
|
57320
|
-
const
|
|
57321
|
-
if (!
|
|
57395
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57396
|
+
if (!sessionId) {
|
|
57322
57397
|
return;
|
|
57323
57398
|
}
|
|
57324
|
-
if (msg.event.users.
|
|
57325
|
-
this.followers = this.followers.filter((follower) => follower !==
|
|
57399
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57400
|
+
this.followers = this.followers.filter((follower) => follower !== sessionId);
|
|
57326
57401
|
}
|
|
57327
57402
|
if (!this.trackedUser) {
|
|
57328
57403
|
return;
|
|
57329
57404
|
}
|
|
57330
|
-
if (this.trackedUser.
|
|
57405
|
+
if (this.trackedUser.sessionId !== sessionId) {
|
|
57331
57406
|
return;
|
|
57332
57407
|
}
|
|
57333
|
-
if (msg.event.users.
|
|
57408
|
+
if (msg.event.users.some((user) => this.isCurrentSessionTarget(user))) {
|
|
57334
57409
|
this.disableTracking();
|
|
57335
57410
|
}
|
|
57336
57411
|
}
|
|
57337
57412
|
processPing(msg) {
|
|
57338
|
-
const
|
|
57413
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57414
|
+
const user = this.users.get(sessionId);
|
|
57339
57415
|
user.lastPing = msg.event.timestamp;
|
|
57340
57416
|
const userCopy = { ...user };
|
|
57341
57417
|
this.updateUserMetaInfo(msg, userCopy, false);
|
|
57342
|
-
this.users.set(
|
|
57418
|
+
this.users.set(sessionId, userCopy);
|
|
57343
57419
|
}
|
|
57344
57420
|
processCameraEvent(msg) {
|
|
57345
|
-
const
|
|
57421
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57422
|
+
const user = this.users.get(sessionId);
|
|
57346
57423
|
const eventData = msg.event;
|
|
57347
57424
|
const userCopy = { ...user };
|
|
57348
57425
|
userCopy.camera = eventData;
|
|
57349
57426
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57350
|
-
this.users.set(
|
|
57351
|
-
if (this.trackedUser && this.trackedUser.
|
|
57427
|
+
this.users.set(sessionId, userCopy);
|
|
57428
|
+
if (this.trackedUser && this.trackedUser.sessionId === sessionId) {
|
|
57352
57429
|
this.trackedUser.camera = eventData;
|
|
57353
57430
|
this.board.camera.animateToMatrix(new Matrix(eventData.translateX, eventData.translateY, eventData.scaleX, eventData.scaleY, eventData.shearX, eventData.shearY));
|
|
57354
57431
|
}
|
|
57355
57432
|
}
|
|
57356
57433
|
processDrawSelect(msg) {
|
|
57357
|
-
const
|
|
57434
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57435
|
+
const user = this.users.get(sessionId);
|
|
57358
57436
|
const eventData = msg.event;
|
|
57359
57437
|
const userCopy = { ...user };
|
|
57360
57438
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57361
57439
|
userCopy.select = eventData.size;
|
|
57362
|
-
this.users.set(
|
|
57440
|
+
this.users.set(sessionId, userCopy);
|
|
57363
57441
|
}
|
|
57364
57442
|
processCancelDrawSelect(msg) {
|
|
57365
|
-
const
|
|
57443
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57444
|
+
const user = this.users.get(sessionId);
|
|
57366
57445
|
const userCopy = { ...user };
|
|
57367
57446
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57368
57447
|
userCopy.select = undefined;
|
|
57369
|
-
this.users.set(
|
|
57448
|
+
this.users.set(sessionId, userCopy);
|
|
57370
57449
|
}
|
|
57371
57450
|
processPointerMove(msg) {
|
|
57372
|
-
const
|
|
57451
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57452
|
+
const user = this.users.get(sessionId);
|
|
57373
57453
|
const eventData = msg.event;
|
|
57374
57454
|
const userCopy = { ...user };
|
|
57375
57455
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57376
57456
|
userCopy.lastPointerActivity = Date.now();
|
|
57377
57457
|
userCopy.pointer = { x: eventData.position.x, y: eventData.position.y };
|
|
57378
|
-
this.users.set(
|
|
57458
|
+
this.users.set(sessionId, userCopy);
|
|
57379
57459
|
}
|
|
57380
57460
|
processSelection(msg) {
|
|
57381
|
-
const
|
|
57461
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57462
|
+
const user = this.users.get(sessionId);
|
|
57382
57463
|
const eventData = msg.event;
|
|
57383
57464
|
const userCopy = { ...user };
|
|
57384
57465
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57385
57466
|
userCopy.selection = eventData.selectedItems;
|
|
57386
|
-
this.users.set(
|
|
57467
|
+
this.users.set(sessionId, userCopy);
|
|
57387
57468
|
}
|
|
57388
57469
|
processSetColor(msg) {
|
|
57389
|
-
const
|
|
57470
|
+
const sessionId = getPresenceSessionId(msg);
|
|
57471
|
+
const user = this.users.get(sessionId);
|
|
57390
57472
|
const userCopy = { ...user };
|
|
57391
57473
|
userCopy.colorChangeable = false;
|
|
57392
57474
|
this.updateUserMetaInfo(msg, userCopy);
|
|
57393
|
-
this.users.set(
|
|
57475
|
+
this.users.set(sessionId, userCopy);
|
|
57394
57476
|
}
|
|
57395
|
-
enableTracking(
|
|
57396
|
-
const user = this.users.get(
|
|
57477
|
+
enableTracking(sessionId) {
|
|
57478
|
+
const user = this.users.get(sessionId);
|
|
57397
57479
|
if (!user) {
|
|
57398
57480
|
this.trackedUser = null;
|
|
57399
57481
|
} else {
|
|
@@ -57403,7 +57485,7 @@ class Presence {
|
|
|
57403
57485
|
}
|
|
57404
57486
|
this.emit({
|
|
57405
57487
|
method: "Follow",
|
|
57406
|
-
user:
|
|
57488
|
+
user: sessionId,
|
|
57407
57489
|
timestamp: Date.now()
|
|
57408
57490
|
});
|
|
57409
57491
|
}
|
|
@@ -57416,7 +57498,7 @@ class Presence {
|
|
|
57416
57498
|
this.emit({
|
|
57417
57499
|
method: "StopFollowing",
|
|
57418
57500
|
timestamp: Date.now(),
|
|
57419
|
-
users: [this.trackedUser
|
|
57501
|
+
users: [this.trackedUser.sessionId || this.trackedUser.userId]
|
|
57420
57502
|
});
|
|
57421
57503
|
this.trackedUser = null;
|
|
57422
57504
|
}
|
|
@@ -57435,18 +57517,12 @@ class Presence {
|
|
|
57435
57517
|
return this.cursorsEnabled;
|
|
57436
57518
|
}
|
|
57437
57519
|
getSelects() {
|
|
57438
|
-
const
|
|
57520
|
+
const selects = [];
|
|
57521
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57439
57522
|
this.users.forEach((user) => {
|
|
57440
|
-
if (user.
|
|
57441
|
-
|
|
57442
|
-
const existingUser = uniqueUsers.get(key);
|
|
57443
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
57444
|
-
uniqueUsers.set(key, user);
|
|
57445
|
-
}
|
|
57523
|
+
if (currentSessionId && user.sessionId === currentSessionId) {
|
|
57524
|
+
return;
|
|
57446
57525
|
}
|
|
57447
|
-
});
|
|
57448
|
-
const selects = [];
|
|
57449
|
-
uniqueUsers.forEach((user) => {
|
|
57450
57526
|
if (user.select && Date.now() - user.lastActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57451
57527
|
selects.push({
|
|
57452
57528
|
...user.select,
|
|
@@ -57460,42 +57536,29 @@ class Presence {
|
|
|
57460
57536
|
getCursors() {
|
|
57461
57537
|
const currentBoardId = this.board.getBoardId();
|
|
57462
57538
|
const now = Date.now();
|
|
57463
|
-
const
|
|
57539
|
+
const cursors = [];
|
|
57540
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57464
57541
|
this.users.forEach((user) => {
|
|
57465
|
-
if (
|
|
57466
|
-
|
|
57467
|
-
|
|
57468
|
-
|
|
57469
|
-
|
|
57470
|
-
|
|
57542
|
+
if (currentSessionId !== user.sessionId && user.boardId === currentBoardId && now - user.lastPointerActivity <= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57543
|
+
cursors.push({
|
|
57544
|
+
...user.pointer,
|
|
57545
|
+
userId: user.sessionId || user.userId,
|
|
57546
|
+
color: user.color,
|
|
57547
|
+
nickname: user.nickname
|
|
57548
|
+
});
|
|
57471
57549
|
}
|
|
57472
57550
|
});
|
|
57473
|
-
const cursors = [];
|
|
57474
|
-
uniqueUsers.forEach((user) => {
|
|
57475
|
-
cursors.push({
|
|
57476
|
-
...user.pointer,
|
|
57477
|
-
userId: user.userId,
|
|
57478
|
-
color: user.color,
|
|
57479
|
-
nickname: user.nickname
|
|
57480
|
-
});
|
|
57481
|
-
});
|
|
57482
57551
|
return cursors;
|
|
57483
57552
|
}
|
|
57484
57553
|
getSelections() {
|
|
57485
57554
|
const currentBoardId = this.board.getBoardId();
|
|
57486
57555
|
const now = Date.now();
|
|
57487
|
-
const
|
|
57556
|
+
const selections = [];
|
|
57557
|
+
const currentSessionId = this.getCurrentSessionId();
|
|
57488
57558
|
this.users.forEach((user) => {
|
|
57489
|
-
if (
|
|
57490
|
-
|
|
57491
|
-
const existingUser = uniqueUsers.get(key);
|
|
57492
|
-
if (!existingUser || user.lastActivity > existingUser.lastActivity) {
|
|
57493
|
-
uniqueUsers.set(key, user);
|
|
57494
|
-
}
|
|
57559
|
+
if (currentSessionId === user.sessionId || user.boardId !== currentBoardId || now - user.lastPointerActivity > CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57560
|
+
return;
|
|
57495
57561
|
}
|
|
57496
|
-
});
|
|
57497
|
-
const selections = [];
|
|
57498
|
-
uniqueUsers.forEach((user) => {
|
|
57499
57562
|
if (Date.now() - user.lastActivity >= CURSORS_IDLE_CLEANUP_DELAY) {
|
|
57500
57563
|
return;
|
|
57501
57564
|
}
|