Installations
npm install react-record-webcam
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
18.17.0
NPM Version
9.6.7
Score
78.3
Supply Chain
99.5
Quality
81.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
samuelweckstrom
Download Statistics
Total Downloads
181,197
Last Day
605
Last Week
2,714
Last Month
10,568
Last Year
106,881
GitHub Statistics
56 Stars
113 Commits
22 Forks
3 Watching
6 Branches
4 Contributors
Bundle Size
11.62 kB
Minified
3.54 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.5
Package Id
react-record-webcam@1.1.5
Unpacked Size
48.99 kB
Size
10.43 kB
File Count
5
NPM Version
9.6.7
Node Version
18.17.0
Publised On
26 Mar 2024
Total Downloads
Cumulative downloads
Total Downloads
181,197
Last day
15.2%
605
Compared to previous day
Last week
13.6%
2,714
Compared to previous week
Last month
-8.5%
10,568
Compared to previous month
Last year
140.8%
106,881
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
React Record Webcam is a promise-based, zero-dependency webcam library for React, enabling the selection of video and audio inputs for single or multiple concurrent recordings with any mix of video and audio sources.
Add package
1npm i react-record-webcam
Quick Start
To start recording, create a recording instance using createRecording
and manage the recording process with the hook's methods:
1import { useRecordWebcam } from 'react-record-webcam' 2 3const App = () => { 4 const { createRecording, openCamera, startRecording, stopRecording, downloadRecording } = useRecordWebcam() 5 6 const recordVideo = async () => { 7 const recording = await createRecording(); 8 await openCamera(recording.id); 9 await startRecording(recording.id); 10 await new Promise(resolve => setTimeout(resolve, 3000)); // Record for 3 seconds 11 await stopRecording(recording.id); 12 await downloadRecording(recording.id); // Download the recording 13 }; 14 15 return <button onClick={recordVideo}>Record Video</button>; 16};
Usage and Examples
Each method in the hook always returns an updated instance of a recording. Pass the id
of the recording instance to any of the methods from the hook to open camera, start, pause or stop a recording:
Heres an example of uploading the recorded blob to a back-end service:
1const { createRecording, openCamera, startRecording, stopRecording } = useRecordWebcam() 2 3 4async function record() { 5 const recording = await createRecording(); 6 7 await openCamera(recording.id); 8 await startRecording(recording.id); 9 await new Promise((resolve) => setTimeout(resolve, 3000)); // Record for 3 seconds 10 const recorded = await stopRecording(recording.id); 11 12 // Upload the blob to a back-end 13 const formData = new FormData(); 14 formData.append('file', recorded.blob, 'recorded.webm'); 15 16 const response = await fetch('https://your-backend-url.com/upload', { 17 method: 'POST', 18 body: formData, 19 }); 20};
All recording instances are available in activeRecordings
. You can for example access refs for webcam feed and recording preview in your component:
1const { activeRecordings } = useRecordWebcam() 2 3... 4 5 {activeRecordings.map(recording => ( 6 <div key={recording.id}> 7 <video ref={recording.webcamRef} autoPlay /> 8 <video ref={recording.previewRef} autoPlay loop /> 9 </div> 10 ))}
Recording instance
Property | Type | Description |
---|---|---|
id | string | The ID of the recording. |
audioId | string | The ID of the audio device. |
audioLabel | string | The label of the audio device. |
blob | Blob | The blob of the recording. |
blobChunks | Blob[] | Single blob or chunks per timeslice of the recording. |
fileName | string | The name of the file. |
fileType | string | The type of the file. |
isMuted | boolean | Whether the recording is muted. |
mimeType | string | The MIME type of the recording. |
objectURL | string | null | The object URL of the recording. |
previewRef | React.RefObject<HTMLVideoElement> | React Ref for the preview element. |
recorder | MediaRecorder | The MediaRecorder instance of the recording. |
status | 'INITIAL' | 'CLOSED' | 'OPEN' | 'RECORDING' | 'STOPPED' | 'ERROR' | 'PAUSED' | The status of the recording. |
videoId | string | The ID of the video device. |
videoLabel | string | The label of the video device. |
webcamRef | React.RefObject<HTMLVideoElement> | React Ref for the webcam element. |
Configuring options
Pass options either when initializing the hook or at any point in your application logic using applyOptions
.
1// At initialization 2const { applyOptions, applyConstraints } = useRecordWebcam({ 3 options: { fileName: 'custom-name', fileType: 'webm', timeSlice: 1000 }, 4 mediaRecorderOptions: { mimeType: 'video/webm; codecs=vp8' }, 5 mediaTrackConstraints: { video: true, audio: true } 6}); 7 8// Dynamically applying options 9applyOptions(recording.id, { fileName: 'updated-name' }); // Update file name 10applyConstraints(recording.id, { aspectRatio: 0.56 }) // Change aspect ratio to portrait
List of options
Option | property | default value |
---|---|---|
fileName | File name | Date.now() |
fileType | File type for download (will override inferred type from mimeType ) | 'webm' |
timeSlice | Recording interval | undefined |
Both mediaRecorderOptions
and mediatrackConstraints
mirror the official API. Please see on MDN for available options:
Codec Support
A codec supported by the current browser will be detected and used for recordings.
To see all video and audio codecs supported by the browser:
1const { supportedAudioCodecs, supportedVideoCodecs } = useRecordWebcam(); 2 3console.log({ supportedAudioCodecs, supportedVideoCodecs })
To check the support of a specific codec:
1const { checkCodecRecordingSupport, checkVideoCodecPlaybackSupport } = useRecordWebcam() 2 3const codec = 'video/x-matroska;codecs=avc1' 4const isRecordingSupported = checkCodecRecordingSupport(codec) 5const isPlayBackSupported = checkVideoCodecPlaybackSupport(codec)
To use a specific codec, pass this in the mediaRecorderOptions. Note that MediaRecorder uses a mimeType format for the codec: <container>;codec=<videoCodec>,<audioCodec>
1const codec = 'video/webm;codecs=h264' 2const mediaRecorderOptions = { mimetype: codec } 3const recordWebcam = useRecordWebcam({ mediaRecorderOptions })
For more info see the codec guide on MDN.
Error handling
Error messages are available in the hook. You can import the constant of all messages for error handling from the package.
1import { useRecordWebcam, ERROR_MESSAGES } from 'react-record-webcam'; 2 3const { errorMessage } = useRecordWebcam(); 4 5if (errorMessage === ERROR_MESSAGES.NO_USER_PERMISSION) { 6 // Handle specific error scenario 7}
API Reference
Method/Property | Arguments | Returns | Description |
---|---|---|---|
activeRecordings | Recording[] | Array of active recordings. | |
applyConstraints | recordingId: string, constraints: MediaTrackConstraints | Promise<Recording | void> | Applies given constraints to the camera for a specific recording. |
applyRecordingOptions | recordingId: string | Promise<Recording | void> | Applies recording options to a specific recording. |
cancelRecording | recordingId: string | Promise<void> | Cancels the current recording session. |
clearAllRecordings | Promise<void> | Clears all active recordings. | |
clearError | void | Function to clear the current error message. | |
clearPreview | recordingId: string | Promise<Recording | void> | Clears the preview of a specific recording. |
closeCamera | recordingId: string | Promise<Recording | void> | Closes the camera for a specific recording. |
createRecording | videoId?: string, audioId?: string | Promise<Recording | void> | Creates a new recording session with specified video and audio sources. |
devicesById | ById | Object containing devices by their ID, where ById is a record of string to { label: string; type: 'videoinput' | 'audioinput'; } . | |
devicesByType | ByType | Object categorizing devices by their type, where ByType has video and audio arrays of { label: string; deviceId: string; } . | |
download | recordingId: string | Promise<void> | Downloads a specific recording. |
errorMessage | string | null | The current error message, if any, related to recording. | |
muteRecording | recordingId: string | Promise<Recording | void> | Mutes or unmutes the recording audio. |
openCamera | recordingId: string | Promise<Recording | void> | Opens the camera for a specific recording with optional constraints. |
pauseRecording | recordingId: string | Promise<Recording | void> | Pauses the current recording. |
resumeRecording | recordingId: string | Promise<Recording | void> | Resumes a paused recording. |
startRecording | recordingId: string | Promise<Recording | void> | Starts a new recording session. |
stopRecording | recordingId: string | Promise<Recording | void> | Stops the current recording session. |
License
Credits
webcam by iconfield from Noun Project (CC BY 3.0)
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yaml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/samuelweckstrom/react-record-webcam/ci-cd.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yaml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/samuelweckstrom/react-record-webcam/ci-cd.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yaml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/samuelweckstrom/react-record-webcam/ci-cd.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-cd.yaml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/samuelweckstrom/react-record-webcam/ci-cd.yaml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-cd.yaml:40: update your workflow using https://app.stepsecurity.io/secureworkflow/samuelweckstrom/react-record-webcam/ci-cd.yaml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci-cd.yaml:52: update your workflow using https://app.stepsecurity.io/secureworkflow/samuelweckstrom/react-record-webcam/ci-cd.yaml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci-cd.yaml:34
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 1 out of 2 npmCommand dependencies pinned
Reason
9 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
- Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Reason
Found 1/24 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci-cd.yaml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 29 are checked with a SAST tool
Score
3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-record-webcam
reeo-react-record-webcam
A React webcam recording hook and component 🎬📹
pyramid-webcam
This is a react based webcam to open, close, record, download recorded video
@zilahir/react-record-webcam
A React webcam hook and component 🎬📹
@scottjgilroy/react-record-webcam
Webcam recording tool for React