fix(call): clear soundboard safety timer + detach permission onchange
- CallSoundboard: the 30s safety timeout (which unsticks the one-at-a-time playingKey guard if audio never signals end) was never cleared, so it fired ~30s after every clip. It's now stored in a per-play token that done() clears by identity — a natural 'ended' cancels it, and a stale done() from a prior clip can't disarm a newer clip's timer (which matters because a rejected audio.play() fires neither ended nor error, leaving the timer as the only guard-reset). The unmount effect also clears any pending timer, and the timer is armed only when there's an audio element. - PrescreenControls: useMediaPermissions set PermissionStatus.onchange but never removed it → a permission change after unmount setState'd a dead component and retained the callback. Now guards all setState with a cancelled flag and detaches onchange in the effect cleanup. Bug-hunt findings from LOTUS_TODO. Three review passes (the last prescribed the per-play token to close a shared-ref cross-play edge). Gate-green (tsc, eslint, prettier, 922 tests, build). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -17,15 +17,29 @@ function useMediaPermissions(): MediaPermState {
|
||||
useEffect(() => {
|
||||
if (!navigator.permissions) {
|
||||
setState('unknown');
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
let cancelled = false;
|
||||
let permStatus: PermissionStatus | undefined;
|
||||
navigator.permissions
|
||||
.query({ name: 'microphone' as unknown as PermissionDescriptor['name'] })
|
||||
.then((result) => {
|
||||
if (cancelled) return;
|
||||
permStatus = result;
|
||||
setState(result.state as MediaPermState);
|
||||
result.onchange = () => setState(result.state as MediaPermState);
|
||||
result.onchange = () => {
|
||||
if (!cancelled) setState(result.state as MediaPermState);
|
||||
};
|
||||
})
|
||||
.catch(() => setState('unknown'));
|
||||
.catch(() => {
|
||||
if (!cancelled) setState('unknown');
|
||||
});
|
||||
// Detach the onchange handler on unmount so it can't setState afterward (and
|
||||
// so the PermissionStatus doesn't retain the callback).
|
||||
return () => {
|
||||
cancelled = true;
|
||||
if (permStatus) permStatus.onchange = null;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return state;
|
||||
|
||||
Reference in New Issue
Block a user