2021-06-22 05:19:00 +02:00
|
|
|
import React, { useState, useEffect, useContext } from 'react';
|
2021-07-20 07:02:02 +02:00
|
|
|
import { Typography } from 'antd';
|
2021-06-22 05:19:00 +02:00
|
|
|
import { ServerStatusContext } from '../../utils/server-status-context';
|
2021-07-20 07:02:02 +02:00
|
|
|
import { CONNECTED_CLIENTS, fetchData, DISABLED_USERS } from '../../utils/apis';
|
|
|
|
import UserTable from '../../components/user-table';
|
|
|
|
import ClientTable from '../../components/client-table';
|
2021-06-22 05:19:00 +02:00
|
|
|
|
2021-07-20 07:02:02 +02:00
|
|
|
const { Title } = Typography;
|
2021-06-22 05:19:00 +02:00
|
|
|
|
2021-07-20 07:02:02 +02:00
|
|
|
export const FETCH_INTERVAL = 10 * 1000; // 10 sec
|
2021-06-22 05:19:00 +02:00
|
|
|
|
|
|
|
export default function ChatUsers() {
|
|
|
|
const context = useContext(ServerStatusContext);
|
|
|
|
const { online } = context || {};
|
|
|
|
|
2021-07-20 07:02:02 +02:00
|
|
|
const [disabledUsers, setDisabledUsers] = useState([]);
|
2021-06-22 05:19:00 +02:00
|
|
|
const [clients, setClients] = useState([]);
|
|
|
|
|
|
|
|
const getInfo = async () => {
|
|
|
|
try {
|
2021-07-20 07:02:02 +02:00
|
|
|
const result = await fetchData(DISABLED_USERS);
|
|
|
|
setDisabledUsers(result);
|
2021-06-22 05:19:00 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.log('==== error', error);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const result = await fetchData(CONNECTED_CLIENTS);
|
|
|
|
setClients(result);
|
|
|
|
} catch (error) {
|
|
|
|
console.log('==== error', error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
let getStatusIntervalId = null;
|
|
|
|
|
|
|
|
getInfo();
|
|
|
|
|
2021-07-20 07:02:02 +02:00
|
|
|
getStatusIntervalId = setInterval(getInfo, FETCH_INTERVAL);
|
|
|
|
// returned function will be called on component unmount
|
|
|
|
return () => {
|
|
|
|
clearInterval(getStatusIntervalId);
|
|
|
|
};
|
2021-06-22 05:19:00 +02:00
|
|
|
}, [online]);
|
|
|
|
|
2021-07-20 07:02:02 +02: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-06-22 05:19:00 +02:00
|
|
|
return (
|
|
|
|
<>
|
2021-07-23 00:18:20 +02:00
|
|
|
<Title>Connected Chat Participants ({clients.length})</Title>
|
2021-07-20 07:02:02 +02:00
|
|
|
{connectedUsers}
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<Title>Banned Users</Title>
|
|
|
|
<UserTable data={disabledUsers} />
|
2021-06-22 05:19:00 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|