fix: webcam recording truncates to a fraction of a second (camera stream contention) - #18
Merged
Merged
Conversation
Confirmed with real recorded output: a 15.3s screen recording paired with a webcam file that was only 0.12s long - the camera track died almost immediately after recording started, matching PR #5's "MediaStreamTrack ends on its own" failure mode exactly, just not why it was happening. Root cause: useWebcamPreviewOverlay's floating live-preview bubble and useScreenRecorder's actual recording each called getUserMedia() independently for the same physical camera, at different resolutions, running concurrently for the entire recording (the bubble stays visible throughout). Two concurrent capture sessions on one camera is fragile on many devices/drivers and is what was truncating the recorded file. Fix: useScreenRecorder now exposes its active recording stream reactively (activeWebcamStream). useWebcamPreviewOverlay attaches directly to that stream when one is active instead of opening its own independent session, falling back to its own getUserMedia() call only when idle (no recording in progress). Ownership of stopping tracks stays with whoever opened the stream - the preview never stops a stream it didn't open.
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
useWebcamPreviewOverlay) and the actual recording (useScreenRecorder) each independently callgetUserMedia()for the same physical camera, at different resolutions, and both run concurrently for the entire recording (the bubble stays visible throughout). Two concurrent capture sessions on one camera is fragile on many devices and is what was truncating the recorded file.useScreenRecordernow exposes its active recording stream reactively. The preview attaches directly to that stream when a recording is active, instead of opening a second independent session - falling back to its owngetUserMedia()call only when idle. Stream ownership (who calls.stop()on the tracks) stays with whoever actually opened it.Test plan
tsc --noEmitcleannpm test- 94/94 files, 819/819 tests passing