Nightly: CHAOS fixt sofort erster Sound, stabile Wiederholung über Ref (13 Min), sauberes Stoppen

This commit is contained in:
vibe-bot 2025-08-09 15:28:32 +02:00
parent 399ab0a14b
commit 460c53c1d4

View file

@ -29,6 +29,8 @@ export default function App() {
const [mediaUrl, setMediaUrl] = useState<string>(''); const [mediaUrl, setMediaUrl] = useState<string>('');
const [chaosMode, setChaosMode] = useState<boolean>(false); const [chaosMode, setChaosMode] = useState<boolean>(false);
const chaosTimeoutRef = useRef<number | null>(null); const chaosTimeoutRef = useRef<number | null>(null);
const chaosModeRef = useRef<boolean>(false);
useEffect(() => { chaosModeRef.current = chaosMode; }, [chaosMode]);
useEffect(() => { useEffect(() => {
(async () => { (async () => {
@ -184,13 +186,15 @@ export default function App() {
}; };
const scheduleNextPlay = async () => { const scheduleNextPlay = async () => {
if (!chaosMode) return; if (!chaosModeRef.current) return;
await playRandomSound(); await playRandomSound();
const delay = 60_000 + Math.floor(Math.random() * 120_000); // 1-3 Minuten const delay = 60_000 + Math.floor(Math.random() * 120_000); // 1-3 Minuten
chaosTimeoutRef.current = window.setTimeout(scheduleNextPlay, delay); chaosTimeoutRef.current = window.setTimeout(scheduleNextPlay, delay);
}; };
// ersten Start zufällig zwischen 1-3 Minuten planen // Sofort ersten Sound abspielen
await playRandomSound();
// Nächsten zufällig in 1-3 Minuten planen
const firstDelay = 60_000 + Math.floor(Math.random() * 120_000); const firstDelay = 60_000 + Math.floor(Math.random() * 120_000);
chaosTimeoutRef.current = window.setTimeout(scheduleNextPlay, firstDelay); chaosTimeoutRef.current = window.setTimeout(scheduleNextPlay, firstDelay);
}; };