SSE Hooks

useUserMedia

Custom hook that captures audio and video from the user's device.

Installation

npx sse-tool add use-user-media

Usage

import { useUserMedia } from "./{hooks file}";

const { stream, error, startCapture, stopCapture } = useUserMedia();

return (
  <div>
    {error && <p>Error: {error}</p>}
    <video
      autoPlay
      muted
      playsInline
      ref={(node) => {
        if (node && stream) node.srcObject = stream;
      }}
    />
    <button onClick={() => startCapture()}>Start Camera</button>
    <button onClick={stopCapture}>Stop Camera</button>
  </div>
);

API

Parameters

NameTypeDescription
initialConstraintsUseUserMediaConstraintsThe initial constraints for audio and video.

Return Value

Returns UseUserMediaReturn.

An object containing the stream, error state, and control functions.

Changelog

c165d — feat: enhance useRoleGuard and useSSR hooks with additional options and documentation

30da4 — feat: add new hooks and their metadata

b17e8 — feat: add computed and reactive hooks with support for audio recording and media session management

Built with Love • © 2026