npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@scottjgilroy/react-record-webcam

v1.1.1

Published

Webcam recording tool for React

Downloads

10

Readme

TypeScript Tests npm version

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.

DEMO

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

// 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.

Passing options

Pass options either when initializing the hook or at any point in your application logic using applyOptions.

const options = { fileName: string, fileType: string, mimeType: string }
const { ... } = useRecordWebcam(options)

// or

const { applyOptions } = useRecordWebcam() // import utility
applyOptions(recording.id: string, options) // add to your application logic

| 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.

const recorderOptions: { audioBitsPerSecond: number, videoBitsPerSecond: number }
const { ... } = useRecordWebcam(recorderOptions)

Link to MDN for supported MediaOptions.

Passing recording constraints

const constraints: { aspectRatio: number, height: number, width: number }
const { ... } = useRecordWebcam(constraints)

// or

const { applyConstraints } = useRecordWebcam() // import utility
applyConstraints(recording.id: string, constraints) // add to your application logic

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

MIT

Credits

webcam by iconfield from Noun Project (CC BY 3.0)