useScreenShare
Custom hook that captures the user's screen or specific application window. It handles permission errors, stream management, native stop events, and cleanup.
Installation
npx sse-hooks add use-screen-share
yarn dlx sse-hooks add use-screen-share
pnpm dlx sse-hooks add use-screen-share
deno run -A npm:sse-hooks add use-screen-share
bunx sse-hooks add use-screen-share
Usage
example.ts
import { useScreenShare } from "./{hooks file}";
const { stream, error, startCapture, stopCapture } = useScreenShare();
return (
<div>
{error && <p>Error: {error}</p>}
<video
autoPlay
muted
playsInline
ref={(node) => {
if (node && stream) node.srcObject = stream;
}}
/>
<button onClick={() => startCapture()}>Share Screen</button>
<button onClick={stopCapture}>Stop Sharing</button>
</div>
);
API
Parameters
| Prop | Default | Type |
|---|---|---|
initialOptions |
|
The initial options for screen sharing (video/audio). |
Returns
| Return Value | Default | Type |
|---|---|---|
error | - |
|
isLoading | - |
|
isSupported | - |
|
startCapture | - |
|
stopCapture | - |
|
stream | - |
|
Types Aliases
No specific type aliases defined for this component.