useRemoteVideo

useRemoteVideo

The useRemoteVideo hook exposes primitives to interact with video streams coming from other peers in the room.

NameDescriptionReturn Type
streamRemote peer's video stream. null if not enabled yet.MediaStream | null
trackRemote peer's video stream track. null if not enabled yet.MediaStreamTrack | null
stateState of the remote peer's video stream."playable" | "unavailable" | "stopped" | "paused" | "available"
isVideoOnState of the remote peer's video stream.boolean

Example Usage

import { useRemoteVideo } from '@huddle01/react/hooks';
import { MediaStream, RTCView } from "react-native-webrtc";
 
const {
    state,
    track,
    stream,
    isVideoOn,
  } = useRemoteVideo({
    peerId: "remote-peer-id",
    onClose(reason:{
    code: number;
    tag: string;
    message: string;
    }) {},
    onPlayable(data:{
      stream:Mediastream,
      track:Mediatrack,
      label:"video"
    }) {}
  });
 
return (
  <View>
      <RTCView streamURL={(videoStream as MediaStream | null)?.toURL() ?? ""}/>
  </View>
);

Props

The useRemoteVideo hook accepts an object with the following fields as props.

peerId

Required
DescriptionType
The peerId of the peer whose video stream you want to consume.string

Example Usage

const remoteVideo = useRemoteVideo({ peerId: "remote-peer-id" });

onPlayable

OptionalAdvanced
DescriptionReturn Type
This function will be called when the other peer has enabled their video stream and it can now be played on your end.void
Parameter NameTypeDescriptionRequired
data{track: MediaStreamTrack; stream: MediaStream; label: 'video';}The data object containing the video stream and video stream track that can be played.Yes

Example Usage

const remoteVideo = useRemoteVideo({ peerId: "remote-peer-id", onPlayable: (data) => {
	console.log("Ready to play remote peer's video stream!");
    // your code here
}});

onClose

OptionalAdvanced
DescriptionReturn Type
This function will be called when the other peer disabled their camera's video stream.void

Example Usage

const remoteVideo = useRemoteVideo({ peerId: "remote-peer-id", onClose: (reason) => {
	console.log("Remote video stream has been closed!");
    // 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.