useRemoteScreenShare
The useRemoteScreenShare hook allows you to receive the media stream for another peer's screen being shared.
const {
videoStream,
audioStream,
videoTrack,
audioTrack,
state,
} = useRemoteScreenShare({
peerId: "remote-peer-id",
onPlayable(data) {},
onClose() {},
});
Props
The useRemoteScreenShare hook accepts an object with the following fields as props.
1. peerIdRequired
Description | Type |
---|---|
The peerId of the peer whose screenshare stream you want to consume. | string |
Example Usage
const remoteScreenShare = useRemoteScreenShare({ peerId: "remote-peer-id" });
2. onPlayableOptionalAdvanced
Description | Return Type |
---|---|
This function will be called when the other peer has started sharing their screen and it can now be played on your end. | void |
Parameter Name | Type | Description | Required |
---|---|---|---|
data | {track: MediaStreamTrack; stream: MediaStream; label: 'share-video' | 'share-audio';} | The data object containing the media stream and media stream track that can be played. | Yes |
Example Usage
const remoteScreenShare = useRemoteScreenShare({ peerId: "remote-peer-id", onPlayable: (data) => {
console.log("Ready to play remote peer's screen being shared!");
// your code here
}});
3. onCloseOptionalAdvanced
Description | Return Type |
---|---|
This function will be called when the other peer stops sharing their screen. | void |
Example Usage
const remoteScreenShare = useRemoteScreenShare({ peerId: "remote-peer-id", onClose: () => {
console.log("Remote peer has stopped sharing their screen!");
// your code here
}});
Returns
The useRemoteScreenShare hook returns an object with the following fields.
1. videoStreamObject
Description | Type |
---|---|
The video stream for remote peer's screen which is being shared. null if screen not shared yet. | MediaStream | null |
2. audioStreamObject
Description | Type |
---|---|
The audio stream for remote peer's screen which is being shared. null if screen not shared yet. | MediaStream | null |
3. videoTrackObject
Description | Type |
---|---|
The video stream track for remote peer's screen which is being shared. null if screen not shared yet. | MediaStreamTrack | null |
4. audioTrackObject
Description | Type |
---|---|
The audio stream track for remote peer's screen which is being shared. null if screen not shared yet. | MediaStreamTrack | null |
5. stateObject
Description | Type |
---|---|
State of the remote peer's screenshare stream. | "playable" | "unavailable" | "stopped" | "paused" | "available" |