Skip to content

Consolidate clean up tasks for voice audio resources#318

Merged
francamps merged 5 commits intomainfrom
franc/cleanup-on-close
May 7, 2025
Merged

Consolidate clean up tasks for voice audio resources#318
francamps merged 5 commits intomainfrom
franc/cleanup-on-close

Conversation

@francamps
Copy link
Copy Markdown
Contributor

@francamps francamps commented May 6, 2025

Context

Websocket connections can close both expectedly and unexpectedly; in the React SDK, there are multiple resources which are dependent on this connection state: microphone, player and the voice provider state itself. Depending on the path by which this connection is closed, either manually, server-side or erroneously, there can exist race conditions that leave some of these resources in unfitting state.

Change

This PR implements a consolidated handleResourceCleanup function that orchestrates cleanup of player, microphone, and application state. Using refs to track microphone, the consolidated function can then be used in the onClose callback of the voice client, ensuring that all cleanup tasks properly run on different cases: manual disconnections, connection being closed server-side, or any type of errors occurring.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented May 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
empathic-voice-api-js-next-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 7, 2025 6:53pm

@francamps francamps changed the title Clean up mic and player on close Consolidate clean up tasks for voice audio resources May 6, 2025
@francamps francamps marked this pull request as ready for review May 7, 2025 18:18
@francamps francamps requested review from a team, chrismanahan, christinapeng1, hume-bot, klaudiuszmiotk, twitchard, vpicone, yinishi, zachkrall and zgreathouse and removed request for a team May 7, 2025 18:18
@francamps francamps merged commit f588294 into main May 7, 2025
3 checks passed
@francamps francamps deleted the franc/cleanup-on-close branch May 7, 2025 19:07
yinishi added a commit that referenced this pull request May 15, 2025
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