fix(web): emit a new MediaStream ref per track so Firefox renders screen share#28
Merged
Merged
Conversation
…een share Web SFU viewers showed camera/black instead of the host's screen share on Firefox. useWebRTCSFU mutated one MediaStream and called setRemoteStream with the same object reference on each TrackSubscribed, so React bailed on the re-render and VideoViewer's srcObject effect (dep [stream]) never re-ran. Firefox does NOT render a track added to a MediaStream already attached to a <video> element — and audio is usually subscribed before the screen-share video — so the video never appeared (Chrome tolerated it, hence egress was fine). Now emit a fresh MediaStream reference on every track add/remove so srcObject re-binds. Updated the test, which had asserted the buggy same-ref. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
vu1nz Security Review0 finding(s) in PR #? No security issues found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Joining a session on the web showed camera + black instead of the host's screen share — on Firefox. The host was publishing SCREEN_SHARE video (the egress composited it fine), and the viewer subscribed; it just never rendered.
Root cause
useWebRTCSFUkept oneMediaStreamand mutated it on eachTrackSubscribed, callingsetRemoteStream(stream)with the same object reference. React bails onsetStatewith an unchanged reference, soVideoViewer'ssrcObjecteffect (dep [stream]) never re-ran. Firefox does not render a track added to aMediaStreamthat's already attached to a<video>element — and audio is usually subscribed before the screen-share video — so the video never appeared. Chrome tolerates the live mutation, which is why the egress (Chrome) was fine.Fix
Emit a fresh
MediaStreamreference on every track add/remove, soremoteStreamchanges identity → React re-renders →srcObjectre-binds → Firefox renders the screen share.Test
The existing test had actually asserted the buggy same-reference behavior (
toBe(firstStream)); updated it to assert a new reference each time, with the correct track contents after add and unsubscribe. Passes; lint clean.🤖 Generated with Claude Code