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

use-media-stream

v1.0.3

Published

React hook that simplifies the integration and management of media streams with extensive control over devices, streaming status, and event handling.

Downloads

21

Readme

Use Media Stream

use-media-stream is a powerful React hook designed to streamline the integration and management of media streams within your React applications. It offers a comprehensive set of features and options for effortless control and manipulation of media streams. It provides a convenient interface for handling media devices, initiating media streams, and controlling audio and video tracks.

GitHub License

Demo - Link

Installation

Install the hook using your preferred package manager:

npm install use-media-stream
or
yarn add use-media-stream

Usage

Import the hook into your React component and leverage its capabilities to manage your media streams:

import useMediaStream from 'use-media-stream';

function MyComponent() {
  const {
    stream,
    isSupported,
    isStreaming,
    isAudioMuted,
    isVideoMuted,
    // ... other properties and handlers
  } = useMediaStream();

  // ... your component logic
}

Props Values

| Prop | Type | Description | | ------------------------ | -------------------------------- | -------------------------------------------------------------------- | | mediaDeviceConstraints | MediaStreamConstraints \| null | The constraints for the media device to be used in the media stream. |

Return Values

| Property | Type | Description | | ------------------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | | stream | MediaStream \| null | The current media stream object. | | isStreaming | boolean | Indicates whether the media stream is currently active. | | isAudioMuted | boolean | Indicates whether audio tracks are muted. | | isVideoMuted | boolean | Indicates whether video tracks are muted. | | devices | MediaDeviceInfo[] | An array of available media devices. | | audioInputDevices | MediaDeviceInfo[] | An array of available audio input devices. | | audioOutputDevices | MediaDeviceInfo[] | An array of available audio output devices. | | videoInputDevices | MediaDeviceInfo[] | An array of available video input devices. | | getStreamRequest | REQUEST_STATES | The state of the request to obtain the media stream (IDLE, PENDING, FULFILLED, or REJECTED). | | getMediaDevicesRequest | REQUEST_STATES | The state of the request to obtain media devices (IDLE, PENDING, FULFILLED, or REJECTED). | | error | unknown | Any error that occurred during media stream or device retrieval. | | start | () => Promise<MediaStream \| null> | Initiates the media stream if not already streaming. | | stop | () => void | Stops the media stream if currently streaming. | | getMediaDevices | () => Promise<MediaDeviceInfo[]> | Retrieves a list of available media devices. | | updateMediaDeviceConstraints | ({ constraints, resetStream }) => Promise<void> | Updates media device constraints and optionally resets the media stream. | | muteAudio | () => void | Mutes all audio tracks in the media stream. | | unmuteAudio | () => void | Unmutes all audio tracks in the media stream. | | muteVideo | () => void | Mutes all video tracks in the media stream. | | unmuteVideo | () => void | Unmutes all video tracks in the media stream. | | addVideoEndedEventListener | (fn: EventListenerOrEventListenerObject) => void | Adds an event listener for 'ended' events on video tracks. | | addAudioEndedEventListener | (fn: EventListenerOrEventListenerObject) => void | Adds an event listener for 'ended' events on audio tracks. | | addVideoMuteEventListener | (fn: EventListenerOrEventListenerObject) => void | Adds an event listener for 'mute' events on video tracks. | | addAudioMuteEventListener | (fn: EventListenerOrEventListenerObject) => void | Adds an event listener for 'mute' events on audio tracks. | | removeVideoEndedEventListener | (fn: EventListenerOrEventListenerObject) => void | Removes an event listener for 'ended' events on video tracks. | | removeAudioEndedEventListener | (fn: EventListenerOrEventListenerObject) => void | Removes an event listener for 'ended' events on audio tracks. | | removeVideoMuteEventListener | (fn: EventListenerOrEventListenerObject) => void | Removes an event listener for 'mute' events on video tracks. | | removeAudioMuteEventListener | (fn: EventListenerOrEventListenerObject) => void | Removes an event listener for 'mute' events on audio tracks. |

Example

Demo - Link

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

Feel free to use and contribute! If you encounter any issues or have suggestions, please open an issue.