style update: .then() to async + await

Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
Timo K
2023-10-10 12:46:12 +02:00
parent fef09ae1aa
commit e4f7a1df19

View File

@@ -143,44 +143,40 @@ export function useLiveKit(
if (room !== undefined && connectionState === ConnectionState.Connected) { if (room !== undefined && connectionState === ConnectionState.Connected) {
const participant = room.localParticipant; const participant = room.localParticipant;
const syncMuteStateAudio = () => { const syncMuteStateAudio = async () => {
if ( if (
participant.isMicrophoneEnabled !== muteStates.audio.enabled && participant.isMicrophoneEnabled !== muteStates.audio.enabled &&
!audioMuteUpdating !audioMuteUpdating
) { ) {
setAudioMuteUpdating(true); setAudioMuteUpdating(true);
participant await participant
.setMicrophoneEnabled(muteStates.audio.enabled) .setMicrophoneEnabled(muteStates.audio.enabled)
.catch((e) => .catch((e) =>
logger.error("Failed to sync audio mute state with LiveKit", e) logger.error("Failed to sync audio mute state with LiveKit", e)
) );
// Run the check again after the change is done. Because the user // Run the check again after the change is done. Because the user
// can update the state (presses mute button) while the device is enabling // can update the state (presses mute button) while the device is enabling
// itself we need might need to update the mute state right away. // itself we need might need to update the mute state right away.
// This async recursion makes sure that setCamera/MicrophoneEnabled is // This async recursion makes sure that setCamera/MicrophoneEnabled is
// called as little times as possible. // called as little times as possible.
.then(() => { setAudioMuteUpdating(false);
setAudioMuteUpdating(false); syncMuteStateAudio();
syncMuteStateAudio();
});
} }
}; };
const syncMuteStateVideo = () => { const syncMuteStateVideo = async () => {
if ( if (
participant.isCameraEnabled !== muteStates.video.enabled && participant.isCameraEnabled !== muteStates.video.enabled &&
!videoMuteUpdating !videoMuteUpdating
) { ) {
setVideoMuteUpdating(true); setVideoMuteUpdating(true);
participant await participant
.setCameraEnabled(muteStates.video.enabled) .setCameraEnabled(muteStates.video.enabled)
.catch((e) => .catch((e) =>
logger.error("Failed to sync video mute state with LiveKit", e) logger.error("Failed to sync video mute state with LiveKit", e)
) );
// see above // see above
.then(() => { setVideoMuteUpdating(false);
setVideoMuteUpdating(false); syncMuteStateVideo();
syncMuteStateVideo();
});
} }
}; };
syncMuteStateAudio(); syncMuteStateAudio();