Skip to content

fix(webrtc): Fix Firefox simulcast race condition and respect HPB bandwidth limits#17776

Open
tareko wants to merge 1 commit intomainfrom
fix/17774/firefox-simulcast-race
Open

fix(webrtc): Fix Firefox simulcast race condition and respect HPB bandwidth limits#17776
tareko wants to merge 1 commit intomainfrom
fix/17774/firefox-simulcast-race

Conversation

@tareko
Copy link
Copy Markdown

@tareko tareko commented Apr 23, 2026

When using Firefox with the High Performance Backend (HPB / MCU) and simulcast enabled, the publisher side initializes simulcast encodings via sender.setParameters(). However, the returned Promise is not awaited before createOffer() is called. This creates a race condition where the offer SDP may be generated before the simulcast parameters are actually applied to the sender.

This fixes issue #17774 - more details in that issue. OpenCode with Kimi 2.6 and Qwen 3.6 35B3A were used to debug and repair.

…dwidth limits

- Chain sender.setParameters() before createOffer() in Firefox to avoid
  a race where the offer SDP is generated before simulcast encodings are
  applied.  Previously the promise was ignored, causing simulcast to fail
  silently on low-bandwidth links and fall back to a single high-bitrate
  stream that congested the connection.

- Add _getMaxBitrates() helper that derives simulcast tiers from the
  signaling server's maxstreambitrate instead of hardcoded values.
  The server already sent this limit in the room join response but the
  client never used it, so publishers always tried to push 1.3 Mbps even
  when the uplink or server policy was much lower.

- Parse data.room.bandwidth.maxstreambitrate in joinResponseReceived and
  expose it on the signaling connection so Peer objects can read it.

- Guard s.track before accessing s.track.kind in getSenders() find,
  matching the existing upstream fix for disabled tracks in Firefox.

Fixes #17774

Signed-off-by: Tarek Loubani <tarek@tarek.org>
@nickvergessen
Copy link
Copy Markdown
Member

Past 2 of your fixes I already did in #17670 πŸ™ˆ

@tareko
Copy link
Copy Markdown
Author

tareko commented Apr 24, 2026

Past 2 of your fixes I already did in #17670 πŸ™ˆ

That's so great. I tried to look and see if this was anywhere, but couldn't quite find it. Does that mean this PR should close? Or was there something in this PR you thought could be useful?

@nickvergessen
Copy link
Copy Markdown
Member

Well you seem to address more, but since you vibed it and I have not enough knowledge about the sdp patching, I leave this to the experts.

@nickvergessen nickvergessen added bug feature: WebRTC 🚑 WebRTC connection between browsers and/or mobile clients performance πŸš€ and removed performance πŸš€ labels Apr 24, 2026
@nickvergessen nickvergessen requested a review from danxuliu April 24, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug feature: WebRTC 🚑 WebRTC connection between browsers and/or mobile clients

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants