Shinigami Hooks
useLocalScreenShare

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
DescriptionReturn Type
This function will be called when you start sharing your screen with other peers in the room.void
Parameter NameTypeDescriptionRequired
producerProducerThe mediasoup producer object.Yes
Example Usage
const localScreenShare = useLocalScreenShare({ onProduceStart: (producer) => {
	console.log("Started screen share!");
	console.log(producer);
    // your code here
}});
2. onProduceCloseOptionalAdvanced
DescriptionReturn 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
DescriptionReturn 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
DescriptionType
The media stream for your screen which is being shared. null if screen not shared yet.MediaStream | null
2. audioTrackObject
DescriptionType
The audio stream track for your screen which is being shared. null if screen not shared yet.MediaStreamTrack | null
3. videoTrackObject
DescriptionType
The video stream track for your screen which is being shared. null if screen not shared yet.MediaStreamTrack | null
4. startScreenShareFunction
DescriptionReturn Type
Start sharing your screen with other peers in the room.Promise<void>
5. stopScreenShareFunction
DescriptionReturn Type
Stop sharing your screen with other peers in the room.Promise<void>
Audio/Video Infrastructure designed for the developers to empower them ship simple yet powerful Audio/Video Apps.
support
company
Copyright © 2022 Graphene 01, Inc. All Rights Reserved.