useLocalScreenShare
The useLocalScreenShare hook allows you to share your screen with other peers in the room.
const {
shareStream,
startScreenShare,
stopScreenShare,
audioTrack,
videoTrack,
} = useLocalScreenShare({
onProduceStart(producer) {},
onProduceClose() {},
onProduceError() {},
});
Props
The useLocalScreenShare hook accepts an object with the following fields as props.
1. onProduceStartOptionalAdvanced
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
}});
2. onProduceCloseOptionalAdvanced
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
}});
3. onProduceErrorOptionalAdvanced
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
}});
Returns
The useLocalScreenShare hook returns an object with the following fields.
1. shareStreamObject
Description | Type |
---|---|
The media stream for your screen which is being shared. null if screen not shared yet. | MediaStream | null |
2. audioTrackObject
Description | Type |
---|---|
The audio stream track for your screen which is being shared. null if screen not shared yet. | MediaStreamTrack | null |
3. videoTrackObject
Description | Type |
---|---|
The video stream track for your screen which is being shared. null if screen not shared yet. | MediaStreamTrack | null |
4. startScreenShareFunction
Description | Return Type |
---|---|
Start sharing your screen with other peers in the room. | Promise<void> |
5. stopScreenShareFunction
Description | Return Type |
---|---|
Stop sharing your screen with other peers in the room. | Promise<void> |