Skip to content

Commit

Permalink
Fix bug where room participants wouldn't update (#2420)
Browse files Browse the repository at this point in the history
* Fix bug where participants wouldn't update

* add comments
  • Loading branch information
Cosmin-Mare authored Oct 9, 2024
1 parent 8cfc6cd commit dc0686f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/codemirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ export default function CodeMirror(props: CodeMirrorProps) {
if(props.roomState)
props.roomState.value = { ...props.roomState?.value, connectionStatus: ConnectionStatus.CONNECTED };
});
// On each update of the awareness(aka whenever a new participant joins/leaves via the awareness state), update the list of participants
provider.awareness.on("update", () => {
let participants: RoomParticipant[] = [];
provider.awareness.getStates().forEach((state) => {
try{
participants.push({
userEmail: state.user.name,
isHost: state.user.host
})
} catch(e){
return // This means that the participant doesn't have an email, which means it's the saving instance so we don't want it to
// be in the list of participants
}
});
if(props.roomState)
props.roomState.value.participants = participants;
})
yDoc.on("update", () => {
if(!props.persistenceState) return;
if (!initialUpdate) return;
Expand Down

0 comments on commit dc0686f

Please sign in to comment.