Chain promises correctly
This commit is contained in:
parent
d34c8d08a4
commit
f6f0c20b08
1 changed files with 5 additions and 3 deletions
|
@ -65,14 +65,16 @@ export const usePTT = (
|
||||||
): PTTState => {
|
): PTTState => {
|
||||||
// Used to serialise all the mute calls so they don't race. It has
|
// 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.
|
// its own state as its always set separately from anything else.
|
||||||
const [mutePromise, setMutePromise] = useState(Promise.resolve());
|
const [mutePromise, setMutePromise] = useState(
|
||||||
|
Promise.resolve<boolean | void>(false)
|
||||||
|
);
|
||||||
|
|
||||||
// Wrapper to serialise all the mute operations on the promise
|
// Wrapper to serialise all the mute operations on the promise
|
||||||
const setMicMuteWrapper = useCallback(
|
const setMicMuteWrapper = useCallback(
|
||||||
(muted) => {
|
(muted: boolean) => {
|
||||||
setMutePromise(
|
setMutePromise(
|
||||||
mutePromise.then(() => {
|
mutePromise.then(() => {
|
||||||
groupCall.setMicrophoneMuted(muted).catch((e) => {
|
return groupCall.setMicrophoneMuted(muted).catch((e) => {
|
||||||
logger.error("Failed to unmute microphone", e);
|
logger.error("Failed to unmute microphone", e);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue