Skip to content

fix: await AudioContext.setSinkId when switching mixed audio output - #2276

Merged
1egoman merged 1 commit into
mainfrom
fix/await-audiocontext-setsinkid
Nov 16, 2026
Merged

1egoman merged 1 commit into
mainfrom
fix/await-audiocontext-setsinkid

Conversation

@1egoman

@1egoman 1egoman commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Closes #2275 (split out from #2271).

With webAudioMix enabled, switchActiveDevice('audiooutput', …) called AudioContext.setSinkId() without awaiting it. The switch resolved and emitted ActiveDeviceChanged before routing finished. If routing failed, the rejection went unhandled and getActiveDevice('audiooutput') still reported the failed device.

This change awaits the call. A routing failure now reaches the existing catch, which restores the previous audioOutput.deviceId and rethrows, and ActiveDeviceChanged is only emitted on success.

Tests

Added two tests to Room.test.ts that stub the room's audio context:

  • a deferred setSinkId: the switch doesn't resolve or emit until routing resolves
  • a rejecting setSinkId: the switch rejects, emits nothing, and keeps the previous device

Both fail on main (the second also with the unhandled rejection) and pass with the fix.

🤖 Generated with Claude Code

With webAudioMix enabled, switchActiveDevice('audiooutput') fired
AudioContext.setSinkId() without awaiting it, so the switch resolved and
emitted ActiveDeviceChanged before routing finished, and a routing
failure became an unhandled rejection while the requested device was
still reported as active.
@changeset-bot

changeset-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 92c8dff

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
livekit-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 117.03 KB (-0.13% 🔽)
dist/livekit-client.umd.js 126.44 KB (-0.01% 🔽)
dist/core/core.mjs 79.56 KB (+0.1% 🔺)

@1egoman
1egoman merged commit 94322b3 into main Nov 16, 2026
7 checks passed
@1egoman
1egoman deleted the fix/await-audiocontext-setsinkid branch November 16, 2026 22:39
@github-actions github-actions Bot mentioned this pull request Nov 16, 2026
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.

switchActiveDevice('audiooutput') doesn't await AudioContext.setSinkId with webAudioMix

2 participants