d1f3fffe2f
* refactor: move/rename BanUserButton file * refactor: move/rename Chart file * refactor: update generic component filenames to PascalCase * refactor: update config component filenames to PascalCase * refactor: update AdminLayout component filename to PascalCase * refactor: update/move VideoJS component * chore(eslint): disable bad react/require-default-props rule * refactor: normalize ActionButton component * refactor: normalize ActionButtonRow component * refactor: normalize FollowButton component * refactor: normalize NotifyButton component * refactor: normalize ChatActionMessage component * refactor: normalize ChatContainer component * refactor: normalize ChatJoinMessage component * refactor: normalize ChatModerationActionMenu component * refactor: normalize ChatModerationDetailsModal component * refactor: normalize ChatModeratorNotification component * refactor: normalize ChatSocialMessage component * refactor: normalize ChatSystemMessage component * refactor: normalize ChatTextField component * refactor: normalize ChatUserBadge component * refactor: normalize ChatUserMessage component * refactor: normalize ContentHeader component * refactor: normalize OwncastLogo component * refactor: normalize UserDropdown component * chore(eslint): modify react/function-component-definition rule * refactor: normalize CodecSelector component * refactor: update a bunch of functional components using eslint * refactor: update a bunch of functional components using eslint, pt2 * refactor: update a bunch of functional components using eslint, pt3 * refactor: replace all component->component default imports with named imports * refactor: replace all component-stories->component default imports with named imports * refactor: remove default exports from most components * chore(eslint): add eslint config files for the components and pages dirs * fix: use-before-define error in ChatContainer * Fix ChatContainer import * Only process .tsx files in Next builds Co-authored-by: Gabe Kangas <gabek@real-ity.com>
108 lines
3.0 KiB
TypeScript
108 lines
3.0 KiB
TypeScript
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 ? (
|
|
<>
|
|
<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>
|
|
);
|
|
|
|
return (
|
|
<Tabs defaultActiveKey="1">
|
|
<TabPane tab={<span>Connected {online ? `(${clients.length})` : '(offline)'}</span>} key="1">
|
|
{connectedUsers}
|
|
</TabPane>
|
|
<TabPane tab={<span>Banned Users ({disabledUsers.length})</span>} key="2">
|
|
<UserTable data={disabledUsers} />
|
|
</TabPane>
|
|
<TabPane tab={<span>IP Bans ({ipBans.length})</span>} key="3">
|
|
<BannedIPsTable data={ipBans} />
|
|
</TabPane>
|
|
<TabPane tab={<span>Moderators ({moderators.length})</span>} key="4">
|
|
<UserTable data={moderators} />
|
|
</TabPane>
|
|
</Tabs>
|
|
);
|
|
}
|