2021-06-22 06:19:00 +03:00
|
|
|
import React, { useState, useEffect, useContext } from 'react';
|
2021-12-07 05:01:30 +03:00
|
|
|
import { Tabs } from 'antd';
|
2021-06-22 06:19:00 +03:00
|
|
|
import { ServerStatusContext } from '../../utils/server-status-context';
|
2022-03-07 07:39:36 +03:00
|
|
|
import {
|
|
|
|
CONNECTED_CLIENTS,
|
|
|
|
fetchData,
|
|
|
|
DISABLED_USERS,
|
|
|
|
MODERATORS,
|
|
|
|
BANNED_IPS,
|
|
|
|
} from '../../utils/apis';
|
2021-07-20 08:02:02 +03:00
|
|
|
import UserTable from '../../components/user-table';
|
|
|
|
import ClientTable from '../../components/client-table';
|
2022-03-07 07:39:36 +03:00
|
|
|
import BannedIPsTable from '../../components/banned-ips-table';
|
2021-06-22 06:19:00 +03:00
|
|
|
|
2021-11-13 08:28:29 +03:00
|
|
|
const { TabPane } = Tabs;
|
2021-06-22 06:19:00 +03:00
|
|
|
|
2021-07-20 08:02:02 +03:00
|
|
|
export const FETCH_INTERVAL = 10 * 1000; // 10 sec
|
2021-06-22 06:19:00 +03:00
|
|
|
|
|
|
|
export default function ChatUsers() {
|
|
|
|
const context = useContext(ServerStatusContext);
|
|
|
|
const { online } = context || {};
|
|
|
|
|
2021-07-20 08:02:02 +03:00
|
|
|
const [disabledUsers, setDisabledUsers] = useState([]);
|
2022-03-07 07:39:36 +03:00
|
|
|
const [ipBans, setIPBans] = useState([]);
|
2021-06-22 06:19:00 +03:00
|
|
|
const [clients, setClients] = useState([]);
|
2021-11-08 11:51:17 +03:00
|
|
|
const [moderators, setModerators] = useState([]);
|
2021-06-22 06:19:00 +03:00
|
|
|
|
|
|
|
const getInfo = async () => {
|
|
|
|
try {
|
2021-07-20 08:02:02 +03:00
|
|
|
const result = await fetchData(DISABLED_USERS);
|
|
|
|
setDisabledUsers(result);
|
2021-06-22 06:19:00 +03:00
|
|
|
} catch (error) {
|
|
|
|
console.log('==== error', error);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const result = await fetchData(CONNECTED_CLIENTS);
|
|
|
|
setClients(result);
|
|
|
|
} catch (error) {
|
|
|
|
console.log('==== error', error);
|
|
|
|
}
|
2021-11-08 11:51:17 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
const result = await fetchData(MODERATORS);
|
|
|
|
setModerators(result);
|
|
|
|
} catch (error) {
|
|
|
|
console.error('error fetching moderators', error);
|
|
|
|
}
|
2022-03-07 07:39:36 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
const result = await fetchData(BANNED_IPS);
|
|
|
|
setIPBans(result);
|
|
|
|
} catch (error) {
|
|
|
|
console.error('error fetching banned ips', error);
|
|
|
|
}
|
2021-06-22 06:19:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
let getStatusIntervalId = null;
|
|
|
|
|
|
|
|
getInfo();
|
|
|
|
|
2021-07-20 08:02:02 +03:00
|
|
|
getStatusIntervalId = setInterval(getInfo, FETCH_INTERVAL);
|
|
|
|
// returned function will be called on component unmount
|
|
|
|
return () => {
|
|
|
|
clearInterval(getStatusIntervalId);
|
|
|
|
};
|
2021-06-22 06:19:00 +03:00
|
|
|
}, [online]);
|
|
|
|
|
2021-07-20 08:02:02 +03:00
|
|
|
const connectedUsers = online ? (
|
|
|
|
<>
|
|
|
|
<ClientTable data={clients} />
|
|
|
|
<p className="description">
|
|
|
|
Visit the{' '}
|
|
|
|
<a
|
|
|
|
href="https://owncast.online/docs/viewers/?source=admin"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
documentation
|
|
|
|
</a>{' '}
|
|
|
|
to configure additional details about your viewers.
|
|
|
|
</p>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<p className="description">
|
|
|
|
When a stream is active and chat is enabled, connected chat clients will be displayed here.
|
|
|
|
</p>
|
|
|
|
);
|
2021-08-13 09:51:13 +03:00
|
|
|
|
2021-06-22 06:19:00 +03:00
|
|
|
return (
|
2021-11-13 08:28:29 +03:00
|
|
|
<Tabs defaultActiveKey="1">
|
|
|
|
<TabPane tab={<span>Connected {online ? `(${clients.length})` : '(offline)'}</span>} key="1">
|
|
|
|
{connectedUsers}
|
|
|
|
</TabPane>
|
2022-03-07 07:39:36 +03:00
|
|
|
<TabPane tab={<span>Banned Users ({disabledUsers.length})</span>} key="2">
|
2021-11-13 08:28:29 +03:00
|
|
|
<UserTable data={disabledUsers} />
|
|
|
|
</TabPane>
|
2022-03-07 07:39:36 +03:00
|
|
|
<TabPane tab={<span>IP Bans ({ipBans.length})</span>} key="3">
|
|
|
|
<BannedIPsTable data={ipBans} />
|
|
|
|
</TabPane>
|
|
|
|
<TabPane tab={<span>Moderators ({moderators.length})</span>} key="4">
|
2021-11-13 08:28:29 +03:00
|
|
|
<UserTable data={moderators} />
|
|
|
|
</TabPane>
|
|
|
|
</Tabs>
|
2021-06-22 06:19:00 +03:00
|
|
|
);
|
|
|
|
}
|