2021-02-07 06:38:58 +03:00
|
|
|
import React, { useState, useEffect, useContext } from 'react';
|
2021-02-15 09:20:25 +03:00
|
|
|
import { Skeleton, Card, Statistic, Row, Col } from 'antd';
|
2021-02-07 06:38:58 +03:00
|
|
|
import { UserOutlined, ClockCircleOutlined } from '@ant-design/icons';
|
|
|
|
import { formatDistanceToNow, formatRelative } from 'date-fns';
|
|
|
|
import { ServerStatusContext } from '../utils/server-status-context';
|
|
|
|
import LogTable from '../components/log-table';
|
2021-10-14 04:44:07 +03:00
|
|
|
import Offline from '../components/offline-notice';
|
2020-10-30 04:01:38 +03:00
|
|
|
|
2021-02-07 06:38:58 +03:00
|
|
|
import { LOGS_WARN, fetchData, FETCH_INTERVAL } from '../utils/apis';
|
|
|
|
import { formatIPAddress, isEmptyObject } from '../utils/format';
|
2021-04-04 07:25:21 +03:00
|
|
|
import NewsFeed from '../components/news-feed';
|
2020-10-26 04:57:23 +03:00
|
|
|
|
2020-11-29 06:26:52 +03:00
|
|
|
function streamDetailsFormatter(streamDetails) {
|
|
|
|
return (
|
|
|
|
<ul className="statistics-list">
|
2021-02-07 06:38:58 +03:00
|
|
|
<li>
|
|
|
|
{streamDetails.videoCodec || 'Unknown'} @ {streamDetails.videoBitrate || 'Unknown'} kbps
|
|
|
|
</li>
|
2020-12-03 04:51:00 +03:00
|
|
|
<li>{streamDetails.framerate || 'Unknown'} fps</li>
|
2021-02-07 06:38:58 +03:00
|
|
|
<li>
|
|
|
|
{streamDetails.width} x {streamDetails.height}
|
|
|
|
</li>
|
2020-11-29 06:26:52 +03:00
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-08 02:32:51 +03:00
|
|
|
export default function Home() {
|
2020-11-13 14:43:28 +03:00
|
|
|
const serverStatusData = useContext(ServerStatusContext);
|
2020-11-13 15:43:27 +03:00
|
|
|
const { broadcaster, serverConfig: configData } = serverStatusData || {};
|
2020-10-26 04:57:23 +03:00
|
|
|
const { remoteAddr, streamDetails } = broadcaster || {};
|
2020-12-03 04:51:00 +03:00
|
|
|
|
2021-02-07 06:38:58 +03:00
|
|
|
const encoder = streamDetails?.encoder || 'Unknown encoder';
|
2020-10-26 04:57:23 +03:00
|
|
|
|
2020-11-13 14:43:28 +03:00
|
|
|
const [logsData, setLogs] = useState([]);
|
2020-10-30 04:01:38 +03:00
|
|
|
const getLogs = async () => {
|
|
|
|
try {
|
|
|
|
const result = await fetchData(LOGS_WARN);
|
|
|
|
setLogs(result);
|
|
|
|
} catch (error) {
|
2021-02-07 06:38:58 +03:00
|
|
|
console.log('==== error', error);
|
2020-10-30 04:01:38 +03:00
|
|
|
}
|
|
|
|
};
|
2020-11-13 14:43:28 +03:00
|
|
|
const getMoreStats = () => {
|
|
|
|
getLogs();
|
2021-02-07 06:38:58 +03:00
|
|
|
};
|
2020-12-06 12:05:49 +03:00
|
|
|
|
2020-10-26 04:57:23 +03:00
|
|
|
useEffect(() => {
|
2020-12-06 12:05:49 +03:00
|
|
|
getMoreStats();
|
|
|
|
|
2020-11-13 14:43:28 +03:00
|
|
|
let intervalId = null;
|
|
|
|
intervalId = setInterval(getMoreStats, FETCH_INTERVAL);
|
2021-02-07 06:38:58 +03:00
|
|
|
|
2020-11-13 14:43:28 +03:00
|
|
|
return () => {
|
|
|
|
clearInterval(intervalId);
|
2021-02-07 06:38:58 +03:00
|
|
|
};
|
2020-10-26 04:57:23 +03:00
|
|
|
}, []);
|
|
|
|
|
2020-11-13 14:43:28 +03:00
|
|
|
if (isEmptyObject(configData) || isEmptyObject(serverStatusData)) {
|
2020-10-26 04:57:23 +03:00
|
|
|
return (
|
2020-11-13 14:43:28 +03:00
|
|
|
<>
|
2020-10-26 04:57:23 +03:00
|
|
|
<Skeleton active />
|
|
|
|
<Skeleton active />
|
|
|
|
<Skeleton active />
|
2020-11-13 14:43:28 +03:00
|
|
|
</>
|
2020-10-26 04:57:23 +03:00
|
|
|
);
|
|
|
|
}
|
2020-10-23 03:16:28 +03:00
|
|
|
|
2020-10-26 04:57:23 +03:00
|
|
|
if (!broadcaster) {
|
2021-02-17 22:40:22 +03:00
|
|
|
return <Offline logs={logsData} config={configData} />;
|
2020-10-26 04:57:23 +03:00
|
|
|
}
|
2021-01-20 04:26:28 +03:00
|
|
|
|
2020-11-13 14:43:28 +03:00
|
|
|
// map out settings
|
2021-02-15 09:20:25 +03:00
|
|
|
const videoQualitySettings = serverStatusData?.currentBroadcast?.outputSettings?.map(setting => {
|
|
|
|
const { audioPassthrough, videoPassthrough, audioBitrate, videoBitrate, framerate } = setting;
|
|
|
|
|
|
|
|
const audioSetting = audioPassthrough
|
|
|
|
? `${streamDetails.audioCodec || 'Unknown'}, ${streamDetails.audioBitrate} kbps`
|
|
|
|
: `${audioBitrate || 'Unknown'} kbps`;
|
|
|
|
|
|
|
|
const videoSetting = videoPassthrough
|
|
|
|
? `${streamDetails.videoBitrate || 'Unknown'} kbps, ${streamDetails.framerate} fps ${
|
|
|
|
streamDetails.width
|
|
|
|
} x ${streamDetails.height}`
|
|
|
|
: `${videoBitrate || 'Unknown'} kbps, ${framerate} fps`;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="stream-details-item-container">
|
|
|
|
<Statistic
|
|
|
|
className="stream-details-item"
|
|
|
|
title="Outbound Video Stream"
|
|
|
|
value={videoSetting}
|
|
|
|
/>
|
|
|
|
<Statistic
|
|
|
|
className="stream-details-item"
|
|
|
|
title="Outbound Audio Stream"
|
|
|
|
value={audioSetting}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
2020-10-26 04:57:23 +03:00
|
|
|
|
2020-11-29 06:26:52 +03:00
|
|
|
// inbound
|
2020-12-13 03:26:50 +03:00
|
|
|
const { viewerCount, sessionPeakViewerCount } = serverStatusData;
|
2020-11-29 06:26:52 +03:00
|
|
|
|
2021-02-07 06:38:58 +03:00
|
|
|
const streamAudioDetailString = `${streamDetails.audioCodec}, ${
|
|
|
|
streamDetails.audioBitrate || 'Unknown'
|
|
|
|
} kbps`;
|
2020-11-13 14:43:28 +03:00
|
|
|
|
|
|
|
const broadcastDate = new Date(broadcaster.time);
|
2020-10-26 04:57:23 +03:00
|
|
|
|
|
|
|
return (
|
2021-01-20 04:26:28 +03:00
|
|
|
<div className="home-container">
|
2020-11-13 14:43:28 +03:00
|
|
|
<div className="sections-container">
|
2021-02-15 09:20:25 +03:00
|
|
|
<div className="online-status-section">
|
|
|
|
<Card size="small" type="inner" className="online-details-card">
|
|
|
|
<Row gutter={[16, 16]} align="middle">
|
|
|
|
<Col span={8} sm={24} md={8}>
|
|
|
|
<Statistic
|
|
|
|
title={`Stream started ${formatRelative(broadcastDate, Date.now())}`}
|
|
|
|
value={formatDistanceToNow(broadcastDate)}
|
|
|
|
prefix={<ClockCircleOutlined />}
|
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
<Col span={8} sm={24} md={8}>
|
|
|
|
<Statistic title="Viewers" value={viewerCount} prefix={<UserOutlined />} />
|
|
|
|
</Col>
|
|
|
|
<Col span={8} sm={24} md={8}>
|
|
|
|
<Statistic
|
|
|
|
title="Peak viewer count"
|
|
|
|
value={sessionPeakViewerCount}
|
|
|
|
prefix={<UserOutlined />}
|
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2020-11-13 14:43:28 +03:00
|
|
|
</Card>
|
2021-01-20 04:26:28 +03:00
|
|
|
</div>
|
|
|
|
|
2021-02-15 09:20:25 +03:00
|
|
|
<Row gutter={[16, 16]} className="section stream-details-section">
|
2021-04-04 07:25:21 +03:00
|
|
|
<Col className="stream-details" span={12} sm={24} md={24} lg={12}>
|
|
|
|
<Card
|
|
|
|
size="small"
|
|
|
|
title="Outbound Stream Details"
|
|
|
|
type="inner"
|
|
|
|
className="outbound-details"
|
|
|
|
>
|
2021-02-15 09:20:25 +03:00
|
|
|
{videoQualitySettings}
|
|
|
|
</Card>
|
2020-10-29 04:59:17 +03:00
|
|
|
|
2021-02-15 09:20:25 +03:00
|
|
|
<Card size="small" title="Inbound Stream Details" type="inner">
|
|
|
|
<Statistic
|
|
|
|
className="stream-details-item"
|
2020-11-13 14:43:28 +03:00
|
|
|
title="Input"
|
2020-12-03 04:34:05 +03:00
|
|
|
value={`${encoder} ${formatIPAddress(remoteAddr)}`}
|
2020-11-13 14:43:28 +03:00
|
|
|
/>
|
2021-02-15 09:20:25 +03:00
|
|
|
<Statistic
|
|
|
|
className="stream-details-item"
|
2020-11-13 14:43:28 +03:00
|
|
|
title="Inbound Video Stream"
|
2020-11-29 06:26:52 +03:00
|
|
|
value={streamDetails}
|
|
|
|
formatter={streamDetailsFormatter}
|
2020-11-13 14:43:28 +03:00
|
|
|
/>
|
2021-02-15 09:20:25 +03:00
|
|
|
<Statistic
|
|
|
|
className="stream-details-item"
|
2020-11-13 14:43:28 +03:00
|
|
|
title="Inbound Audio Stream"
|
|
|
|
value={streamAudioDetailString}
|
|
|
|
/>
|
|
|
|
</Card>
|
2021-02-15 09:20:25 +03:00
|
|
|
</Col>
|
2021-04-04 07:25:21 +03:00
|
|
|
<Col span={12} xs={24} sm={24} md={24} lg={12}>
|
|
|
|
<NewsFeed />
|
|
|
|
</Col>
|
2021-02-15 09:20:25 +03:00
|
|
|
</Row>
|
2020-11-13 14:43:28 +03:00
|
|
|
</div>
|
2021-02-15 09:20:25 +03:00
|
|
|
<br />
|
2020-11-13 14:57:57 +03:00
|
|
|
<LogTable logs={logsData} pageSize={5} />
|
2020-10-26 04:57:23 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|