useLocalVideo
The useLocalVideo hook exposes primitives to interact with your own video stream - coming from your camera device.
const {
stream,
track,
enableVideo,
disableVideo,
} = useLocalVideo({
onProduceStart(producer) {},
onProduceClose() {},
onProduceError() {},
});
Props
The useLocalVideo hook accepts an object with the following fields as props.
1. onProduceStartOptionalAdvanced
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
}});
2. onProduceCloseOptionalAdvanced
Description | Return Type |
---|---|
This function will be called when you stop producing your camera's video stream. | void |
Example Usage
const localVideo = useLocalVideo({ onProduceClose: () => {
console.log("Stopped producing your video stream!");
// your code here
}});
3. onProduceErrorOptionalAdvanced
Description | Return Type |
---|---|
This function will be called when there was an error encountered while producing your camera's video stream. | void |
Example Usage
const localVideo = useLocalVideo({ onProduceError: () => {
console.log("There was an error in producing your video stream!");
// your code here
}});
Returns
The useLocalVideo hook returns an object with the following fields.
1. streamObject
Description | Type |
---|---|
Your camera's video stream. null if not enabled yet. | MediaStream | null |
2. trackObject
Description | Type |
---|---|
Your camera's video stream track. null if not enabled yet. | MediaStreamTrack | null |
3. enableVideoFunction
Description | Return Type |
---|---|
Enable your camera's video stream and start producing it with other peers in the room. | Promise<void> |
4. disableVideoFunction
Description | Return Type |
---|---|
Disable your camera's video stream and stop producing it with other peers in the room. | Promise<void> |