
Security News
Cline CLI npm Package Compromised via Suspected Cache Poisoning Attack
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.
use-simple-camera
Advanced tools
A simple and easy to use react hook, it can help you capture videos, images and get media devices streams in an easy to use way.
🛠️ Use Simple Camera is a lightweight React hook that simplifies interacting with browser APIs for capturing audio and video from media devices. It abstracts the complexities of managing permissions, media streams, and recording operations, providing a seamless developer experience for building camera-enabled applications.
Whether you're creating a video conferencing app, a custom video recording tool, or an image capture utility, Use Simple Camera equips you with all the essential functionalities in one easy-to-use package.
Well life's too short for clunky APIs! Whether you’re building a photo booth, a live streamer, or a casual media app, Use Simple Camera is your new BFF.
Find it on NPM https://www.npmjs.com/package/use-simple-camera
Find it on Github https://github.com/ketanip/use-simple-camera
Demo Project Live: https://use-simple-camera-demo.vercel.app/
Demo Project Source Code: https://github.com/ketanip/use-simple-camera-demo
That'll Make You Go WOW
I was working extensively once with these APIs for a project and that experience annoyed me a lot, so I decided to write custom code that time.
I was planning once again to work with same APIs so not to feel that same unpleasant experience again I decided to create this library (hook).
import { useSimpleCamera } from "use-simple-camera";
import { useState, useRef } from "react";
const MyComponent = () => {
const [imageURL, setImageURL] = useState("");
const videoRef = useRef<HTMLVideoElement>(null);
const {
acquirePermissions,
captureImage,
startCamera,
stopCamera,
recordVideo,
stopVideoRecording,
downloadRecordedVideo,
} = useSimpleCamera();
return (
<div>
<button onClick={acquirePermissions}>Permissions</button>
<button onClick={startCamera}>Start</button>
<button onClick={stopCamera}>Stop</button>
<button onClick={() => captureImage().then(setImageURL)}>Capture</button>
<button onClick={() => recordVideo("vid1")}>Record</button>
<button onClick={stopVideoRecording}>Stop Recording</button>
<button onClick={() => downloadRecordedVideo("vid1")}>Download</button>
{imageURL && <img src={imageURL} alt="Captured" />}
{videoRef && <video ref={videoRef} controls />}
</div>
);
};
This hook packs a punch with intuitive, flexible functions. Here’s the action-packed lineup:
Here’s the magic you'll have at your fingertips:
permissionAcquired – Do we have the green light?isCameraActive – Is the camera rolling?videoDevices – All available video sources.audioDevices – All available audio sources.videoRecordingInProgress – Are we filming?acquirePermissions, startCamera, stopCamera, getMediaStreamcaptureImagerecordVideo, stopVideoRecording, getRecordedVideoURL, getRecordedVideoBlob, downloadRecordedVideoacquirePermissions before anything else.stopCamera to release media devices and avoid leaving them active.captureImage gives you a Base64 blob of your snapshot.getRecordedVideoURL: Get a URL to the video.getRecordedVideoBlob: Get the raw blob of the video.downloadRecordedVideo: Save the video locally.getMediaStream with React refs for custom video streaming, audio-only and video-only streaming.acquirePermissions()Description: Asks the user for permission to access the camera and microphone.
Returns: Promise<void>
Example:
await acquirePermissions();
startCamera(config: object)Description: Starts the camera to capture video and audio.
Parameters:
config: Provide MediaStreamConstraints for the media input. (optional)Returns: Promise<void>
Example:
await startCamera();
stopCamera()Description: Stops the camera and releases all media devices.
Returns: Promise<void>
Example:
await stopCamera();
captureImage(videoTrackID?: string)Description: Captures an image from the specified video track. If no videoTrackID is provided, it uses the first available video device.
Returns: Promise<string> – A Base64-encoded string representing the captured image.
Example:
const imageURL = await captureImage();
<img src={imageURL} alt="Captured" />;
recordVideo(id: string, config?: RecordVideoConfig)Description: Starts recording a video.
Parameters:
id: Unique identifier for the recorded video.config: Optional configuration object for custom video settings.
videoStreamID: The ID of the video stream to record.audioStreamID: The ID of the audio stream to record.customMimeType: Optional MIME type for the video recording (e.g., 'video/webm').Returns: Promise<void>
Example:
await recordVideo("submission-1234", {
videoStreamID: "video-stream-1",
audioStreamID: "audio-stream-1",
customMimeType: "video/codec=vp9".
})
stopVideoRecording()Description: Stops the ongoing video recording.
Returns: Promise<void>
Example:
await stopVideoRecording();
getRecordedVideoURL(videoID: string)Description: Retrieves the blob URL of the recorded video by its videoID.
Returns: string – The blob URL of the recorded video.
Example:
const videoURL = getRecordedVideoURL("video1");
<video src={videoURL} controls />;
getRecordedVideoBlob(videoID: string)Description: Retrieves the recorded video as a Blob by its videoID.
Returns: Blob – The raw Blob of the recorded video.
Example:
const videoBlob = getRecordedVideoBlob("video1");
const url = URL.createObjectURL(videoBlob);
downloadRecordedVideo(videoID: string, filename?: string)Description: Downloads the recorded video by its videoID, with an optional custom filename. Include file extension. If you haven't changed codec use webm as file extension.
Returns: void
Example:
downloadRecordedVideo("video1", "my-video.webm");
getMediaStream(config: GetMediaStreamConfig)Description: Retrieves a media stream based on the provided video and audio track IDs.
Parameters:
config: The configuration for selecting the media stream, which includes videoID and audioID.Returns: Promise<MediaStream> – The media stream for custom use.
Example:
const mediaStream = await getMediaStream({
videoID: "camera1",
audioID: "microphone1",
});
videoRef.current.srcObject = mediaStream;
We welcome contributions! If you'd like to help improve this project, here’s how you can contribute:
The License for this project is located in License file. This project is licensed under MIT License.
If you encounter any issues or have questions, please open a GitHub issue, and I'll be happy to assist you!
This is still first version of this library so please be careful while using it your application, test it extensively for your application.
✨ Ready to simplify your media game? Let’s roll!
FAQs
Production-ready React Hooks for Camera, Video Recording, QR/Barcode Scanning, Motion Detection, and Audio Analysis. Zero dependencies, fully typed, and easy to use.
The npm package use-simple-camera receives a total of 27 weekly downloads. As such, use-simple-camera popularity was classified as not popular.
We found that use-simple-camera 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
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.

Product
Socket is now scanning AI agent skills across multiple languages and ecosystems, detecting malicious behavior before developers install, starting with skills.sh's 60,000+ skills.

Product
Socket now supports PHP with full Composer and Packagist integration, enabling developers to search packages, generate SBOMs, and protect their PHP dependencies from supply chain threats.