Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-hook-recorder

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hook-recorder

React based hook to use native MediaRecorder API

  • 0.0.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-hook-recorder

A simple react hook using MediaRecorder API

Demo

https://codesandbox.io/s/react-hook-recorder-gbz6z

Example

import React, { useCallback, useState } from "react";
import useRecorder from "react-hook-recorder";

function Recorder() {
  const [url, setUrl] = useState("");
  const onStop = useCallback((blob, blobUrl) => {
    setUrl(blobUrl);
  }, []);

  const { startRecording, stopRecording, register, status } = useRecorder();

  return (
    <div>
      <video ref={register} autoPlay muted playsInline />
      {url && (
        <>
          Recorded video&nbsp;:
          <video controls src={url} />
        </>
      )}
      {status !== "init" && (
        <>
          <button onClick={startRecording} disabled={status === "recording"}>
            Start Recording
          </button>
          <button
            onClick={stopRecording(onStop)}
            disabled={status !== "recording"}
          >
            Stop Recording
          </button>
        </>
      )}
      <div>
        <strong>Status :</strong>&nbsp;
        {status}
      </div>
    </div>
  );
}

export default Recorder;

API

useRecorder

Args (mediaStreamConstraints: MediaStreamConstraints, mediaRecorderOptions: MediaRecorderOptions)
PropertyRequiredTypeDescription
mediaStreamConstraintsfalseobjectMediaStreamConstraints object
mediaRecorderOptionsfalseobjectMediaRecorder object
Returns (object)
PropertyTypeArgsDescription
mediaRecorderMediaRecorderMediaRecorder instance ref
streamMediaStreamMediaStream instance ref
startRecordingfunctionfunction to start recording
stopRecordingfunctionfunction(blob: Blob, url: string) => voidfunction to stop recording
registerfunctionHTMLVideoElementfunction to register video element
statusRecorderStatusreturn recorder status
errorRecorderErrorreturn recorder error

Types

enum RecorderStatus : "idle" | "init" | "recording"
enum RecorderError : "stream-init" | "recorder-init"

Keywords

FAQs

Package last updated on 02 Oct 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc