Skip to content

fix: stop recording from opening a second competing webcam session - #6

Open
Alfredoalv13 wants to merge 1 commit into
mainfrom
fix/webcam-preview-recording-contention
Open

fix: stop recording from opening a second competing webcam session#6
Alfredoalv13 wants to merge 1 commit into
mainfrom
fix/webcam-preview-recording-contention

Conversation

@Alfredoalv13

Copy link
Copy Markdown
Owner

Summary

  • Recording opened its own getUserMedia session for the webcam at 1280x720/30fps, while the live floating preview bubble kept a 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 live preview go blank the instant recording started (the recording itself kept working, since its session survived).
  • Recording now reuses the live preview's existing camera track instead of opening a second session: it bumps the shared track's resolution via applyConstraints, records from a clone() 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.
  • Falls back to the original getUserMedia call 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 useEffect deps don't even re-run when recording starts, ruling out a cleanup-then-reacquire race. The two independent getUserMedia calls (different resolutions, same device) are the root cause.

Test plan

  • npx tsc — clean
  • npx vitest --run — 786/786 passing
  • npx biome check on changed files — clean (one pre-existing, unrelated formatting issue on main left untouched)
  • Manual: record with webcam + floating preview enabled, confirm the preview keeps showing live video for the whole recording instead of going blank at start

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.
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