import React, { FC, useEffect, useRef } from 'react'; import { useRealtimeKitSelector } from '../../src'; const PeerView: FC<{ peerId: string; }> = ({ peerId }) => { const { audioEnabled, audioTrack, videoEnabled, videoTrack, } = useRealtimeKitSelector((meeting) => meeting.participants.active.get(peerId))!; const videoRef = useRef(null); const audioRef = useRef(null); useEffect(() => { if (!audioRef.current) return; if (audioEnabled && audioTrack) { const stream = new MediaStream(); stream.addTrack(audioTrack); audioRef.current.srcObject = stream; } else { audioRef.current.srcObject = null; } }, [audioEnabled, audioTrack]); useEffect(() => { if (!videoRef.current) return; if (videoEnabled && videoTrack) { const stream = new MediaStream(); stream.addTrack(videoTrack); videoRef.current.srcObject = stream; } else { videoRef.current.srcObject = null; } }, [videoEnabled, videoTrack]); return (
); }; function ActiveParticipants() { const activeParticipants = useRealtimeKitSelector( (meeting) => meeting.participants.active, ); return (
{activeParticipants?.toArray().map((peer: { id: string }) => ( ))}
); } function Participants() { const roomJoined = useRealtimeKitSelector( (meeting) => meeting.self.roomJoined, ); const joinedParticipants = useRealtimeKitSelector( (meeting) => meeting.participants.joined, ); if (!joinedParticipants || !roomJoined) { return null; } return (
Participants

Active Participants

Joined Participants

    {joinedParticipants ?.toArray() .map( (peer: { id: string; audioEnabled: boolean; name: string; videoEnabled: boolean; }) => (
  • {peer.name} {' '} - audio: {' '} {JSON.stringify(peer.audioEnabled)} , video: {' '} {JSON.stringify(peer.videoEnabled)}
  • ), )}
); } export default Participants;