import React, { useState, useEffect, useContext } from 'react'; import { Tabs } from 'antd'; import { ServerStatusContext } from '../../../utils/server-status-context'; import { CONNECTED_CLIENTS, fetchData, DISABLED_USERS, MODERATORS, BANNED_IPS, } from '../../../utils/apis'; import { UserTable } from '../../../components/UserTable'; import { ClientTable } from '../../../components/ClientTable'; import { BannedIPsTable } from '../../../components/BannedIPsTable'; const { TabPane } = Tabs; export const FETCH_INTERVAL = 10 * 1000; // 10 sec export default function ChatUsers() { const context = useContext(ServerStatusContext); const { online } = context || {}; const [disabledUsers, setDisabledUsers] = useState([]); const [ipBans, setIPBans] = useState([]); const [clients, setClients] = useState([]); const [moderators, setModerators] = useState([]); const getInfo = async () => { try { const result = await fetchData(DISABLED_USERS); setDisabledUsers(result); } catch (error) { console.log('==== error', error); } try { const result = await fetchData(CONNECTED_CLIENTS); setClients(result); } catch (error) { console.log('==== error', error); } try { const result = await fetchData(MODERATORS); setModerators(result); } catch (error) { console.error('error fetching moderators', error); } try { const result = await fetchData(BANNED_IPS); setIPBans(result); } catch (error) { console.error('error fetching banned ips', error); } }; useEffect(() => { let getStatusIntervalId = null; getInfo(); getStatusIntervalId = setInterval(getInfo, FETCH_INTERVAL); // returned function will be called on component unmount return () => { clearInterval(getStatusIntervalId); }; }, [online]); const connectedUsers = online ? ( <>

Visit the{' '} documentation {' '} to configure additional details about your viewers.

) : (

When a stream is active and chat is enabled, connected chat clients will be displayed here.

); return ( Connected {online ? `(${clients.length})` : '(offline)'}} key="1"> {connectedUsers} Banned Users ({disabledUsers.length})} key="2"> IP Bans ({ipBans.length})} key="3"> Moderators ({moderators.length})} key="4"> ); }