useLocalVideo
The useLocalVideo hook exposes primitives to interact with your own video stream - coming from your camera device.
Name | Description | Return Type | Params |
---|---|---|---|
stream | Your camera's video stream. Null if not enabled yet. | MediaStream | null | |
track | Your camera's video stream track. Null if not enabled yet. | MediaStreamTrack | null | |
isVideoOn | Your camera's video stream is on or off. | boolean | |
enableVideo | Enable your camera's video stream and start producing it with other peers in the room. | Promise<void> | |
disableVideo | Disable your camera's video stream and stop producing it with other peers in the room. | Promise<void> | |
replaceVideoStream | Replaces the mediastream. | Promise<void> | |
changeVideoSource | Changes the video sources of the devices. | Promise<void> | { deviceId: string } |
Example Usage
import { useLocalVideo } from '@huddle01/react/hooks';
const {
stream,
track,
isVideoOn,
enableVideo,
disableVideo,
replaceVideoStream,
changeVideoSource,
} = useLocalVideo({
onProduceStart(producer) {},
onProduceClose(reason :{
code:number,
tag:string,
message:string
}) {},
});
// enable and disable video
const handleVideo = async () => {
if (isVideoOn) {
await disableVideo();
} else {
await enableVideo();
}
};
Props
The useLocalVideo hook accepts an object with the following fields as props.
onProduceStart
OptionalAdvanced
Description | Return Type |
---|---|
This function will be called when you start producing your camera's video stream i.e sharing it with other peers in the room. | void |
Parameter Name | Type | Description | Required |
---|---|---|---|
producer | Producer | The mediasoup producer object. | Yes |
Example Usage
const localVideo = useLocalVideo({ onProduceStart: (producer) => {
console.log("Started producing your video stream!");
console.log(producer);
// your code here
}});
onProduceClose
OptionalAdvanced
Description | Return Type |
---|---|
This function will be called when you stop producing your camera's video stream. | void |
Example Usage
const localVideo = useLocalVideo({ onProduceClose: (reason) => {
console.log("Stopped producing your video stream!");
// your code here
}});