From 23763422d88f8c73a46b03c609d016c627e3a40b Mon Sep 17 00:00:00 2001 From: Robert Long Date: Thu, 26 Aug 2021 11:10:49 -0700 Subject: [PATCH] Put presenter state in conference manager --- src/ConferenceCallManager.js | 14 ++++++++++++++ src/ConferenceCallManagerHooks.js | 13 +++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ConferenceCallManager.js b/src/ConferenceCallManager.js index d608b07..99c7c72 100644 --- a/src/ConferenceCallManager.js +++ b/src/ConferenceCallManager.js @@ -247,6 +247,7 @@ export class ConferenceCallManager extends EventEmitter { stream, audioMuted: this.audioMuted, videoMuted: this.videoMuted, + presenter: false, }; this.participants.push(this.localParticipant); @@ -400,6 +401,17 @@ export class ConferenceCallManager extends EventEmitter { this.emit("participants_changed"); } + setPresenter(userId, presenter) { + const participant = this.participants.find( + (participant) => participant.userId === userId + ); + + if (participant) { + participant.presenter = presenter; + this.emit("participants_changed"); + } + } + logout() { localStorage.removeItem("matrix-auth-store"); } @@ -533,6 +545,7 @@ export class ConferenceCallManager extends EventEmitter { stream, audioMuted, videoMuted, + presenter: false, }; this.participants.push(participant); } @@ -632,6 +645,7 @@ export class ConferenceCallManager extends EventEmitter { stream: null, audioMuted: false, videoMuted: false, + presenter: false, }; // TODO: Should we wait until the call has been answered to push the participant? // Or do we hide the participant until their stream is live? diff --git a/src/ConferenceCallManagerHooks.js b/src/ConferenceCallManagerHooks.js index 145fec7..eaedfac 100644 --- a/src/ConferenceCallManagerHooks.js +++ b/src/ConferenceCallManagerHooks.js @@ -340,16 +340,13 @@ export function useVideoRoom(manager, roomId, timeout = 5000) { }, [manager]); const togglePresenter = useCallback((selectedParticipant) => { + manager.setPresenter( + selectedParticipant.userId, + !selectedParticipant.presenter + ); setState((prevState) => ({ ...prevState, - participants: prevState.participants.map((participant) => - participant === selectedParticipant - ? { - ...participant, - presenter: !participant.presenter, - } - : participant - ), + participants: [...manager.participants], })); }, []);