fn

useDisplayMedia

v0.0.14testeddemo

Reactive mediaDevices.getDisplayMedia (screen share) streaming.

Examples

ts
const { stream, enabled, isSupported } = useDisplayMedia();
videoEl.srcObject = stream.value ?? null;
enabled.value = true; // prompts the screen-share picker
ts
const { start, stop } = useDisplayMedia({ audio: true });
await start();

Demo

Loading demo…

Signature

ts
export function useDisplayMedia(options: UseDisplayMediaOptions ={ ... }

Parameters

ParameterTypeDescription
options?UseDisplayMediaOptionsOptions

Returns

UseDisplayMediaReturnstream, start, stop, enabled and isSupported
PropertyTypeDescription
isSupportedReadonly<Ref<boolean>>Whether navigator.mediaDevices.getDisplayMedia is available.
streamShallowRef<MediaStream | undefined>The active MediaStream, or undefined when not sharing.
start() => Promise<MediaStream | undefined>Request the screen-share picker and start the stream. Resolves to the stream (or undefined when unsupported / cancelled). Concurrent calls are deduped and an already-running stream is returned as-is.
stop() => voidStop every track and clear the stream.
enabledShallowRef<boolean>Two-way switch mirroring the live state of the stream. Set it to true to start sharing and false to stop.