perf: multiple Tab for the same user lead to duplicate joining issues
This commit is contained in:
parent
e9e73bd128
commit
420586839a
1 changed files with 22 additions and 14 deletions
|
@ -281,11 +281,19 @@ const RoomDomain = Remesh.domain({
|
|||
const commandEvent$ = (() => {
|
||||
switch (message.type) {
|
||||
case SendType.UserSync: {
|
||||
const self = get(UserListQuery()).find((user) => user.peerId === peerRoom.peerId)!
|
||||
const isJoining = self.joinTime < message.joinTime
|
||||
return of(
|
||||
const userList = get(UserListQuery())
|
||||
const selfUser = userList.find((user) => user.peerId === peerRoom.peerId)!
|
||||
// If the browser has multiple tabs open, it can cause the same user to join multiple times with the same peerId but different userId
|
||||
const isSelfJoinEvent = !!userList.find((user) => user.userId === message.userId)
|
||||
// When a new user joins, it triggers join events for all users, i.e., newUser join event and oldUser join event
|
||||
// Use joinTime to determine if it's a new user
|
||||
const isNewJoinEvent = selfUser.joinTime < message.joinTime
|
||||
|
||||
return isSelfJoinEvent
|
||||
? EMPTY
|
||||
: of(
|
||||
UpdateUserListCommand({ type: 'create', user: message }),
|
||||
isJoining
|
||||
isNewJoinEvent
|
||||
? messageListDomain.command.CreateItemCommand({
|
||||
...message,
|
||||
id: nanoid(),
|
||||
|
|
Loading…
Reference in a new issue