This commit is contained in:
Gabe Kangas
2021-07-21 17:28:56 -07:00
parent a839d7250b
commit f8521d33d5
2 changed files with 4 additions and 38 deletions

View File

@ -1,14 +1,12 @@
import React, { useState, useEffect, useContext } from 'react';
import { Table, Row, Col, Typography } from 'antd';
import { formatDistanceToNow } from 'date-fns';
import { Row, Col, Typography } from 'antd';
import { UserOutlined } from '@ant-design/icons';
import { SortOrder } from 'antd/lib/table/interface';
import Chart from '../components/chart';
import StatisticItem from '../components/statistic';
import { ServerStatusContext } from '../utils/server-status-context';
import { CONNECTED_CLIENTS, VIEWERS_OVER_TIME, fetchData } from '../utils/apis';
import { VIEWERS_OVER_TIME, fetchData } from '../utils/apis';
const FETCH_INTERVAL = 60 * 1000; // 1 min
@ -17,7 +15,6 @@ export default function ViewersOverTime() {
const { online, viewerCount, overallPeakViewerCount, sessionPeakViewerCount } = context || {};
const [viewerInfo, setViewerInfo] = useState([]);
const [clients, setClients] = useState([]);
const getInfo = async () => {
try {
@ -26,13 +23,6 @@ export default function ViewersOverTime() {
} catch (error) {
console.log('==== error', error);
}
try {
const result = await fetchData(CONNECTED_CLIENTS);
setClients(result);
} catch (error) {
console.log('==== error', error);
}
};
useEffect(() => {
@ -50,34 +40,10 @@ export default function ViewersOverTime() {
return () => [];
}, [online]);
// todo - check to see if broadcast active has changed. if so, start polling.
if (!viewerInfo.length) {
return 'no info';
}
const columns = [
{
title: 'Connected Time',
dataIndex: 'connectedAt',
key: 'connectedAt',
render: time => formatDistanceToNow(new Date(time)),
sorter: (a, b) => new Date(a.connectedAt).getTime() - new Date(b.connectedAt).getTime(),
sortDirections: ['descend', 'ascend'] as SortOrder[],
},
{
title: 'User Agent',
dataIndex: 'userAgent',
key: 'userAgent',
},
{
title: 'Location',
dataIndex: 'geo',
key: 'geo',
render: geo => (geo ? `${geo.regionName}, ${geo.countryCode}` : '-'),
},
];
return (
<>
<Typography.Title>Viewer Info</Typography.Title>

View File

@ -71,7 +71,7 @@ export const CREATE_WEBHOOK = `${API_LOCATION}webhooks/create`;
export const SOCIAL_PLATFORMS_LIST = `${NEXT_PUBLIC_API_HOST}api/socialplatforms`;
// set external action links
export const EXTERNAL_ACTIONS = `${API_LOCATION}api/externalactions`
export const EXTERNAL_ACTIONS = `${API_LOCATION}api/externalactions`;
export const API_YP_RESET = `${API_LOCATION}yp/reset`;
@ -88,6 +88,7 @@ interface FetchOptions {
export async function fetchData(url: string, options?: FetchOptions) {
const { data, method = 'GET', auth = true } = options || {};
// eslint-disable-next-line no-undef
const requestOptions: RequestInit = {
method,
};
@ -119,7 +120,6 @@ export async function fetchData(url: string, options?: FetchOptions) {
// console.log(error)
// throw new Error(error)
}
return {};
}
export async function fetchExternalData(url: string) {