2020-10-26 02:57:23 +01:00
|
|
|
/*
|
|
|
|
Will display an overview with the following datasources:
|
|
|
|
1. Current broadcaster.
|
|
|
|
2. Viewer count.
|
|
|
|
3. Video settings.
|
2020-10-01 03:47:18 +02:00
|
|
|
|
2020-10-26 02:57:23 +01:00
|
|
|
TODO: Link each overview value to the sub-page that focuses on it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React, { useState, useEffect, useContext } from "react";
|
2021-01-30 10:39:58 +01:00
|
|
|
import { Skeleton, Card, Statistic } from "antd";
|
2020-10-26 02:57:23 +01:00
|
|
|
import { UserOutlined, ClockCircleOutlined } from "@ant-design/icons";
|
|
|
|
import { formatDistanceToNow, formatRelative } from "date-fns";
|
2020-11-06 03:30:14 +01:00
|
|
|
import { ServerStatusContext } from "../utils/server-status-context";
|
2020-10-29 02:36:25 +01:00
|
|
|
import StatisticItem from "./components/statistic"
|
2020-10-30 02:01:38 +01:00
|
|
|
import LogTable from "./components/log-table";
|
2020-11-08 00:32:51 +01:00
|
|
|
import Offline from './offline-notice';
|
2021-01-28 21:46:19 +01:00
|
|
|
import TextField from './components/config/form-textfield';
|
2021-01-30 21:27:07 +01:00
|
|
|
import { TEXTFIELD_PROPS_STREAM_TITLE } from './components/config/constants';
|
2020-10-30 02:01:38 +01:00
|
|
|
|
2020-10-26 02:57:23 +01:00
|
|
|
import {
|
2020-10-30 02:01:38 +01:00
|
|
|
LOGS_WARN,
|
2020-10-26 02:57:23 +01:00
|
|
|
fetchData,
|
|
|
|
FETCH_INTERVAL,
|
2020-11-01 08:01:37 +01:00
|
|
|
} from "../utils/apis";
|
|
|
|
import { formatIPAddress, isEmptyObject } from "../utils/format";
|
2021-01-30 10:39:58 +01:00
|
|
|
import { UpdateArgs } from "../types/config-section";
|
2020-10-26 02:57:23 +01:00
|
|
|
|
2020-11-29 04:26:52 +01:00
|
|
|
function streamDetailsFormatter(streamDetails) {
|
|
|
|
return (
|
|
|
|
<ul className="statistics-list">
|
2020-12-03 02:51:00 +01:00
|
|
|
<li>{streamDetails.videoCodec || 'Unknown'} @ {streamDetails.videoBitrate || 'Unknown'} kbps</li>
|
|
|
|
<li>{streamDetails.framerate || 'Unknown'} fps</li>
|
2020-11-29 04:26:52 +01:00
|
|
|
<li>{streamDetails.width} x {streamDetails.height}</li>
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-08 00:32:51 +01:00
|
|
|
export default function Home() {
|
2020-11-13 12:43:28 +01:00
|
|
|
const serverStatusData = useContext(ServerStatusContext);
|
2020-11-13 13:43:27 +01:00
|
|
|
const { broadcaster, serverConfig: configData } = serverStatusData || {};
|
2020-10-26 02:57:23 +01:00
|
|
|
const { remoteAddr, streamDetails } = broadcaster || {};
|
2021-01-30 10:39:58 +01:00
|
|
|
const { instanceDetails } = configData;
|
2020-12-03 02:51:00 +01:00
|
|
|
|
2020-12-03 02:34:05 +01:00
|
|
|
const encoder = streamDetails?.encoder || "Unknown encoder";
|
2021-01-30 10:39:58 +01:00
|
|
|
const [streamTitle, setStreamTitle] = useState('');
|
2020-10-26 02:57:23 +01:00
|
|
|
|
2020-11-13 12:43:28 +01:00
|
|
|
const [logsData, setLogs] = useState([]);
|
2020-10-30 02:01:38 +01:00
|
|
|
const getLogs = async () => {
|
|
|
|
try {
|
|
|
|
const result = await fetchData(LOGS_WARN);
|
|
|
|
setLogs(result);
|
|
|
|
} catch (error) {
|
|
|
|
console.log("==== error", error);
|
|
|
|
}
|
|
|
|
};
|
2020-11-13 12:43:28 +01:00
|
|
|
const getMoreStats = () => {
|
|
|
|
getLogs();
|
|
|
|
}
|
2020-12-06 10:05:49 +01:00
|
|
|
|
2021-01-30 10:39:58 +01:00
|
|
|
useEffect(() => {
|
|
|
|
setStreamTitle(instanceDetails.streamTitle);
|
|
|
|
}, [instanceDetails]);
|
|
|
|
|
2020-10-26 02:57:23 +01:00
|
|
|
useEffect(() => {
|
2020-12-06 10:05:49 +01:00
|
|
|
getMoreStats();
|
|
|
|
|
2020-11-13 12:43:28 +01:00
|
|
|
let intervalId = null;
|
|
|
|
intervalId = setInterval(getMoreStats, FETCH_INTERVAL);
|
2021-01-28 21:46:19 +01:00
|
|
|
|
2020-11-13 12:43:28 +01:00
|
|
|
return () => {
|
|
|
|
clearInterval(intervalId);
|
|
|
|
}
|
2020-10-26 02:57:23 +01:00
|
|
|
}, []);
|
|
|
|
|
2020-11-13 12:43:28 +01:00
|
|
|
if (isEmptyObject(configData) || isEmptyObject(serverStatusData)) {
|
2020-10-26 02:57:23 +01:00
|
|
|
return (
|
2020-11-13 12:43:28 +01:00
|
|
|
<>
|
2020-10-26 02:57:23 +01:00
|
|
|
<Skeleton active />
|
|
|
|
<Skeleton active />
|
|
|
|
<Skeleton active />
|
2020-11-13 12:43:28 +01:00
|
|
|
</>
|
2020-10-26 02:57:23 +01:00
|
|
|
);
|
|
|
|
}
|
2020-10-23 02:16:28 +02:00
|
|
|
|
2021-01-30 10:39:58 +01:00
|
|
|
const handleStreamTitleChanged = ({ value }: UpdateArgs) => {
|
2021-01-28 21:46:19 +01:00
|
|
|
setStreamTitle(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-26 02:57:23 +01:00
|
|
|
if (!broadcaster) {
|
2020-11-13 12:43:28 +01:00
|
|
|
return <Offline logs={logsData} />;
|
2020-10-26 02:57:23 +01:00
|
|
|
}
|
2021-01-20 02:26:28 +01:00
|
|
|
|
2020-11-13 12:43:28 +01:00
|
|
|
// map out settings
|
2021-01-20 00:57:40 +01:00
|
|
|
const videoQualitySettings = serverStatusData?.currentBroadcast?.outputSettings?.map((setting, index) => {
|
2020-11-20 06:56:29 +01:00
|
|
|
const { audioPassthrough, videoPassthrough, audioBitrate, videoBitrate, framerate } = setting;
|
2020-12-03 02:51:00 +01:00
|
|
|
|
|
|
|
const audioSetting = audioPassthrough
|
2021-01-20 02:26:28 +01:00
|
|
|
? `${streamDetails.audioCodec || 'Unknown'}, ${streamDetails.audioBitrate} kbps`
|
|
|
|
: `${audioBitrate || 'Unknown'} kbps`;
|
2020-12-03 02:51:00 +01:00
|
|
|
|
|
|
|
const videoSetting = videoPassthrough
|
2021-01-20 02:26:28 +01:00
|
|
|
? `${streamDetails.videoBitrate || 'Unknown'} kbps, ${streamDetails.framerate} fps ${streamDetails.width} x ${streamDetails.height}`
|
|
|
|
: `${videoBitrate || 'Unknown'} kbps, ${framerate} fps`;
|
|
|
|
|
2020-11-13 12:43:28 +01:00
|
|
|
let settingTitle = 'Outbound Stream Details';
|
|
|
|
settingTitle = (videoQualitySettings?.length > 1) ?
|
|
|
|
`${settingTitle} ${index + 1}` : settingTitle;
|
2020-10-26 02:57:23 +01:00
|
|
|
return (
|
2020-12-06 10:05:49 +01:00
|
|
|
<Card title={settingTitle} type="inner" key={`${settingTitle}${index}`}>
|
2020-10-29 02:36:25 +01:00
|
|
|
<StatisticItem
|
2020-10-28 08:53:24 +01:00
|
|
|
title="Outbound Video Stream"
|
2020-11-20 06:56:29 +01:00
|
|
|
value={videoSetting}
|
2020-10-28 08:53:24 +01:00
|
|
|
prefix={null}
|
|
|
|
/>
|
2020-10-29 02:36:25 +01:00
|
|
|
<StatisticItem
|
2020-10-28 08:53:24 +01:00
|
|
|
title="Outbound Audio Stream"
|
|
|
|
value={audioSetting}
|
|
|
|
prefix={null}
|
|
|
|
/>
|
2020-11-13 12:43:28 +01:00
|
|
|
</Card>
|
2020-10-26 02:57:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-11-29 04:26:52 +01:00
|
|
|
// inbound
|
2020-12-13 01:26:50 +01:00
|
|
|
const { viewerCount, sessionPeakViewerCount } = serverStatusData;
|
2020-11-29 04:26:52 +01:00
|
|
|
|
2020-12-03 02:51:00 +01:00
|
|
|
const streamAudioDetailString = `${streamDetails.audioCodec}, ${streamDetails.audioBitrate || 'Unknown'} kbps`;
|
2020-11-13 12:43:28 +01:00
|
|
|
|
|
|
|
const broadcastDate = new Date(broadcaster.time);
|
2020-10-26 02:57:23 +01:00
|
|
|
|
|
|
|
return (
|
2021-01-20 02:26:28 +01:00
|
|
|
<div className="home-container">
|
2020-11-13 12:43:28 +01:00
|
|
|
<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"
|
2020-12-13 01:26:50 +01:00
|
|
|
value={sessionPeakViewerCount}
|
2020-11-13 12:43:28 +01:00
|
|
|
prefix={<UserOutlined />}
|
|
|
|
/>
|
|
|
|
</Card>
|
2021-01-20 02:26:28 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="section online-details-section">
|
|
|
|
<Card title="Stream description">
|
2021-01-28 21:46:19 +01:00
|
|
|
<TextField
|
|
|
|
fieldName="streamTitle"
|
|
|
|
{...TEXTFIELD_PROPS_STREAM_TITLE}
|
|
|
|
value={streamTitle}
|
2021-01-30 10:39:58 +01:00
|
|
|
initialValue={instanceDetails.streamTitle}
|
2021-01-28 21:46:19 +01:00
|
|
|
onChange={handleStreamTitleChanged}
|
|
|
|
/>
|
2021-01-20 02:26:28 +01:00
|
|
|
</Card>
|
|
|
|
</div>
|
2020-10-26 02:57:23 +01:00
|
|
|
|
2020-11-13 12:43:28 +01:00
|
|
|
<div className="section stream-details-section">
|
2020-10-26 02:57:23 +01:00
|
|
|
|
2020-11-13 12:43:28 +01:00
|
|
|
<div className="details outbound-details">
|
|
|
|
{videoQualitySettings}
|
|
|
|
</div>
|
2020-10-29 02:59:17 +01:00
|
|
|
|
2020-11-13 12:43:28 +01:00
|
|
|
<div className="details other-details">
|
|
|
|
<Card title="Inbound Stream Details" type="inner">
|
|
|
|
<StatisticItem
|
|
|
|
title="Input"
|
2020-12-03 02:34:05 +01:00
|
|
|
value={`${encoder} ${formatIPAddress(remoteAddr)}`}
|
2020-11-13 12:43:28 +01:00
|
|
|
prefix={null}
|
|
|
|
/>
|
|
|
|
<StatisticItem
|
|
|
|
title="Inbound Video Stream"
|
2020-11-29 04:26:52 +01:00
|
|
|
value={streamDetails}
|
|
|
|
formatter={streamDetailsFormatter}
|
2020-11-13 12:43:28 +01:00
|
|
|
prefix={null}
|
|
|
|
/>
|
|
|
|
<StatisticItem
|
|
|
|
title="Inbound Audio Stream"
|
|
|
|
value={streamAudioDetailString}
|
|
|
|
prefix={null}
|
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
<div className="server-detail">
|
|
|
|
<Card title="Server Config" type="inner">
|
|
|
|
<StatisticItem
|
|
|
|
title="Directory registration enabled"
|
|
|
|
value={configData.yp.enabled.toString()}
|
|
|
|
prefix={null}
|
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-12-04 07:55:04 +01:00
|
|
|
</div>
|
2020-11-13 12:43:28 +01:00
|
|
|
</div>
|
2020-11-13 12:57:57 +01:00
|
|
|
<LogTable logs={logsData} pageSize={5} />
|
2020-10-26 02:57:23 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|