add clientsinchannel state

This commit is contained in:
Janis
2023-07-24 02:18:43 +02:00
parent bc8a16edc5
commit 477c08232d

View File

@@ -13,6 +13,8 @@ export default function useTSRemoteApp({ remoteAppPort = 5899 }: { remoteAppPort
const [currentChannel, setCurrentChannel] = useState<IChannel | undefined>(undefined); const [currentChannel, setCurrentChannel] = useState<IChannel | undefined>(undefined);
const [currentClient, setCurrentClient] = useState<IClient | undefined>(undefined); const [currentClient, setCurrentClient] = useState<IClient | undefined>(undefined);
const [clientsInChannel, setClientsInChannel] = useState<IClient[]>([]);
useEffect(() => { useEffect(() => {
const tsConnection: ITS5ConnectionHandler = new TS5ConnectionHandler( const tsConnection: ITS5ConnectionHandler = new TS5ConnectionHandler(
remoteAppPort, remoteAppPort,
@@ -36,6 +38,13 @@ export default function useTSRemoteApp({ remoteAppPort = 5899 }: { remoteAppPort
setCurrentChannel(currentChannel); setCurrentChannel(currentChannel);
} }
} }
if (currentChannel) {
const clientsInChannel = clients.filter((client) => {
return client.channel?.id === currentChannel?.id && client.channel.connection.id === activeConnectionId;
});
setClientsInChannel(clientsInChannel);
}
}, [clients, channels, connections, activeConnectionId]); }, [clients, channels, connections, activeConnectionId]);
return { return {
@@ -46,5 +55,6 @@ export default function useTSRemoteApp({ remoteAppPort = 5899 }: { remoteAppPort
currentConnection, currentConnection,
currentChannel, currentChannel,
currentClient, currentClient,
clientsInChannel,
}; };
} }