CameraSource component provides a complete camera capture interface for taking photos and recording videos. It handles camera permissions, device selection, and provides controls for capture, preview, and retake functionality.
Overview
CameraSource extendsLitUploaderBlock and creates a full-screen camera interface with support for:
- Photo capture
- Video recording with audio
- Multiple camera selection (front/back)
- Microphone selection and control
- Camera mirroring
- Recording time limits
- Preview and retake functionality
Basic Usage
Camera Modes
Configure available camera modes:Configuration
Camera Mirror
Mirror the camera preview (useful for front-facing cameras):Audio Recording
Control audio recording for videos:- Microphone permission is requested
- Audio device selector is shown
- Mute toggle button is available
Video Recording Duration
Set maximum recording duration in seconds:Media Recorder Options
Customize video recording parameters:- Your specified
mimeType video/webm(if supported)video/mp4(fallback)
User Interface
Photo Mode
In photo mode, users can:- See live camera preview
- Switch between cameras (if multiple available)
- Take a photo by clicking the camera button
- Preview the captured photo
- Retake or accept the photo
Video Mode
In video mode, users can:- See live camera preview
- Switch between cameras
- Select microphone (if audio enabled)
- Mute/unmute audio
- Start recording
- See recording timer
- Stop recording
- Play/pause preview
- Retake or accept the video
Permissions
The component handles camera and microphone permissions:Automatic Request (Desktop)
On browsers with Permissions API support, permissions are requested automatically:Manual Request (Fallback)
On unsupported browsers, a “Grant permissions” button is shown:Permission States
The interface adapts to permission states:- Granted - Shows camera interface
- Denied - Shows error message
- Prompt - Shows permission request message
Device Selection
Camera Selection
When multiple cameras are available:Microphone Selection
When audio recording is enabled and multiple microphones exist:Workflow
Photo Capture Flow
- Camera activates with live preview
- User clicks camera button
- Photo is captured and displayed
- User can:
- Retake - Returns to live preview
- Accept - Uploads the photo
Video Recording Flow
- Camera activates with live preview
- User clicks record button
- Recording starts, timer displays
- User clicks stop button (or time limit reached)
- Video preview plays
- User can:
- Play/Pause - Control preview playback
- Retake - Returns to live preview
- Accept - Uploads the video
Output Files
Photo Output
Video Output
.webm- Most modern browsers.mp4- Safari, older browsers.mkv- Some browsers with specific codecs.avi- Fallback
Events
Camera actions emit telemetry events:- Camera activation
- Tab switching (photo/video)
- Shot/recording events
- Retake actions
- Accept actions
Examples
Photo Only Mode
Video with Time Limit
Silent Video Recording
Both Modes with Custom Settings
Handle Camera Uploads
Browser Compatibility
Required APIs
MediaDevices.getUserMedia()- Camera accessMediaRecorder- Video recordingHTMLMediaElement- Video previewCanvas 2D Context- Photo capture
Mobile Considerations
On mobile devices:- Use native camera controls when available
- Request specific camera (front/back) via constraints
- Handle orientation changes
- Manage memory for large videos
Desktop Considerations
- Multiple camera support
- Higher resolution options
- External webcam support
- Screen capture (not implemented in CameraSource)
Styling
Customize the camera interface:Accessibility
Keyboard Controls
- Tab navigation through controls
- Enter/Space to activate buttons
- Focus management during state changes
Screen Reader Support
Status Announcements
Important state changes should be announced to screen readers:Error Handling
The component handles various error scenarios:Permission Denied
No Camera Available
Recording Failed
Mobile HTML Capture
On mobile devices with HTML media capture, the source list may show separate buttons:Source Code Reference
Implementation:/workspace/source/src/blocks/CameraSource/CameraSource.ts:53
Camera mode calculations: /workspace/source/src/blocks/CameraSource/calcCameraModes.ts
Constants: /workspace/source/src/blocks/CameraSource/constants.ts:14
See Also
- Config - Camera configuration options
- SourceList - Source selection
- UploadList - Manage captured files