useLocalScreenShare

useLocalScreenShare

The useLocalScreenShare hook allows you to share your screen with other peers in the room.

NameDescriptionReturn Type
shareStreamThe media stream for your screen which is being shared. null if screen not shared yet.MediaStream | null
audioTrackThe audio stream track for your screen which is being shared. null if screen not shared yet.MediaStreamTrack | null
videoTrackThe video stream track for your screen which is being shared. null if screen not shared yet.MediaStreamTrack | null
startScreenShareStart sharing your screen with other peers in the room.Promise<void>
stopScreenShareStop 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
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
}});

onProduceClose

OptionalAdvanced
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
}});

onProduceError

OptionalAdvanced
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
}});
Audio/Video Infrastructure designed for developers to empower them to ship simple yet powerful Audio/Video Apps.
support
company
Copyright © 2024 Graphene 01, Inc. All Rights Reserved.