feat: filter disconnected users

This commit is contained in:
Arnošt Pleskot 2023-07-13 10:07:31 +02:00
parent db5149ab5d
commit 4608e809b1
No known key found for this signature in database
4 changed files with 13 additions and 10 deletions

View File

@ -882,17 +882,12 @@ class Collab extends PureComponent<Props, CollabState> {
};
setCollaborators(sockets: string[]) {
const collaborators: InstanceType<typeof Collab>["collaborators"] =
new Map();
for (const socketId of sockets) {
if (this.collaborators.has(socketId)) {
collaborators.set(socketId, this.collaborators.get(socketId)!);
} else {
collaborators.set(socketId, {});
this.collaborators.forEach((value, key) => {
if (value.socketId && !sockets.includes(value.socketId)) {
this.collaborators.delete(key);
}
}
this.collaborators = collaborators;
this.excalidrawAPI.updateScene({ collaborators });
});
this.excalidrawAPI.updateScene({ collaborators: this.collaborators });
}
public setLastBroadcastedOrReceivedSceneVersion = (version: number) => {

View File

@ -74,6 +74,9 @@ class Portal {
/* syncAll */ true,
);
});
this.socket.on("room-user-change", (clients: string[]) => {
this.collab.setCollaborators(clients);
});
}
isOpen() {
@ -193,6 +196,7 @@ class Portal {
userState,
username: this.collab.state.username,
userId: this.collab.state.userId,
socketId: this.socket.id,
},
};
return this._broadcastSocketData(
@ -216,6 +220,7 @@ class Portal {
this.collab.excalidrawAPI.getAppState().selectedElementIds,
username: this.collab.state.username,
userId: this.collab.state.userId,
socketId: this.socket.id,
},
};
return this._broadcastSocketData(

View File

@ -111,6 +111,7 @@ export type SocketUpdateDataSource = {
selectedElementIds: AppState["selectedElementIds"];
username: string;
userId: string;
socketId: string;
};
};
IDLE_STATUS: {
@ -119,6 +120,7 @@ export type SocketUpdateDataSource = {
userState: UserIdleState;
username: string;
userId: string;
socketId: string;
};
};
};

View File

@ -55,6 +55,7 @@ export type Collaborator = {
avatarUrl?: string;
// user id. If supplied, we'll filter out duplicates when rendering user avatars.
id?: string;
socketId?: string;
};
export type DataURL = string & { _brand: "DataURL" };