Installations
npm install @scottjgilroy/react-record-webcam
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
20.10.0
NPM Version
10.2.3
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
samuelweckstrom
Download Statistics
Total Downloads
971
Last Day
7
Last Week
20
Last Month
63
Last Year
971
GitHub Statistics
56 Stars
113 Commits
22 Forks
3 Watching
6 Branches
4 Contributors
Bundle Size
10.01 kB
Minified
2.78 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.1
Package Id
@scottjgilroy/react-record-webcam@1.1.1
Unpacked Size
61.05 kB
Size
13.91 kB
File Count
15
NPM Version
10.2.3
Node Version
20.10.0
Publised On
11 Jun 2024
Total Downloads
Cumulative downloads
Total Downloads
971
Last day
-12.5%
7
Compared to previous day
Last week
33.3%
20
Compared to previous week
Last month
18.9%
63
Compared to previous month
Last year
0%
971
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Promise based zero dependency webcam library for React. Select video and audio input for one or multiple concurrent recordings using any mix of video and audio source.
Note version 1.0 is a complete rewrite so you will need to make some changes if updating.
Add package
npm i react-record-webcam
Usage
1// record a 3s. video 2 3import { useRecordWebcam } from 'react-record-webcam' 4 5... 6 7 const { 8 activeRecordings, 9 createRecording, 10 openCamera, 11 startRecording, 12 stopRecording, 13 } = useRecordWebcam() 14 15 const example = async () => { 16 try { 17 const recording = await createRecording(); 18 if (!recording) return; 19 await openCamera(recording.id); 20 await startRecording(recording.id); 21 await new Promise((resolve) => setTimeout(resolve, 3000)); 22 await stopRecording(recording.id); 23 } catch (error) { 24 console.error({ error }); 25 } 26 }; 27 28 return ( 29 <div> 30 <button onClick={example}>Start</button> 31 {activeRecordings.map(recording => ( 32 <div key={recording.id}> 33 <video ref={recording.webcamRef} autoPlay muted /> 34 <video ref={recording.previewRef} autoPlay muted loop /> 35 </div> 36 ))} 37 </div> 38 ) 39 40... 41
Check the CodeSandbox links for above demo and one with more features.
Passing options
Pass options either when initializing the hook or at any point in your application logic using applyOptions
.
1const options = { fileName: string, fileType: string, mimeType: string } 2const { ... } = useRecordWebcam(options) 3 4// or 5 6const { applyOptions } = useRecordWebcam() // import utility 7applyOptions(recording.id: string, options) // add to your application logic 8 9
Option | default value |
---|---|
fileName | timestamp |
fileType | webm |
mimeType | video/webm;codecs=vp9 |
If you want to use a specific video/audio codec you can pass this in the mimeType
. For example:
'video/webm;codecs=vp9'
'video/webm;codecs=vp8'
'video/webm;codecs=h264'
'video/x-matroska;codecs=avc1'
Please check that the browser supports the selected codec.
Passing recorder options
Pass recorder options when initializing the hook.
1const recorderOptions: { audioBitsPerSecond: number, videoBitsPerSecond: number } 2const { ... } = useRecordWebcam(recorderOptions)
Link to MDN for supported MediaOptions.
Passing recording constraints
1const constraints: { aspectRatio: number, height: number, width: number } 2const { ... } = useRecordWebcam(constraints) 3 4// or 5 6const { applyConstraints } = useRecordWebcam() // import utility 7applyConstraints(recording.id: string, constraints) // add to your application logic 8
Link to MDN for supported MediaConstraints.
Full API
Method | Description |
---|---|
activeRecordings | Array of currently active recordings. |
applyConstraints(recordingId, constraints): Promise<Recording> | Apply constraints to a recording session. See passing recording constraints. |
applyRecordingOptions(recordingId, options) Promise<Recording> | Apply options to a recording. See passing options. |
cancelRecording(recordingId): Promise<void> | Cancels and deletes a specified recording session. |
clearAllRecordings() | Clears all the active recordings and resets them. |
clearPreview(recordingId): Promise<Recording> | Clears the preview of a specific recording. |
closeCamera(recordingId): Promise<Recording> | Closes the camera of a specified recording session. |
createRecording(videoId?, audioId?): Promise<Recording> | Creates a new recording session with specified video and audio IDs. If none are give the system defaults are used. |
devicesById | Available input devices by their device ID. |
devicesByType | Available input devices based on their type (audio, video). |
download(recordingId): Promise<void> | Downloads the specified recording as a file. |
errorMessage | Returns the last error message, if any, from the hook's operations. |
muteRecording(recordingId): Promise<Recording> | Toggles mute on or off for a specified recording session. |
openCamera(recordingId): Promise<Recording> | Opens the camera for a specified recording session, preparing it for recording. |
pauseRecording(recordingId): Promise<Recording> | Pauses an ongoing recording session. |
resumeRecording(recordingId): Promise<Recording> | Resumes a paused recording session. |
startRecording(recordingId): Promise<Recording> | Starts a new recording for the specified session. |
stopRecording(recordingId): Promise<Recording> | Stops an ongoing recording session and finalizes the recording. |
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 More