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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-media-manager

v0.1.1

Published

Production-ready React hooks for managing media devices.

Readme

react-media-manager

Production-ready React hooks for cameras, microphones, speakers, permissions, device changes, and recording. The package is SSR-safe, tree-shakeable, TypeScript-first, and built for React 18+ applications across Next.js, Vite, CRA, Remix, and plain React setups.

Features

  • Camera, microphone, and speaker device enumeration
  • Stream lifecycle management with start, stop, pause, resume, mute, and unmute flows
  • Permission querying and permission request helpers
  • Automatic device-change detection
  • Audio output switching through setSinkId when supported
  • Optional media recording hook
  • Human-readable normalized media errors
  • TypeScript declarations for all public hooks and device models

Installation

npm install react-media-manager

Peer dependencies:

  • react >= 18
  • react-dom >= 18

Quick Start

import { useCamera } from 'react-media-manager';

export function CameraPreview() {
	const { cameras, currentCamera, stream, isActive, error, start, stop, switchCamera } = useCamera();

	return (
		<div>
			<button onClick={() => void start()} disabled={isActive}>
				Start camera
			</button>
			<button onClick={stop} disabled={!isActive}>
				Stop camera
			</button>
			<select
				value={currentCamera?.deviceId ?? ''}
				onChange={(event) => void switchCamera(event.target.value)}
			>
				{cameras.map((camera) => (
					<option key={camera.deviceId} value={camera.deviceId}>
						{camera.label || camera.deviceId}
					</option>
				))}
			</select>
			{stream && <video autoPlay muted playsInline ref={(node) => node && (node.srcObject = stream)} />}
			{error && <p>{error.message}</p>}
		</div>
	);
}

API Overview

useCamera(options?)

Returns camera devices, the active stream, camera status, permission state, and camera controls.

const {
	cameras,
	currentCamera,
	stream,
	isActive,
	isLoading,
	isPaused,
	permission,
	status,
	error,
	start,
	stop,
	pause,
	resume,
	switchCamera,
	refreshDevices,
	refresh,
	destroy,
} = useCamera();

useMicrophone(options?)

Returns microphone devices, audio stream state, mute state, and live volume level monitoring when supported.

useSpeaker(target)

Returns output devices and a switchSpeaker helper for HTMLMediaElement.setSinkId capable browsers.

usePermissions()

Returns live camera and microphone permission state plus requestCamera, requestMicrophone, and requestAll helpers.

useMediaDevices(options?)

Returns grouped device lists and a refresh method.

useDeviceChange()

Returns refreshed devices plus changeCount and lastChangeAt each time navigator.mediaDevices.devicechange fires.

useMediaRecorder()

Returns recorder lifecycle helpers, chunk data, final Blob, object URL, and download support.

MediaProvider

Provides shared defaults:

<MediaProvider
	value={{
		autoRefreshOnDeviceChange: true,
		cameraConstraints: { width: 1280, height: 720 },
		microphoneConstraints: { echoCancellation: true },
		monitorMicrophoneVolume: true,
	}}
>
	<App />
</MediaProvider>

TypeScript

Public types include:

  • CameraDevice
  • MicrophoneDevice
  • SpeakerDevice
  • MediaPermissionState
  • MediaError
  • MediaConstraints

Browser Support

  • Chrome: supported
  • Edge: supported
  • Firefox: supported, with browser-specific output-device limitations
  • Safari: supported for core camera and microphone hooks, with limited output-device support
  • Brave: supported

The library degrades gracefully when MediaDevices, Permissions, MediaRecorder, or setSinkId are not available.

Errors

Errors are normalized into a consistent shape:

type MediaError = {
	code:
		| 'abort'
		| 'browser-not-supported'
		| 'device-in-use'
		| 'device-not-found'
		| 'invalid-state'
		| 'not-allowed'
		| 'not-readable'
		| 'overconstrained'
		| 'permission-denied'
		| 'permission-query-failed'
		| 'recorder-not-supported'
		| 'speaker-not-supported'
		| 'unknown';
	message: string;
	cause?: unknown;
	name?: string;
};

Development

npm install
npm run build
npm test

Current local validation:

  • Build: passes with tsup
  • Tests: 16 passing
  • Coverage: 90.87% statements, 90.87% lines, 91.2% functions

Examples and Docs

  • JavaScript example: examples/js-example/App.jsx
  • TypeScript example: examples/ts-example/App.tsx
  • Next.js example notes: docs/nextjs.md
  • Troubleshooting and FAQ: docs/troubleshooting.md