owncast/web/pages/video-config.tsx

117 lines
2.4 KiB
TypeScript
Raw Normal View History

2020-11-01 10:01:37 +03:00
/* eslint-disable react/prop-types */
2020-10-29 20:16:13 +03:00
import React, { useState, useEffect } from 'react';
import { Table, Typography } from 'antd';
2020-11-01 10:01:37 +03:00
import { SERVER_CONFIG, fetchData, FETCH_INTERVAL } from '../utils/apis';
2020-10-29 20:16:13 +03:00
const { Title } = Typography;
function VideoVariants({ config }) {
2020-11-01 10:01:37 +03:00
if (!config || !config.videoSettings) {
2020-10-29 20:16:13 +03:00
return null;
}
const videoQualityColumns = [
{
title: "Video bitrate",
dataIndex: "videoBitrate",
key: "videoBitrate",
render: (bitrate) =>
bitrate === 0 || !bitrate ? "Passthrough" : `${bitrate} kbps`,
},
{
title: "Framerate",
dataIndex: "framerate",
key: "framerate",
},
{
title: "Encoder preset",
dataIndex: "encoderPreset",
key: "framerate",
},
{
title: "Audio bitrate",
dataIndex: "audioBitrate",
key: "audioBitrate",
render: (bitrate) =>
bitrate === 0 || !bitrate ? "Passthrough" : `${bitrate} kbps`,
},
];
const miscVideoSettingsColumns = [
{
title: "Name",
dataIndex: "name",
key: "name",
},
{
title: "Value",
dataIndex: "value",
key: "value",
},
];
const miscVideoSettings = [
{
name: "Segment length",
value: config.videoSettings.segmentLengthSeconds,
},
{
name: "Number of segments",
value: config.videoSettings.numberOfPlaylistItems,
},
];
return (
<div>
<Title>Video configuration</Title>
<Table
pagination={false}
columns={videoQualityColumns}
dataSource={config.videoSettings.videoQualityVariants}
/>
<Table
pagination={false}
columns={miscVideoSettingsColumns}
dataSource={miscVideoSettings}
/>
</div>
);
}
export default function VideoConfig() {
2020-11-01 10:01:37 +03:00
const [config, setConfig] = useState({});
2020-10-29 20:16:13 +03:00
const getInfo = async () => {
try {
const result = await fetchData(SERVER_CONFIG);
console.log("viewers result", result)
setConfig({ ...result });
} catch (error) {
setConfig({ ...config, message: error.message });
}
};
useEffect(() => {
let getStatusIntervalId = null;
getInfo();
getStatusIntervalId = setInterval(getInfo, FETCH_INTERVAL);
// returned function will be called on component unmount
return () => {
clearInterval(getStatusIntervalId);
}
}, []);
return (
<div>
<VideoVariants config={config} />
</div>
);
}