React Hooks
The@daydreamlive/react package provides React hooks for easy integration with React applications.
Installation
useBroadcast
Manages broadcasting state and controls.Options
Returns
| Property | Type | Description |
|---|---|---|
status | UseBroadcastStatus | Current state (see below) |
start | (stream: MediaStream) => Promise<void> | Start broadcasting |
stop | () => void | Stop broadcasting |
setMaxFramerate | (fps?: number) => void | Adjust framerate |
Status States
Thestatus is a discriminated union - use status.state to determine the current state:
usePlayer
Manages playback state and controls.Options
Returns
| Property | Type | Description |
|---|---|---|
status | UsePlayerStatus | Current state |
play | () => Promise<void> | Start playback |
stop | () => void | Stop playback |
videoRef | RefObject<HTMLVideoElement> | Attach to <video> |
Status States
Complete Example
Here’s a full example with broadcasting and playback:Next.js Server Actions Pattern
For Next.js apps, create the stream on the server and pass the WHIP URL to the client:Live Examples
- with-react - Basic React hooks demo
- with-compositor - Canvas composition
- with-screen-share - Screen capture
- with-three - Three.js integration
Next Steps
- Broadcast - Core broadcast API
- Player - Core player API
- Compositor - Combine video sources