Gathering detailed insights and metrics for react-record-webcam
Gathering detailed insights and metrics for react-record-webcam
Gathering detailed insights and metrics for react-record-webcam
Gathering detailed insights and metrics for 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
npm install react-record-webcam
Typescript
Module System
Node Version
NPM Version
79.4
Supply Chain
99.5
Quality
81.6
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
178,966
Last Day
483
Last Week
2,388
Last Month
9,144
Last Year
105,583
55 Stars
113 Commits
22 Forks
3 Watching
6 Branches
4 Contributors
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
Cumulative downloads
Total Downloads
Last day
-0.2%
483
Compared to previous day
Last week
-18.8%
2,388
Compared to previous week
Last month
-31.9%
9,144
Compared to previous month
Last year
139.9%
105,583
Compared to previous year
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.
1npm i react-record-webcam
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};
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 ))}
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. |
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
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:
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 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}
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. |
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
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
8 existing vulnerabilities detected
Details
Reason
Found 1/24 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-13
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 More