Skip to content

fix(client): prevent screen share audio loopback by default#2226

Merged
oliverlaz merged 2 commits into
mainfrom
worktree-screenshare-audio
May 5, 2026
Merged

fix(client): prevent screen share audio loopback by default#2226
oliverlaz merged 2 commits into
mainfrom
worktree-screenshare-audio

Conversation

@oliverlaz
Copy link
Copy Markdown
Member

@oliverlaz oliverlaz commented May 5, 2026

💡 Overview

When a user shares system audio while in a call, the OS-mixed system audio also includes the remote participants' voices coming out of the local speakers. This currently produces an unpleasant loopback for the remote speakers (they hear themselves played back through the screen share track).

This change updates the screen share audio defaults so AEC removes the call audio from the captured system audio by default, while preserving the rest (music, video, presentation audio).

📝 Implementation notes

  • Flip echoCancellation to true in getScreenShareStream's default audio constraints
  • Adds restrictOwnAudio for browsers that support it
  • Change ScreenShareState's default audioBitrateProfile from MUSIC_HIGH_QUALITY to VOICE_HIGH_QUALITY. The previous default was inconsistent with what the capture path actually produces.
  • The defaults still merge caller-supplied options.audio last, so any explicit override, including the constraints written by setAudioBitrateProfile(MUSIC_HIGH_QUALITY) continues to win, preserving HIFI music quality when the integrator opts in.

🎫 Ticket: https://linear.app/stream/issue/REACT-973/feedback-loop-issue-with-chromes-new-system-audio-sharing-feature

Enable AEC on the default screen share audio constraints so that remote
participants' voices played through the local speakers are subtracted
from the captured system audio before publish. Also align the default
ScreenShareState audio bitrate profile with the capture path: switch
from MUSIC_HIGH_QUALITY to VOICE_HIGH_QUALITY so the declared profile
honestly describes what is being captured. Music sharing remains
supported via an explicit setAudioBitrateProfile(MUSIC_HIGH_QUALITY)
call when HIFI is enabled at the call level.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 5, 2026

⚠️ No Changeset found

Latest commit: 64063e8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

@oliverlaz oliverlaz requested a review from jdimovska May 5, 2026 09:03
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

📝 Walkthrough

Walkthrough

Switches screen-share audio bitrate profile from MUSIC_HIGH_QUALITY to VOICE_HIGH_QUALITY, enables echo cancellation and restrictOwnAudio in getDisplayMedia audio constraints, and updates the corresponding test expectation.

Changes

Screen Share Audio Configuration

Layer / File(s) Summary
Core Initialization
packages/client/src/devices/ScreenShareState.ts
ScreenShareState constructor now passes AudioBitrateProfile.VOICE_HIGH_QUALITY to the base AudioDeviceManagerState instead of MUSIC_HIGH_QUALITY.
Media Constraints / Wiring
packages/client/src/devices/devices.ts
getScreenShareStream audio constraints changed: echoCancellation set to true and restrictOwnAudio: true added (with @ts-expect-error for absent types); other audio constraint merging remains.
Tests
packages/client/src/devices/__tests__/ScreenShareManager.test.ts
publishes screen share stream test updated to expect AudioBitrateProfile.VOICE_HIGH_QUALITY in the call.publish assertion.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped to tweak the sharing sound,
From music waves to voice profound,
Echoes softened, bitrate right,
Screened voices crisp and light 🎧

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing screen share audio loopback by default.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description provides a clear overview of the problem, implementation details, and the ticket reference. All required template sections are present and well-filled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-screenshare-audio

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Set restrictOwnAudio: true on the default screen share audio
constraints so that audio originating from the capturing tab
(notably WebRTC <audio> elements rendering remote participants)
is filtered out at the source before publish. Complements the
AEC default for the system-audio capture path. Browsers without
support for the constraint silently ignore it.
@oliverlaz oliverlaz merged commit 6877fb5 into main May 5, 2026
18 checks passed
@oliverlaz oliverlaz deleted the worktree-screenshare-audio branch May 5, 2026 10:31
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