Skip to content

Commit

Permalink
fix(#141): peer verification stability regression
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Dec 5, 2024
1 parent a53eacc commit 8c86140
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/components/Room/usePeerVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const usePeerVerification = ({
// getDisplayUsername).
const [scheduledPeerToVerify, setScheduledPeerToVerify] =
useState<Peer | null>(null)

useEffect(() => {
if (scheduledPeerToVerify === null || isDirectMessageRoom) return

Expand All @@ -143,6 +144,8 @@ export const usePeerVerification = ({
// NOTE: END HACKY WORKAROUND

const verifyPeer = (peer: Peer) => {
if (isDirectMessageRoom) return

setScheduledPeerToVerify(peer)
}

Expand Down
22 changes: 14 additions & 8 deletions src/components/Room/useRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,18 +296,21 @@ export function useRoom(
verificationTimer: null,
}

setPeerList([...peerList, newPeer])
setPeerList(prev => [...prev, newPeer])
sendTypingStatusChange({ isTyping }, peerId)
verifyPeer(newPeer)
} else {
const oldUsername =
peerList[peerIndex].customUsername || getPeerName(userId)
const newUsername = customUsername || getPeerName(userId)

const newPeerList = [...peerList]
const newPeer = { ...newPeerList[peerIndex], userId, customUsername }
newPeerList[peerIndex] = newPeer
setPeerList(newPeerList)
setPeerList(prev => {
const newPeerList = [...prev]
const newPeer = { ...newPeerList[peerIndex], userId, customUsername }
newPeerList[peerIndex] = newPeer

return newPeerList
})

if (oldUsername !== newUsername) {
showAlert(`${oldUsername} is now ${newUsername}`)
Expand Down Expand Up @@ -471,9 +474,12 @@ export function useRoom(
)

if (doesPeerExist) {
const peerListClone = [...peerList]
peerListClone.splice(peerIndex, 1)
setPeerList(peerListClone)
setPeerList(prev => {
const peerListClone = [...prev]
peerListClone.splice(peerIndex, 1)

return peerListClone
})
}
})
}
Expand Down

0 comments on commit 8c86140

Please sign in to comment.