recursive play sound logic

Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
Timo K
2025-09-12 12:04:53 +02:00
parent b0f91d56ef
commit c382291336

View File

@@ -372,16 +372,23 @@ export const InCallView: FC<InCallViewProps> = ({
}); });
// When waiting for pickup, loop a waiting sound // When waiting for pickup, loop a waiting sound
const [playing, setPlaying] = useState(false);
useEffect((): void | (() => void) => { useEffect((): void | (() => void) => {
if (callPickupState !== "ringing") return; if (callPickupState !== "ringing") return;
// play immediately and then every ~2.5s while in ringing setPlaying(true);
void pickupPhaseAudio?.playSound("waiting"); // play and then wait for 1.5s
const id = window.setInterval( const playSoundAndWait = async (): Promise<void> => {
() => void pickupPhaseAudio?.playSound("waiting"), await pickupPhaseAudio?.playSound("waiting");
2500, await new Promise((res) => setTimeout(res, 1500));
); };
return (): void => window.clearInterval(id); const startPlaying = async (): Promise<void> => {
}, [callPickupState, pickupPhaseAudio]); while (playing) {
await playSoundAndWait();
}
};
void startPlaying();
return (): void => setPlaying(false);
}, [callPickupState, pickupPhaseAudio, playing]);
// Waiting UI overlay // Waiting UI overlay
const waitingOverlay: JSX.Element | null = useMemo(() => { const waitingOverlay: JSX.Element | null = useMemo(() => {