From e4f7a1df19c166e36d3ad7b51962f65fd9fa3bdb Mon Sep 17 00:00:00 2001 From: Timo K Date: Tue, 10 Oct 2023 12:46:12 +0200 Subject: [PATCH] style update: .then() to async + await Signed-off-by: Timo K --- src/livekit/useLiveKit.ts | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/livekit/useLiveKit.ts b/src/livekit/useLiveKit.ts index 64645924..40b3660b 100644 --- a/src/livekit/useLiveKit.ts +++ b/src/livekit/useLiveKit.ts @@ -143,44 +143,40 @@ export function useLiveKit( if (room !== undefined && connectionState === ConnectionState.Connected) { const participant = room.localParticipant; - const syncMuteStateAudio = () => { + const syncMuteStateAudio = async () => { if ( participant.isMicrophoneEnabled !== muteStates.audio.enabled && !audioMuteUpdating ) { setAudioMuteUpdating(true); - participant + await participant .setMicrophoneEnabled(muteStates.audio.enabled) .catch((e) => logger.error("Failed to sync audio mute state with LiveKit", e) - ) - // Run the check again after the change is done. Because the user - // can update the state (presses mute button) while the device is enabling - // itself we need might need to update the mute state right away. - // This async recursion makes sure that setCamera/MicrophoneEnabled is - // called as little times as possible. - .then(() => { - setAudioMuteUpdating(false); - syncMuteStateAudio(); - }); + ); + // Run the check again after the change is done. Because the user + // can update the state (presses mute button) while the device is enabling + // itself we need might need to update the mute state right away. + // This async recursion makes sure that setCamera/MicrophoneEnabled is + // called as little times as possible. + setAudioMuteUpdating(false); + syncMuteStateAudio(); } }; - const syncMuteStateVideo = () => { + const syncMuteStateVideo = async () => { if ( participant.isCameraEnabled !== muteStates.video.enabled && !videoMuteUpdating ) { setVideoMuteUpdating(true); - participant + await participant .setCameraEnabled(muteStates.video.enabled) .catch((e) => logger.error("Failed to sync video mute state with LiveKit", e) - ) - // see above - .then(() => { - setVideoMuteUpdating(false); - syncMuteStateVideo(); - }); + ); + // see above + setVideoMuteUpdating(false); + syncMuteStateVideo(); } }; syncMuteStateAudio();