include server config fetch in serverstatus context hook so config data can be provided across multiple views
This commit is contained in:
@@ -18,47 +18,32 @@ import LogTable from "./components/log-table";
|
|||||||
import Offline from './offline-notice';
|
import Offline from './offline-notice';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
SERVER_CONFIG,
|
|
||||||
LOGS_WARN,
|
LOGS_WARN,
|
||||||
fetchData,
|
fetchData,
|
||||||
FETCH_INTERVAL,
|
FETCH_INTERVAL,
|
||||||
} from "../utils/apis";
|
} from "../utils/apis";
|
||||||
import { formatIPAddress, isEmptyObject } from "../utils/format";
|
import { formatIPAddress, isEmptyObject } from "../utils/format";
|
||||||
import { INITIAL_SERVER_CONFIG_STATE } from "./update-server-config";
|
|
||||||
|
|
||||||
const { Title } = Typography;
|
const { Title } = Typography;
|
||||||
|
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const serverStatusData = useContext(ServerStatusContext);
|
const serverStatusData = useContext(ServerStatusContext);
|
||||||
const { broadcaster } = serverStatusData || {};
|
const { broadcaster, serverConfig: configData } = serverStatusData || {};
|
||||||
const { remoteAddr, streamDetails } = broadcaster || {};
|
const { remoteAddr, streamDetails } = broadcaster || {};
|
||||||
|
|
||||||
// Pull in the server config so we can show config overview.
|
|
||||||
const [configData, setServerConfig] = useState(INITIAL_SERVER_CONFIG_STATE);
|
|
||||||
const getConfig = async () => {
|
|
||||||
try {
|
|
||||||
const result = await fetchData(SERVER_CONFIG);
|
|
||||||
setServerConfig(result);
|
|
||||||
console.log("CONFIG", result);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const [logsData, setLogs] = useState([]);
|
const [logsData, setLogs] = useState([]);
|
||||||
const getLogs = async () => {
|
const getLogs = async () => {
|
||||||
try {
|
try {
|
||||||
const result = await fetchData(LOGS_WARN);
|
const result = await fetchData(LOGS_WARN);
|
||||||
setLogs(result);
|
setLogs(result);
|
||||||
console.log("LOGS", result);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("==== error", error);
|
console.log("==== error", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const getMoreStats = () => {
|
const getMoreStats = () => {
|
||||||
getLogs();
|
getLogs();
|
||||||
getConfig();
|
// getConfig();
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let intervalId = null;
|
let intervalId = null;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable react/prop-types */
|
/* eslint-disable react/prop-types */
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useContext } from "react";
|
||||||
import { SERVER_CONFIG, fetchData, FETCH_INTERVAL } from "../utils/apis";
|
|
||||||
import KeyValueTable from "./components/key-value-table";
|
import KeyValueTable from "./components/key-value-table";
|
||||||
|
import { ServerStatusContext } from '../utils/server-status-context';
|
||||||
|
|
||||||
function Storage({ config }) {
|
function Storage({ config }) {
|
||||||
if (!config || !config.s3) {
|
if (!config || !config.s3) {
|
||||||
@@ -47,30 +47,8 @@ function Storage({ config }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ServerConfig() {
|
export default function ServerConfig() {
|
||||||
const [config, setConfig] = useState({});
|
const serverStatusData = useContext(ServerStatusContext);
|
||||||
|
const { serverConfig: config } = serverStatusData || {};
|
||||||
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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -1,30 +1,13 @@
|
|||||||
/* eslint-disable react/prop-types */
|
/* eslint-disable react/prop-types */
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { Table, Typography, Input } from 'antd';
|
import { Table, Typography, Input } from 'antd';
|
||||||
import { SERVER_CONFIG, fetchData, FETCH_INTERVAL } from '../utils/apis';
|
|
||||||
import { isEmptyObject } from '../utils/format';
|
import { isEmptyObject } from '../utils/format';
|
||||||
import KeyValueTable from "./components/key-value-table";
|
import KeyValueTable from "./components/key-value-table";
|
||||||
|
import { ServerStatusContext } from '../utils/server-status-context';
|
||||||
|
|
||||||
const { Title } = Typography;
|
const { Title } = Typography;
|
||||||
const { TextArea } = Input;
|
const { TextArea } = Input;
|
||||||
|
|
||||||
export const INITIAL_SERVER_CONFIG_STATE = {
|
|
||||||
streamKey: '',
|
|
||||||
yp: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
videoSettings: {
|
|
||||||
videoQualityVariants: [
|
|
||||||
{
|
|
||||||
audioPassthrough: false,
|
|
||||||
videoBitrate: 0,
|
|
||||||
audioBitrate: 0,
|
|
||||||
framerate: 0,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function SocialHandles({ config }) {
|
function SocialHandles({ config }) {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return null;
|
return null;
|
||||||
@@ -137,22 +120,8 @@ function PageContent({ config }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ServerConfig() {
|
export default function ServerConfig() {
|
||||||
const [config, setConfig] = useState(INITIAL_SERVER_CONFIG_STATE);
|
const serverStatusData = useContext(ServerStatusContext);
|
||||||
|
const { serverConfig: config } = serverStatusData || {};
|
||||||
const getInfo = async () => {
|
|
||||||
try {
|
|
||||||
const result = await fetchData(SERVER_CONFIG);
|
|
||||||
console.log("SERVER_CONFIG", result)
|
|
||||||
|
|
||||||
setConfig({ ...result });
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
setConfig({ ...config, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
useEffect(() => {
|
|
||||||
getInfo();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -5,6 +5,29 @@ import { getGithubRelease } from "../utils/apis";
|
|||||||
|
|
||||||
const { Title } = Typography;
|
const { Title } = Typography;
|
||||||
|
|
||||||
|
function AssetTable(assets) {
|
||||||
|
const data = Object.values(assets);
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
title: "Name",
|
||||||
|
dataIndex: "name",
|
||||||
|
key: "name",
|
||||||
|
render: (text, entry) =>
|
||||||
|
<a href={entry.browser_download_url}>{text}</a>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Size",
|
||||||
|
dataIndex: "size",
|
||||||
|
key: "size",
|
||||||
|
render: (text) => (`${(text/1024/1024).toFixed(2)} MB`),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return <Table dataSource={data} columns={columns} rowKey="id" size="large" pagination={false} />
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export default function Logs() {
|
export default function Logs() {
|
||||||
const [release, setRelease] = useState({
|
const [release, setRelease] = useState({
|
||||||
html_url: "",
|
html_url: "",
|
||||||
@@ -44,30 +67,3 @@ export default function Logs() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AssetTable(assets) {
|
|
||||||
const data = [];
|
|
||||||
|
|
||||||
for (const key in assets) {
|
|
||||||
data.push(assets[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const columns = [
|
|
||||||
{
|
|
||||||
title: "Name",
|
|
||||||
dataIndex: "name",
|
|
||||||
key: "name",
|
|
||||||
render: (text, entry) =>
|
|
||||||
<a href={entry.browser_download_url}>{text}</a>,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Size",
|
|
||||||
dataIndex: "size",
|
|
||||||
key: "size",
|
|
||||||
render: (text, entry) =>
|
|
||||||
`${(text/1024/1024).toFixed(2)} MB`
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return <Table dataSource={data} columns={columns} rowKey="id" size="large" pagination={false} />
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable react/prop-types */
|
/* eslint-disable react/prop-types */
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { Table, Typography } from 'antd';
|
import { Table, Typography } from 'antd';
|
||||||
import { SERVER_CONFIG, fetchData, FETCH_INTERVAL } from '../utils/apis';
|
import { ServerStatusContext } from '../utils/server-status-context';
|
||||||
|
|
||||||
const { Title } = Typography;
|
const { Title } = Typography;
|
||||||
|
|
||||||
@@ -81,31 +81,8 @@ function VideoVariants({ config }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function VideoConfig() {
|
export default function VideoConfig() {
|
||||||
const [config, setConfig] = useState({});
|
const serverStatusData = useContext(ServerStatusContext);
|
||||||
|
const { serverConfig: config } = serverStatusData || {};
|
||||||
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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -1,9 +1,26 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { STATUS, fetchData, FETCH_INTERVAL } from './apis';
|
import { STATUS, fetchData, FETCH_INTERVAL, SERVER_CONFIG } from './apis';
|
||||||
|
|
||||||
const initialState = {
|
export const initialServerConfigState = {
|
||||||
|
streamKey: '',
|
||||||
|
yp: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
videoSettings: {
|
||||||
|
videoQualityVariants: [
|
||||||
|
{
|
||||||
|
audioPassthrough: false,
|
||||||
|
videoBitrate: 0,
|
||||||
|
audioBitrate: 0,
|
||||||
|
framerate: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const initialServerStatusState = {
|
||||||
broadcastActive: false,
|
broadcastActive: false,
|
||||||
broadcaster: null,
|
broadcaster: null,
|
||||||
online: false,
|
online: false,
|
||||||
@@ -15,10 +32,14 @@ const initialState = {
|
|||||||
versionNumber: '0.0.0',
|
versionNumber: '0.0.0',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ServerStatusContext = React.createContext(initialState);
|
export const ServerStatusContext = React.createContext({
|
||||||
|
...initialServerStatusState,
|
||||||
|
serverConfig: initialServerConfigState,
|
||||||
|
});
|
||||||
|
|
||||||
const ServerStatusProvider = ({ children }) => {
|
const ServerStatusProvider = ({ children }) => {
|
||||||
const [status, setStatus] = useState(initialState);
|
const [status, setStatus] = useState(initialServerStatusState);
|
||||||
|
const [config, setConfig] = useState(initialServerConfigState);
|
||||||
|
|
||||||
const getStatus = async () => {
|
const getStatus = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -29,6 +50,15 @@ const ServerStatusProvider = ({ children }) => {
|
|||||||
// todo
|
// todo
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const getConfig = async () => {
|
||||||
|
try {
|
||||||
|
const result = await fetchData(SERVER_CONFIG);
|
||||||
|
setConfig(result);
|
||||||
|
} catch (error) {
|
||||||
|
// todo
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let getStatusIntervalId = null;
|
let getStatusIntervalId = null;
|
||||||
@@ -36,14 +66,20 @@ const ServerStatusProvider = ({ children }) => {
|
|||||||
getStatus();
|
getStatus();
|
||||||
getStatusIntervalId = setInterval(getStatus, FETCH_INTERVAL);
|
getStatusIntervalId = setInterval(getStatus, FETCH_INTERVAL);
|
||||||
|
|
||||||
|
getConfig();
|
||||||
|
|
||||||
// returned function will be called on component unmount
|
// returned function will be called on component unmount
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(getStatusIntervalId);
|
clearInterval(getStatusIntervalId);
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const providerValue = {
|
||||||
|
...status,
|
||||||
|
serverConfig: config,
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<ServerStatusContext.Provider value={status}>
|
<ServerStatusContext.Provider value={providerValue}>
|
||||||
{children}
|
{children}
|
||||||
</ServerStatusContext.Provider>
|
</ServerStatusContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user