Commit 652b86c
authored
Fix local VAD flickering on cleanup (#520)
## Description
`useLocalVAD` polls `getLocalTrackAudioLevel` in a `setTimeout` loop. On
cleanup it calls `clearTimeout`, but that can't cancel a poll that's
already mid-`await`. The in-flight promise still resolves after
cleanup runs, calls `setIsSpeaking`, and schedules a fresh `setTimeout`
so `isSpeaking` flickers and the poll loop leaks past the disabled
state.
Fix: added an `AbortController` and check `signal.aborted` around each
`await` boundary. The poll exits cleanly on cleanup and won't schedule
another timeout.
## Motivation and Context
`isSpeaking` was flickering when the hook got toggled off or the
component unmounted, and a stale poll could keep running against aborted
state. Users saw the speaking indicator flash briefly after going
silent or leaving the room.
## Documentation impact
- [ ] Documentation update required
- [ ] Documentation updated [in another PR](_)
- [x] No documentation update required
## Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to
not work as expected)1 parent ae22852 commit 652b86c
1 file changed
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
| 46 | + | |
| 47 | + | |
44 | 48 | | |
| 49 | + | |
| 50 | + | |
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
| |||
52 | 58 | | |
53 | 59 | | |
54 | 60 | | |
| 61 | + | |
55 | 62 | | |
56 | 63 | | |
57 | 64 | | |
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
| 68 | + | |
61 | 69 | | |
62 | 70 | | |
63 | 71 | | |
| |||
0 commit comments