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

react-video-stream-canvas

v0.1.0

Published

React Stream Video Canvas Utility

Downloads

9

Readme

Overview

This package provides a toolset to simplify casting camera/MediaStream to HTML video/canvas elements.

When developing WebRTC applications, we need to deal with camera feeds and media streams. The traditional way to translate these streams to a HTML video element can be very complicated:

  • Allocate camera MediaStream
  • Set MediaStream to a Video elements' srcObject
  • Render stream on a Canvas element
  • Clear MediaStream after usage
  • Unset MediaStream of Video element
  • ...

Especially in React's strict mode, resources leakage happens frequently. Therefore, we have to be very careful when dealing with these streams.

This package simplifies the process of casting camera and media streams to HTML elements, as well as the cleanup after using the streams.

Installation

npm i react-video-stream-canvas

Watch Demo

git clone https://github.com/robwang8456/react-video-stream-canvas.git
cd demo
npm i
npm run dev

You can see the usages of Hooks and Components.

Hooks

useLink(target, source)

Link two streamed HTMLElements, pipe source's stream to target.

Refer to README.md in demo folder for refence of useLink

useCamera(constraints?: MediaStreamConstraints): Promise

return a Camera object initiated with constraints, just like:

const camera = useCamera(constraints);

which equals

const camera = navigator.mediaDevices.getUserMedia(constraints)

useVideoRef/useCanvasRef

Create Video/Canvas Ref-object.

const canvasRef = useCanvasRef({ drawForeground, drawBackground});

You can draw foreground/background while canvas rendering other media-stream.

const videoRef = useVideoRef() Just like useRef()

Components

Video/Canvas/Camera/Stream

When these components inside other stream-like component, will link to upper stream-like component automatically.