Cleanup
This commit is contained in:
@@ -1,14 +1,12 @@
|
|||||||
import React, { useState, useEffect, useContext } from 'react';
|
import React, { useState, useEffect, useContext } from 'react';
|
||||||
import { Table, Row, Col, Typography } from 'antd';
|
import { Row, Col, Typography } from 'antd';
|
||||||
import { formatDistanceToNow } from 'date-fns';
|
|
||||||
import { UserOutlined } from '@ant-design/icons';
|
import { UserOutlined } from '@ant-design/icons';
|
||||||
import { SortOrder } from 'antd/lib/table/interface';
|
|
||||||
import Chart from '../components/chart';
|
import Chart from '../components/chart';
|
||||||
import StatisticItem from '../components/statistic';
|
import StatisticItem from '../components/statistic';
|
||||||
|
|
||||||
import { ServerStatusContext } from '../utils/server-status-context';
|
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
|
const FETCH_INTERVAL = 60 * 1000; // 1 min
|
||||||
|
|
||||||
@@ -17,7 +15,6 @@ export default function ViewersOverTime() {
|
|||||||
const { online, viewerCount, overallPeakViewerCount, sessionPeakViewerCount } = context || {};
|
const { online, viewerCount, overallPeakViewerCount, sessionPeakViewerCount } = context || {};
|
||||||
|
|
||||||
const [viewerInfo, setViewerInfo] = useState([]);
|
const [viewerInfo, setViewerInfo] = useState([]);
|
||||||
const [clients, setClients] = useState([]);
|
|
||||||
|
|
||||||
const getInfo = async () => {
|
const getInfo = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -26,13 +23,6 @@ export default function ViewersOverTime() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('==== error', error);
|
console.log('==== error', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await fetchData(CONNECTED_CLIENTS);
|
|
||||||
setClients(result);
|
|
||||||
} catch (error) {
|
|
||||||
console.log('==== error', error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -50,34 +40,10 @@ export default function ViewersOverTime() {
|
|||||||
return () => [];
|
return () => [];
|
||||||
}, [online]);
|
}, [online]);
|
||||||
|
|
||||||
// todo - check to see if broadcast active has changed. if so, start polling.
|
|
||||||
|
|
||||||
if (!viewerInfo.length) {
|
if (!viewerInfo.length) {
|
||||||
return 'no info';
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography.Title>Viewer Info</Typography.Title>
|
<Typography.Title>Viewer Info</Typography.Title>
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export const CREATE_WEBHOOK = `${API_LOCATION}webhooks/create`;
|
|||||||
export const SOCIAL_PLATFORMS_LIST = `${NEXT_PUBLIC_API_HOST}api/socialplatforms`;
|
export const SOCIAL_PLATFORMS_LIST = `${NEXT_PUBLIC_API_HOST}api/socialplatforms`;
|
||||||
|
|
||||||
// set external action links
|
// 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`;
|
export const API_YP_RESET = `${API_LOCATION}yp/reset`;
|
||||||
|
|
||||||
@@ -88,6 +88,7 @@ interface FetchOptions {
|
|||||||
export async function fetchData(url: string, options?: FetchOptions) {
|
export async function fetchData(url: string, options?: FetchOptions) {
|
||||||
const { data, method = 'GET', auth = true } = options || {};
|
const { data, method = 'GET', auth = true } = options || {};
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
const requestOptions: RequestInit = {
|
const requestOptions: RequestInit = {
|
||||||
method,
|
method,
|
||||||
};
|
};
|
||||||
@@ -119,7 +120,6 @@ export async function fetchData(url: string, options?: FetchOptions) {
|
|||||||
// console.log(error)
|
// console.log(error)
|
||||||
// throw new Error(error)
|
// throw new Error(error)
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchExternalData(url: string) {
|
export async function fetchExternalData(url: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user