From f6f0c20b08f434d88a39bb75efc5a6dfc02f530b Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 13 May 2022 20:39:21 +0100 Subject: [PATCH] Chain promises correctly --- src/room/usePTT.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/room/usePTT.ts b/src/room/usePTT.ts index 5d4682e..3b80f8c 100644 --- a/src/room/usePTT.ts +++ b/src/room/usePTT.ts @@ -65,14 +65,16 @@ export const usePTT = ( ): PTTState => { // Used to serialise all the mute calls so they don't race. It has // its own state as its always set separately from anything else. - const [mutePromise, setMutePromise] = useState(Promise.resolve()); + const [mutePromise, setMutePromise] = useState( + Promise.resolve(false) + ); // Wrapper to serialise all the mute operations on the promise const setMicMuteWrapper = useCallback( - (muted) => { + (muted: boolean) => { setMutePromise( mutePromise.then(() => { - groupCall.setMicrophoneMuted(muted).catch((e) => { + return groupCall.setMicrophoneMuted(muted).catch((e) => { logger.error("Failed to unmute microphone", e); }); })