MicProtocol / apps /web /src /components /livekit /ParticipantGrid.tsx
Benaah's picture
Upload folder using huggingface_hub
fb12607 verified
Raw History Blame Contribute Delete
3.65 kB
"use client";
import { useParticipants, ParticipantTile, ParticipantAudioTile } from "@livekit/components-react";
import { Mic, MicOff, Video, VideoOff, User } from "lucide-react";
interface ParticipantGridProps {
roomName?: string;
onMuteAudio?: (identity: string) => void;
onMuteVideo?: (identity: string) => void;
}
export function ParticipantGrid({ roomName, onMuteAudio, onMuteVideo }: ParticipantGridProps) {
const participants = useParticipants();
return (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{participants.map((participant) => (
<ParticipantCard
key={participant.identity}
participant={participant}
onMuteAudio={onMuteAudio}
onMuteVideo={onMuteVideo}
/>
))}
</div>
);
}
interface ParticipantCardProps {
participant: any;
onMuteAudio?: (identity: string) => void;
onMuteVideo?: (identity: string) => void;
}
function ParticipantCard({ participant, onMuteAudio, onMuteVideo }: ParticipantCardProps) {
const isLocal = participant.kind === "local";
const identity = participant.identity;
const name = participant.name || identity;
// Find microphone and camera tracks
const tracks = (participant as any).tracks;
const trackValues = tracks ? Array.from(tracks.values()) : [];
const micTrackPub: any = trackValues.find(
(pub: any) => pub.track?.source === "microphone" && pub.track?.kind === "audio"
);
const camTrackPub: any = trackValues.find(
(pub: any) => pub.track?.source === "camera" && pub.track?.kind === "video"
);
const isAudioMuted = !micTrackPub?.isSubscribed || micTrackPub?.muted;
const isVideoEnabled = !!camTrackPub?.track;
return (
<div className="bg-muted rounded-lg p-4 border border-border relative overflow-hidden">
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-2">
<div className="w-2 h-2 rounded-full bg-green-500 animate-pulse" />
<span className="text-sm font-medium truncate max-w-[120px]">{name}</span>
{isLocal && <span className="text-xs text-muted-foreground">(you)</span>}
</div>
<div className="flex gap-1">
{onMuteAudio && (
<button
onClick={() => onMuteAudio(identity)}
className="p-1.5 hover:bg-muted/50 rounded"
title="Mute audio"
>
{isAudioMuted ? <MicOff size={14} /> : <Mic size={14} />}
</button>
)}
{onMuteVideo && (
<button
onClick={() => onMuteVideo(identity)}
className="p-1.5 hover:bg-muted/50 rounded"
title="Mute video"
>
{!isVideoEnabled ? <VideoOff size={14} /> : <Video size={14} />}
</button>
)}
</div>
</div>
<div className="aspect-video bg-muted/50 rounded overflow-hidden flex items-center justify-center mb-2">
{isVideoEnabled && camTrackPub?.track ? (
<ParticipantTile participant={participant} className="w-full h-full object-cover" />
) : (
<div className="absolute inset-0 flex items-center justify-center opacity-30">
<User size={32} />
</div>
)}
</div>
<div className="flex items-center gap-2">
{micTrackPub?.track && (
<ParticipantAudioTile participant={participant} />
)}
<div className="flex-1 h-1.5 bg-muted/50 rounded overflow-hidden">
<div className="h-full bg-primary w-1/3" />
</div>
</div>
</div>
);
}