fix: stop recording from opening a second competing webcam session - #6
Open
Alfredoalv13 wants to merge 1 commit into
Open
fix: stop recording from opening a second competing webcam session#6Alfredoalv13 wants to merge 1 commit into
Alfredoalv13 wants to merge 1 commit into
Conversation
Recording opened its own getUserMedia session for the webcam at 1280x720/30fps while the live preview bubble kept its own separate session open at 320x320/24fps. Two concurrent sessions to the same physical camera at different resolutions cause the OS to reconfigure the capture pipeline, silently killing whichever session isn't renegotiated - this made the floating preview go blank the instant recording started, even though the recording itself kept working. Recording now reuses the live preview's track (bumping its resolution via applyConstraints, then recording from a clone so stopping the recording doesn't also kill the shared preview track) instead of opening a second session, and reverts the shared track back to preview quality once recording stops.
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.
Summary
getUserMediasession for the webcam at 1280x720/30fps, while the live floating preview bubble kept a separate session open at 320x320/24fps.applyConstraints, records from aclone()of that track (so stopping the recording, which stops its own tracks, doesn't also kill the shared preview track), and reverts the shared track back to preview quality once recording stops.getUserMediacall if no live preview track is available (or it doesn't match the selected device), preserving current behavior for that case.Why
Confirmed via investigation: this is a genuine hardware/device-contention bug, not a React state/teardown bug — the preview hook's
useEffectdeps don't even re-run when recording starts, ruling out a cleanup-then-reacquire race. The two independentgetUserMediacalls (different resolutions, same device) are the root cause.Test plan
npx tsc— cleannpx vitest --run— 786/786 passingnpx biome checkon changed files — clean (one pre-existing, unrelated formatting issue onmainleft untouched)