From 64fee07dce6e210ec10176b04dd24049404de525 Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Tue, 25 Apr 2023 11:04:21 +0800 Subject: [PATCH] refactor: leave voice --- src/common/component/Voice.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/component/Voice.tsx b/src/common/component/Voice.tsx index e73d43ba..b55ef91f 100644 --- a/src/common/component/Voice.tsx +++ b/src/common/component/Voice.tsx @@ -227,15 +227,17 @@ const useVoice = ({ id, context = "channel" }: VoiceProps) => { const leave = async () => { const localAudioTrack = window.VOICE_TRACK_MAP[loginUid] as IMicrophoneAudioTrack; const localVideoTrack = window.VIDEO_TRACK_MAP[loginUid] as ICameraVideoTrack; - if (window.VOICE_CLIENT && localAudioTrack) { - localAudioTrack.close(); - window.VOICE_TRACK_MAP[loginUid] = null; + if (window.VOICE_CLIENT) { + await window.VOICE_CLIENT.leave(); + dispatch(updateVoicingInfo(null)); + if (localAudioTrack) { + localAudioTrack.close(); + window.VOICE_TRACK_MAP[loginUid] = null; + } if (localVideoTrack) { localVideoTrack.close(); window.VIDEO_TRACK_MAP[loginUid] = null; } - await window.VOICE_CLIENT.leave(); - dispatch(updateVoicingInfo(null)); if (context == "channel") { dispatch(updateChannelVisibleAside({ id, aside: null