Skip to content

Fix local VAD flickering on cleanup#520

Merged
MiloszFilimowski merged 1 commit into
fishjam-cloud:mainfrom
Critteros:fix_local_vad_flickering
Apr 24, 2026
Merged

Fix local VAD flickering on cleanup#520
MiloszFilimowski merged 1 commit into
fishjam-cloud:mainfrom
Critteros:fix_local_vad_flickering

Conversation

@Critteros

Copy link
Copy Markdown
Contributor

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
  • No documentation update required

Types of changes

  • 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)

clearTimeout alone cannot cancel an already-running poll awaiting
getLocalTrackAudioLevel. Pending promise resolved after cleanup,
calling setIsSpeaking and scheduling new timeout — caused flickering.
AbortSignal short-circuits poll at each await boundary.
@Critteros Critteros closed this Apr 24, 2026
@Critteros Critteros reopened this Apr 24, 2026
@MiloszFilimowski MiloszFilimowski merged commit 652b86c into fishjam-cloud:main Apr 24, 2026
2 of 6 checks passed
@Critteros Critteros deleted the fix_local_vad_flickering branch May 8, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants