Skip to content

fix: release the microphone stream and audio context that increaseMicLevel opens - #185

Open
RaphaelFakhri wants to merge 1 commit into
VapiAI:mainfrom
RaphaelFakhri:fix/mic-boost-release
Open

RaphaelFakhri wants to merge 1 commit into
VapiAI:mainfrom
RaphaelFakhri:fix/mic-boost-release

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Summary

increaseMicLevel() leaks a microphone stream and an AudioContext on every call.

Problem

Each call opens a getUserMedia stream and an AudioContext and keeps no reference to them. Nothing stops the tracks or closes the context, not when a later call replaces the boost, not on stop(), and not when setting the input device fails. The microphone stays captured after the call ends, and repeated calls accumulate contexts until the browser refuses to create more.

Solution

The SDK now keeps the stream and context of the active boost in micBoost.

  • A successful increaseMicLevel() releases the previous boost after the new track is in place.
  • stop() and the internal cleanup release the active boost.
  • A failure while setting the input, or a stop() that lands while the boost is being set up, releases the resources that this call opened.

Testing

Adds __tests__/micBoost.test.ts (fake getUserMedia and AudioContext, no browser):

  • A second call releases the first stream and context and keeps the second.
  • stop() releases the active stream and context.
  • A stop() during setup releases the resources that the interrupted call opened.
  • A failing input change releases the resources that this call opened.

Run with npx jest __tests__/micBoost.test.ts. Without the change to vapi.ts, 4 of 4 tests fail. With it, 4 pass. The full suite (65 tests) passes and tsc --noEmit is clean.

Fixes #184

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.

increaseMicLevel() leaks a microphone stream and an AudioContext on every call

1 participant