From a81c48cc22ca5d88b05b6e3a5bc3e9be2e3e9c50 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Jul 2022 15:52:32 +0100 Subject: [PATCH] Fix 'waiting for network' after reaching time limit If you spoke for the maximum amount of time and got cut off, the next time you tried to speak you'd just get the 'waiting for network' state. Key repeats would cause more delayed state timeouts to queue up. --- src/room/PTTButton.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/room/PTTButton.tsx b/src/room/PTTButton.tsx index 53f6f7bc..306a3314 100644 --- a/src/room/PTTButton.tsx +++ b/src/room/PTTButton.tsx @@ -57,13 +57,17 @@ export const PTTButton: React.FC = ({ const buttonRef = useRef(); const [activeTouchId, setActiveTouchId] = useState(null); + const [buttonHeld, setButtonHeld] = useState(false); const hold = useCallback(() => { // This update is delayed so the user only sees it if latency is significant + if (buttonHeld) return; + setButtonHeld(true); enqueueNetworkWaiting(true, 100); startTalking(); - }, [enqueueNetworkWaiting, startTalking]); + }, [enqueueNetworkWaiting, startTalking, buttonHeld]); const unhold = useCallback(() => { + setButtonHeld(false); setNetworkWaiting(false); stopTalking(); }, [setNetworkWaiting, stopTalking]);