import Enclave from "@/app/app"; import { ChannelPageProps } from "../PageView"; import { useEffect, useRef } from "react"; import { invoke } from "@tauri-apps/api/core"; import { cn } from "@/lib/utils"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; export default function VoiceChannel({ appRef, }: { appRef: React.RefObject | null>; }) { const channel = appRef.current?.page?.channel; if (!channel) return null; const lastChannelId = useRef(null); useEffect(() => { const hostname = appRef.current?.server?.hostname; if (!hostname) return; if (lastChannelId.current === channel.id) return; lastChannelId.current = channel.id; invoke("disconnect_from_vc"); if (channel.kind !== "voice" || !appRef.current?.server) return; appRef.current.server.voiceJoin = (pin, channelId) => { invoke("connect_to_vc", { hostname, pin, channelId }).catch( console.error, ); }; appRef.current.server.websocket?.send({ method: "JoinVoice", channel_id: channel.id, }); }, [channel.id]); const speakers = appRef.current?.server?.voiceChatSpeakers && Object.keys(appRef.current?.server?.voiceChatSpeakers); const users = appRef.current?.server?.voiceChatUsers[channel.id]; const usersLength = users?.length || 0; // Dynamic grid column layout based on user count const getGridCols = () => { if (usersLength <= 3) return "grid-cols-1"; if (usersLength <= 6) return "grid-cols-3"; if (usersLength <= 9) return "grid-cols-3"; return "grid-cols-5"; }; // Avatar sizing scales up for fewer participants const getAvatarSize = () => { if (usersLength <= 2) return "h-24 w-24 text-3xl"; if (usersLength <= 4) return "h-20 w-20 text-2xl"; return "h-14 w-14 text-lg"; }; return (

{channel.name}

{users?.map((pubkey) => { const user = appRef.current?.server?.users[pubkey]; const isSpeaking = speakers?.includes(pubkey); const displayName = user?.displayName || "Unknown User"; const fallbackLetter = displayName.charAt(0).toUpperCase(); return (
{/* Avatar Container */}
{fallbackLetter} {/* Mute indicator badge overlay */} {/*{user?.isMuted && (
)}*/}
{displayName}
); })}
); }