[Bug]: Missing WebRTC playoutDelayHint introduces 50-100ms artificial latency and redundant MediaStream recreation triggers video pipeline reload
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- typescript, web-dev
- Domain
- audio-video-rtc, frontend
Research direction
Read src/hooks/useWebRtcStream.ts around the pc.ontrack handler and ScreenMirror.tsx around the effect that assigns video.srcObject. Check how track additions update the stream reference and what receiver controls are supported. The linked pull request #524 is already open; compare its changes and tests with the reported startup flicker and playout delay.
Written by the indexing model from the issue text.
Description
Bug Description
Summary
Rein is designed as a low-latency remote desktop and screen mirror aiming for sub-8ms response times. However, two issues in src/hooks/useWebRtcStream.ts introduce significant visual lag and a video pipeline reset on initial connection:
-
Artificial Browser Jitter Buffer Delay (50ms–100ms):
When WebRTC media tracks arrive inpc.ontrack(src/hooks/useWebRtcStream.ts, lines 255–275), low-latency playout hints (event.receiver.playoutDelayHint = 0/jitterBufferTarget = 0) are not configured on theRTCRtpReceiver. By default, Chromium and other browsers treat incoming WebRTC tracks as conversational video calls, automatically buffering frames in an internal jitter buffer for 50ms to 100ms before rendering them to the<video>element. For real-time remote desktop interaction, this causes perceptible input-to-display lag. -
Redundant MediaStream Instantiation & Video Reload:
The server streams both video and audio tracks. When the audio track arrives shortly after the video track (lines 264–268):if (!activeStream.getTracks().some((t) => t.id === event.track.id)) { activeStream.addTrack(event.track); setVideoStream(new MediaStream(activeStream.getTracks())); // Creates a brand new instance }This creates a brand new
MediaStreaminstance and updates state. InScreenMirror.tsx(lines 66–70), the effect detectsvideo.srcObject !== videoStreamand re-assignsvideo.srcObject = videoStream. Re-assigningsrcObjecton an actively playing HTML5 video element forces the browser to abort playback, re-run the media element load algorithm, and re-negotiate codecs. This results in a brief black frame flash and stalls stream startup.
Performance & Latency Impact
- Latency: Adds an unnecessary 50ms–100ms playout delay to remote desktop mirroring.
- Speed & Stability: Forces a redundant video decoder reload right after initial connection.
Steps to Reproduce
- Start the Rein host server (
npm run dev). - Open a client browser (e.g. Chrome 130+) and navigate to
/trackpad. - Observe the mirror startup: a brief black frame flash occurs when the audio track arrives and re-assigns
video.srcObject. - Open
chrome://webrtc-internalsin another tab, locate the Inbound RTP video stream, and inspectjitterBufferDelay/playoutDelay: observe ~50ms–100ms buffer delay instead of near-zero playout latency. - Move the cursor on the trackpad and notice the visual lag on the mirrored screen.
Expected Behavior
- The video receiver should set
receiver.playoutDelayHint = 0(andjitterBufferTarget = 0where supported) to instruct the browser decoder to render frames immediately without artificial buffering. - The client should retain a stable
MediaStreamreference across track additions sovideo.srcObjectis assigned once, eliminating the video reload and black frame flicker.
Desktop Operating System
Windows 11
Client OS and browser
Chrome 130+ on Windows
Rein Version
1.0.0
Console Logs / Error Messages (Optional)
[WebRTC] Received track: video
[WebRTC] Received track: audio
[ScreenMirror] User interaction detected
Screenshots / Recordings (Optional)
Checklist
- I have searched for existing issues to avoid duplicates
- Dominant language
- TypeScript
- Stars
- 55
- Forks
- 120
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 24
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AOSSIE-Org/Rein
-
[Bug]: JSON body null returns 500 on /api/clipboard/copy and /api/clipboard/pastePossibly taken A pull request linked to this issue is open or already merged. Openbug enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
AOSSIE-Org/Rein#522 · 1 comment ·
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AOSSIE-Org/Rein#509 · 3 comments ·
Maintainers usually reply within 2 days
-
[Bug]: Session tokens expire 10 days after creation regardless of use (touchToken is never called)Possibly taken @Ankitavasudev claimed this 12 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
AOSSIE-Org/Rein#466 · 6 comments · 1 assignee ·
Maintainers usually reply within 2 days
-
[Bug]: Uploaded files are saved with garbled non-ASCII names and overwrite existing files with the same namePossibly taken @Aryan-en claimed this 23 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
AOSSIE-Org/Rein#458 · 5 comments ·
Maintainers usually reply within 2 days
-
[Bug]: release held keys, mouse buttons, and gamepad buttons on session disconnectPossibly taken @Abfa41 claimed this 4 days ago. Openbug enhancement
Difficulty 3/5 Half a day Newbie friendliness 55/100
AOSSIE-Org/Rein#518 · 1 comment ·
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
-
review-followup
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
griffinwork40/agent-afk#5387 ·
Maintainers usually reply within 1 day
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
CodeManufactoryLLC/Code60#358 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
android:plan ios:plan main:plan packages:learn
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day