/* eslint-disable react-hooks/exhaustive-deps */ import "@styles/App.scss"; import { IChannel, IClient, IConnection, ITS5ConnectionHandler } from "@interfaces/teamspeak"; import { useEffect, useState } from "react"; import Viewer from "./Viewer"; import { useSearchParams } from "react-router-dom"; import { TS5ConnectionHandler } from "@handlers/teamspeak/connectionHandler"; export default function App() { const [searchParams] = useSearchParams(); const [clients, setClients] = useState([]); const [channels, setChannels] = useState([]); const [connections, setConnections] = useState([]); const [activeConnectionId, setActiveConnectionId] = useState(1); const [currentConnection, setCurrentConnection] = useState(undefined); const [currentChannel, setCurrentChannel] = useState(undefined); const [currentClient, setCurrentClient] = useState(undefined); function setCurrentStates() { const currentConnection = connections.find((connection) => connection.id === activeConnectionId); setCurrentConnection(currentConnection); if (currentConnection) { const currentClient = clients.find((client) => client.id === currentConnection.clientId); setCurrentClient(currentClient); if (currentClient) { const currentChannel = channels.find((channel) => channel.id === currentClient.channel?.id); setCurrentChannel(currentChannel); if (currentChannel) { return currentChannel; } } } } useEffect(() => { const remoteAppPort = searchParams.get("remoteAppPort"); console.log(searchParams.get("hideNonTalking")); const tsConnection: ITS5ConnectionHandler = new TS5ConnectionHandler( parseInt(remoteAppPort ?? "5899"), setConnections, setChannels, setClients, setActiveConnectionId ); tsConnection.connect(); }, []); useEffect(() => { setCurrentStates(); }, [clients, channels, connections, activeConnectionId]); return (
{ if (client.channel?.id === currentChannel?.id && client.channel.connection.id === activeConnectionId) { return client; } }) as IClient[] } channel={currentChannel} />
); }