"use client"; import { useEffect, useState } from "react"; import { usePilotConnectionStore } from "_store/pilot/connectionStore"; import { Disc, Mic, PlugZap, ServerCrash, ShieldQuestion, Signal, SignalLow, SignalMedium, WifiOff, ZapOff, } from "lucide-react"; import { useAudioStore } from "_store/audioStore"; import { cn } from "_helpers/cn"; import { ConnectionQuality } from "livekit-client"; import { ROOMS } from "_data/livekitRooms"; import { useDispatchConnectionStore } from "_store/dispatch/connectionStore"; import { useSession } from "next-auth/react"; import { useSounds } from "_components/Audio/useSounds"; export const Audio = () => { const { speakingParticipants, isTalking, toggleTalking, transmitBlocked, connect, state, connectionQuality, disconnect, remoteParticipants, room, message, removeMessage, } = useAudioStore(); const [selectedRoom, setSelectedRoom] = useState("LST_01"); useSounds({ isReceiving: speakingParticipants.length > 0, isTransmitting: isTalking, unpausedTracks: speakingParticipants, transmitBlocked, }); const { selectedStation, status: pilotState } = usePilotConnectionStore((state) => state); const { selectedZone, status: dispatcherState } = useDispatchConnectionStore((state) => state); const session = useSession(); const [isReceivingBlick, setIsReceivingBlick] = useState(false); const [recentSpeakers, setRecentSpeakers] = useState([]); useEffect(() => { if (speakingParticipants.length > 0) { setRecentSpeakers(speakingParticipants); } else if (recentSpeakers.length > 0) { const timeout = setTimeout(() => { setRecentSpeakers([]); }, 10000); return () => clearTimeout(timeout); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [speakingParticipants]); useEffect(() => { if (speakingParticipants.length > 0) { setIsReceivingBlick(true); const timeout = setInterval(() => { setIsReceivingBlick((s) => !s); }, 1000); return () => { clearTimeout(timeout); setIsReceivingBlick(false); }; } }, [setIsReceivingBlick, speakingParticipants]); useEffect(() => { if (message && state !== "error") { const timeout = setTimeout(() => { removeMessage(); }, 10000); return () => clearTimeout(timeout); } }, [message, removeMessage, state]); const displayedSpeakers = speakingParticipants.length > 0 ? speakingParticipants : recentSpeakers; const canStopOtherSpeakers = dispatcherState === "connected"; const role = (dispatcherState === "connected" && selectedZone) || (pilotState == "connected" && selectedStation?.bosCallsignShort) || session.data?.user?.publicId; return ( <>
{message && (
)} {displayedSpeakers.length > 0 && (
0 && "tooltip", )} data-tip="Funkspruch unterbrechen" >
)} {state === "connected" && (
{connectionQuality === ConnectionQuality.Excellent && } {connectionQuality === ConnectionQuality.Good && } {connectionQuality === ConnectionQuality.Poor && } {connectionQuality === ConnectionQuality.Lost && } {connectionQuality === ConnectionQuality.Unknown && ( )}
{remoteParticipants}
    {ROOMS.map((r) => (
  • ))}
)}
); };