From dc0686f5f9e10e2fe85d51f701f6011bae7b5092 Mon Sep 17 00:00:00 2001 From: Mare Cosmin <147330889+Cosmin-Mare@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:40:06 +0300 Subject: [PATCH] Fix bug where room participants wouldn't update (#2420) * Fix bug where participants wouldn't update * add comments --- src/components/codemirror.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/components/codemirror.tsx b/src/components/codemirror.tsx index 3e5da8b40d..c37c7cb455 100644 --- a/src/components/codemirror.tsx +++ b/src/components/codemirror.tsx @@ -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;