0
owncast/web/pages/index.tsx

191 lines
5.9 KiB
TypeScript
Raw Normal View History

/* eslint-disable no-console */
2020-10-25 18:57:23 -07:00
/*
Will display an overview with the following datasources:
1. Current broadcaster.
2. Viewer count.
3. Video settings.
2020-09-30 18:47:18 -07:00
2020-10-25 18:57:23 -07:00
TODO: Link each overview value to the sub-page that focuses on it.
2020-11-28 17:59:09 -08:00
GW: to do:
- fix side nav on long pages
- Hardware + Viewer count views- top 3 boxes - restyle
- "Current stream" - rename to "latest" stream?
- Home - more box shadoe?
- "Viewers" section - not "current viewers"
- maybe not have "current stream" nav section
- put viewers table info on Home
- maybe make outbound/inbound smaller (since it's fixed info for current stream)
- reformat "Inbound Video Stream" section.
2020-10-25 18:57:23 -07:00
*/
import React, { useState, useEffect, useContext } from "react";
2020-11-13 03:57:57 -08:00
import { Skeleton, Typography, Card, Statistic } from "antd";
2020-10-25 18:57:23 -07:00
import { UserOutlined, ClockCircleOutlined } from "@ant-design/icons";
import { formatDistanceToNow, formatRelative } from "date-fns";
import { ServerStatusContext } from "../utils/server-status-context";
import StatisticItem from "./components/statistic"
2020-10-29 18:01:38 -07:00
import LogTable from "./components/log-table";
2020-11-07 15:32:51 -08:00
import Offline from './offline-notice';
2020-10-29 18:01:38 -07:00
2020-10-25 18:57:23 -07:00
import {
2020-10-29 18:01:38 -07:00
LOGS_WARN,
2020-10-25 18:57:23 -07:00
fetchData,
FETCH_INTERVAL,
2020-11-01 00:01:37 -07:00
} from "../utils/apis";
import { formatIPAddress, isEmptyObject } from "../utils/format";
2020-10-25 18:57:23 -07:00
2020-10-28 00:53:24 -07:00
const { Title } = Typography;
2020-10-25 18:57:23 -07:00
2020-11-07 23:00:02 -08:00
2020-11-07 15:32:51 -08:00
export default function Home() {
const serverStatusData = useContext(ServerStatusContext);
const { broadcaster, serverConfig: configData } = serverStatusData || {};
2020-10-25 18:57:23 -07:00
const { remoteAddr, streamDetails } = broadcaster || {};
const [logsData, setLogs] = useState([]);
2020-10-29 18:01:38 -07:00
const getLogs = async () => {
try {
const result = await fetchData(LOGS_WARN);
setLogs(result);
} catch (error) {
console.log("==== error", error);
}
};
const getMoreStats = () => {
getLogs();
// getConfig();
}
2020-10-25 18:57:23 -07:00
useEffect(() => {
let intervalId = null;
intervalId = setInterval(getMoreStats, FETCH_INTERVAL);
return () => {
clearInterval(intervalId);
}
2020-10-25 18:57:23 -07:00
}, []);
if (isEmptyObject(configData) || isEmptyObject(serverStatusData)) {
2020-10-25 18:57:23 -07:00
return (
<>
2020-10-25 18:57:23 -07:00
<Skeleton active />
<Skeleton active />
<Skeleton active />
</>
2020-10-25 18:57:23 -07:00
);
}
2020-10-22 17:16:28 -07:00
2020-10-25 18:57:23 -07:00
if (!broadcaster) {
return <Offline logs={logsData} />;
2020-10-25 18:57:23 -07:00
}
2020-10-28 18:59:17 -07:00
// map out settings
const videoQualitySettings = configData?.videoSettings?.videoQualityVariants?.map((setting, index) => {
const { audioPassthrough, videoPassthrough, audioBitrate, videoBitrate, framerate } = setting;
2020-10-25 18:57:23 -07:00
const audioSetting =
audioPassthrough || audioBitrate === 0
2020-11-17 22:48:03 -08:00
? `${streamDetails.audioCodec} ${streamDetails.audioBitrate} kpbs`
: `${audioBitrate} kbps`;
const videoSetting =
videoPassthrough || videoBitrate === 0
? `${streamDetails.videoBitrate} kbps ${streamDetails.framerate}fps ${streamDetails.width}x${streamDetails.height}`
: `${videoBitrate} kbps ${framerate}fps`;
2020-10-25 18:57:23 -07:00
let settingTitle = 'Outbound Stream Details';
settingTitle = (videoQualitySettings?.length > 1) ?
`${settingTitle} ${index + 1}` : settingTitle;
2020-10-25 18:57:23 -07:00
return (
2020-11-13 03:57:57 -08:00
<Card title={settingTitle} type="inner" key={settingTitle}>
<StatisticItem
2020-10-28 00:53:24 -07:00
title="Outbound Video Stream"
value={videoSetting}
2020-10-28 00:53:24 -07:00
prefix={null}
/>
<StatisticItem
2020-10-28 00:53:24 -07:00
title="Outbound Audio Stream"
value={audioSetting}
prefix={null}
/>
</Card>
2020-10-25 18:57:23 -07:00
);
});
const { viewerCount, sessionMaxViewerCount } = serverStatusData;
2020-11-17 22:48:03 -08:00
const streamVideoDetailString = `${streamDetails.videoCodec} ${streamDetails.videoBitrate} kbps ${streamDetails.framerate}fps ${streamDetails.width}x${streamDetails.height}`;
const streamAudioDetailString = `${streamDetails.audioCodec} ${streamDetails.audioBitrate} kbps`;
const broadcastDate = new Date(broadcaster.time);
2020-10-25 18:57:23 -07:00
return (
<div className="home-container">
<div className="sections-container">
<div className="section online-status-section">
<Card title="Stream is online" type="inner">
<Statistic
title={`Stream started ${formatRelative(
broadcastDate,
Date.now()
)}`}
value={formatDistanceToNow(broadcastDate)}
prefix={<ClockCircleOutlined />}
/>
<Statistic
title="Viewers"
value={viewerCount}
prefix={<UserOutlined />}
/>
<Statistic
title="Peak viewer count"
value={sessionMaxViewerCount}
prefix={<UserOutlined />}
/>
</Card>
</div>
2020-10-25 18:57:23 -07:00
<div className="section stream-details-section">
2020-10-25 18:57:23 -07:00
<div className="details outbound-details">
{videoQualitySettings}
</div>
2020-10-28 18:59:17 -07:00
<div className="details other-details">
<Card title="Inbound Stream Details" type="inner">
<StatisticItem
title="Input"
value={formatIPAddress(remoteAddr)}
prefix={null}
/>
<StatisticItem
title="Inbound Video Stream"
value={streamVideoDetailString}
prefix={null}
/>
<StatisticItem
title="Inbound Audio Stream"
value={streamAudioDetailString}
prefix={null}
/>
</Card>
<div className="server-detail">
<Card title="Server Config" type="inner">
<StatisticItem
title="Stream key"
value={configData.streamKey}
prefix={null}
/>
<StatisticItem
title="Directory registration enabled"
value={configData.yp.enabled.toString()}
prefix={null}
/>
</Card>
</div>
</div>
</div>
</div>
2020-10-29 18:01:38 -07:00
2020-11-13 03:57:57 -08:00
<LogTable logs={logsData} pageSize={5} />
2020-10-25 18:57:23 -07:00
</div>
);
}