Skip to content

useDisplayMedia ​

Category
Browser

Hook that provides screen sharing functionality using the Display Media API

typescript
import { useDisplayMedia } from '@siberiacancode/reactuse';

Usage ​

typescript
const { stream, sharing, start, stop } = useDisplayMedia(ref);
// or
const { ref, stream, sharing, start, stop } = useDisplayMedia<HTMLVideoElement>();

Demo ​

Api ​

Parameters

NameTypeDefaultNote
targetTarget-The target video element to display the media stream
options.audio?boolean | MediaTrackConstraints-Whether to enable audio sharing
options.enabled?booleanfalseWhether to start immediately
options.video?boolean | MediaTrackConstraints-Whether to enable video sharing

Parameters

NameTypeDefaultNote
options.audio?boolean | MediaTrackConstraints-Whether to enable audio sharing
options.enabled?booleanfalseWhether to start immediately
options.video?boolean | MediaTrackConstraints-Whether to enable video sharing

Contributors ​

Source • Demo