useScreenShare
Custom hook that captures the user's screen or specific application window.
Installation
npx sse-tool add use-screen-share
npm install sse-hooks
Usage
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>
);
import { useScreenShare } from "sse-hooks";
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
| Name | Type | Description |
|---|---|---|
| initialOptions | UseScreenShareOptions | The initial options for screen sharing (video/audio). |
Return Value
Returns Object.
An object containing the stream, error state, and control functions.