From 087a52d698a1e65fa702718e81f89fac23a31a85 Mon Sep 17 00:00:00 2001 From: Jessica Mitchell Date: Fri, 18 Feb 2022 17:06:09 -0500 Subject: [PATCH] update with useCallback --- .../components/Call/PeopleAside.js | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/custom/fitness-demo/components/Call/PeopleAside.js b/custom/fitness-demo/components/Call/PeopleAside.js index be9385f..a01853e 100644 --- a/custom/fitness-demo/components/Call/PeopleAside.js +++ b/custom/fitness-demo/components/Call/PeopleAside.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useCallback } from 'react'; import { Aside } from '@custom/shared/components/Aside'; import Button from '@custom/shared/components/Button'; import { useCallState } from '@custom/shared/contexts/CallProvider'; @@ -97,26 +97,32 @@ export const PeopleAside = () => { const { showAside, setShowAside } = useUIState(); const { participants, isOwner } = useParticipants(); + const muteAll = useCallback( + (deviceType) => { + let updatedParticipantList = {}; + // Accommodate muting mics and cameras + const newSetting = + deviceType === 'video' ? { setVideo: false } : { setAudio: false }; + for (let id in callObject.participants()) { + // Do not update the local participant's device (aka the instructor) + if (id === 'local') continue; + + updatedParticipantList[id] = newSetting; + } + + // Update all participants at once + callObject.updateParticipants(updatedParticipantList); + }, + [callObject] + ); + + const handleMuteAllAudio = () => muteAll('audio'); + const handleMuteAllVideo = () => muteAll('video'); + if (!showAside || showAside !== PEOPLE_ASIDE) { return null; } - async function muteAll(deviceType) { - let updatedParticipantList = {}; - // Accommodate muting mics and cameras - const newSetting = - deviceType === 'video' ? { setVideo: false } : { setAudio: false }; - for (let id in callObject.participants()) { - // Do not update the local participant's device (aka the instructor) - if (id === 'local') continue; - - updatedParticipantList[id] = newSetting; - } - - // Update all participants at once - callObject.updateParticipants(updatedParticipantList); - } - return (