Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
react-record-webcam
Advanced tools
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.
npm i react-record-webcam
// record a 3s. video
import { useRecordWebcam } from 'react-record-webcam'
...
const {
activeRecordings,
createRecording,
openCamera,
startRecording,
stopRecording,
} = useRecordWebcam()
const example = async () => {
try {
const recording = await createRecording();
if (!recording) return;
await openCamera(recording.id);
await startRecording(recording.id);
await new Promise((resolve) => setTimeout(resolve, 3000));
await stopRecording(recording.id);
} catch (error) {
console.error({ error });
}
};
return (
<div>
<button onClick={example}>Start</button>
{activeRecordings.map(recording => (
<div key={recording.id}>
<video ref={recording.webcamRef} autoPlay muted />
<video ref={recording.previewRef} autoPlay muted loop />
</div>
))}
</div>
)
...
Check the CodeSandbox links for above demo and one with more features.
Pass options either when initializing the hook or at any point in your application logic using applyOptions
.
const options = { ... }
const mediaRecorderOptions = { ... }
const mediaTrackConstraints = { ... }
const { ... } = useRecordWebcam({
options,
mediaRecorderOptions,
mediaTrackConstraints
})
// or
const { applyOptions } = useRecordWebcam() // use utility
applyOptions(recording.id: string, options: Options) // add to your application logic
Option | property | default value |
---|---|---|
fileName | 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:
The default codec is set to video/webm;codecs=vp9
. If you prefer to use another one, you can check the compatibility for playback and recording with the following utilities:
const { checkCodecRecordingSupport, checkVideoCodecPlaybackSupport } = useRecordWebcam()
...
const codec = 'video/x-matroska;codecs=avc1'
const isRecordingSupported = checkCodecRecordingSupport(codec)
const isPlayBackSupported = checkVideoCodecPlaybackSupport(codec)
...
To use a specific codec, pass this in the mediaRecorderOptions:
const codec = 'video/webm;codecs=h264'
const mediaRecorderOptions = { mimetype: codec }
const recordWebcam = useRecordWebcam({ mediaRecorderOptions })
For more info see the codec guide on MDN.
Current error message is passed from the hook, along with a object of error states which you can use for checks.
import { useRecordWebcam, ERROR_MESSAGES } from 'react-record-webcam'
const { errorMessage } = useRecordWebcam()
...
const isUserPermissionDenied = errorMessage === ERROR_MESSAGES.NO_USER_PERMISSION;
...
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)
FAQs
Webcam recording tool for React
We found that react-record-webcam demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.