useLocalScreenShare
The useLocalScreenShare hook allows you to share your screen with other peers in the room.
| Name | Description | Return Type |
|---|---|---|
| shareStream | The media stream for your screen which is being shared. null if screen not shared yet. | MediaStream | null |
| audioTrack | The audio stream track for your screen which is being shared. null if screen not shared yet. | MediaStreamTrack | null |
| videoTrack | The video stream track for your screen which is being shared. null if screen not shared yet. | MediaStreamTrack | null |
| startScreenShare | Start sharing your screen with other peers in the room. | Promise<void> |
| stopScreenShare | Stop sharing your screen with other peers in the room. | Promise<void> |
Example Usage
import { useLocalScreenShare } from "@huddle01/react/hooks"
const {
shareStream,
startScreenShare,
stopScreenShare,
audioTrack,
videoTrack,
} = useLocalScreenShare({
onProduceStart(producer) {},
onProduceClose() {},
onProduceError() {},
});
const startSharing = async () => {
await startScreenShare();
}
const stopSharing = async () => {
await stopScreenShare();
}Props
The useLocalScreenShare hook accepts an object with the following fields as props.
onProduceStart
OptionalAdvanced
| Description | Return Type |
|---|---|
| This function will be called when you start sharing your screen with other peers in the room. | void |
| Parameter Name | Type | Description | Required |
|---|---|---|---|
| producer | Producer | The mediasoup producer object. | Yes |
Example Usage
const localScreenShare = useLocalScreenShare({ onProduceStart: (producer) => {
console.log("Started screen share!");
console.log(producer);
// your code here
}});onProduceClose
OptionalAdvanced
| Description | Return Type |
|---|---|
| This function will be called when you stop sharing your screen with other peers in the room. | void |
Example Usage
const localScreenShare = useLocalScreenShare({ onProduceClose: () => {
console.log("Stopped screen share!");
// your code here
}});onProduceError
OptionalAdvanced
| Description | Return Type |
|---|---|
| This function will be called when there was an error encountered while sharing your screen. | void |
Example Usage
const localScreenShare = useLocalScreenShare({ onProduceError: () => {
console.log("There was an error in sharing your screen!");
// your code here
}});