Closed lichin-lin closed 2 years ago
If you're using Liveblocks I'd recommend this improvement we made in our app vs the example code for tracking active users:
liveBlocks.subscribe('others', (others, event) => {
if (event.type === 'leave') {
if (event.user.presence) {
app.removeUser(event.user.presence.id);
}
} else {
app.updateUsers(
others.map((p) => p.presence)
);
}
})
Assuming you're storing TLDraw user data directly in Liveblocks presence, presence.id
will be the TLDraw user ID.
By listening explicitly for Liveblocks user leave events, which are delivered reliably, you can drop the beforeunload
handlers and the use of broadcast events to tell peers you're leaving.
Hi @lichin-lin , this seems to be fixed, could you test it again please, if it's working for you, please close the issue! thanks
I think this issue still occurs, and it's quite easily to reproduce:
It appears because you're on the same browser, I tried it on a different browser
I've also tested with different browsers, but still get the same issue:
that's weird, can you try deleting the cache? and the retry please, let me know if the bugs still occur
Yes, I've tried cleaning the cache, and use incognito to test the behavior, sadly, this issue still happens. 😢
okay, I can reproduce it now! I'll try to fix it
the problem was the user presence was never deleted when they exit or leave so that's why there are many cursor because the user presence before he leaves is never deleted
@lichin-lin can you try with this link if it's working, please? link preview tldraw
yes!! it's working perfectly!
okay it's merged, can you close this issue now @lichin-lin please ? thanks
First of all, thanks for making the multiplayer feature, it works in most cases!
Here is one bug I found: If you try to refresh a tab with an element selected, somehow the
removeuser
function inuseMultiplayerState.ts
will not be triggered, so in other user's views, they will see more and more cursors show up (but actually, they all indicate the same user.)I am not sure if this has to do with how Liveblock sends the event to a room, or, we didn't really clean up the userID in our storage so that we can't show the correct amount of cursor in a room 🙌
https://user-images.githubusercontent.com/10290616/154104177-8a26a71b-d30f-48c0-bd48-afdd73ed907f.mov