useLocalVideo

useLocalVideo

The useLocalVideo hook exposes primitives to interact with your own video stream - coming from your camera device.

NameDescriptionReturn TypeParams
streamYour camera's video stream. Null if not enabled yet.MediaStream | null
trackYour camera's video stream track. Null if not enabled yet.MediaStreamTrack | null
isVideoOnYour camera's video stream is on or off.boolean
enableVideoEnable your camera's video stream and start producing it with other peers in the room.Promise<void>
disableVideoDisable your camera's video stream and stop producing it with other peers in the room.Promise<void>
replaceVideoStreamReplaces the mediastream.Promise<void>
changeVideoSourceChanges 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
DescriptionReturn 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 NameTypeDescriptionRequired
producerProducerThe 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
DescriptionReturn 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
}});
Audio/Video Infrastructure designed for the developers to empower them ship simple yet powerful Audio/Video Apps.
support
company
Copyright © 2024 Graphene 01, Inc. All Rights Reserved.