useUserMedia

A React Hook that helps to manage the user media.

Demo

Source

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const { stream, isSupported } = useUserMedia(options)

Options

export interface UseUserMediaOptions { /** * Callback when MediaStream is ready */ onStart?: (stream: MediaStream) => void /** * Callback when MediaStream is stopped */ onStop?(): void /** * Recreate stream when deviceIds or constraints changed * * @defaultValue true */ autoSwitch?: boolean /** * MediaStreamConstraints to be applied to the requested MediaStream * If provided, the constraints will override videoDeviceId and audioDeviceId * * @defaultValue {} */ constraints?: MediaStreamConstraints }

Returns

export interface UseUserMediaReturns extends Pausable { /** * The current MediaStream */ stream: MutableRefObject<MediaStream | null> /** * Whether the browser supports getUserMedia */ isSupported: boolean }