mirror of
https://github.com/owncast/owncast.git
synced 2025-11-02 03:54:54 +08:00
Replace broadcaster API call with generic server status call. Add upgrade check bool
This commit is contained in:
55
web/utils/server-status-context.tsx
Normal file
55
web/utils/server-status-context.tsx
Normal file
@ -0,0 +1,55 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { STATUS, fetchData, FETCH_INTERVAL } from './apis';
|
||||
|
||||
const initialState = {
|
||||
broadcastActive: false,
|
||||
broadcaster: null,
|
||||
online: false,
|
||||
viewerCount: 0,
|
||||
sessionPeakViewerCount: 0,
|
||||
overallPeakViewerCount: 0,
|
||||
disableUpgradeChecks: true,
|
||||
versionNumber: '0.0.0',
|
||||
};
|
||||
|
||||
export const ServerStatusContext = React.createContext(initialState);
|
||||
|
||||
const ServerStatusProvider = ({ children }) => {
|
||||
const [status, setStatus] = useState(initialState);
|
||||
|
||||
const getStatus = async () => {
|
||||
try {
|
||||
const result = await fetchData(STATUS);
|
||||
setStatus({ ...result });
|
||||
|
||||
} catch (error) {
|
||||
// setBroadcasterStatus({ ...broadcasterStatus, message: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let getStatusIntervalId = null;
|
||||
|
||||
getStatus();
|
||||
getStatusIntervalId = setInterval(getStatus, FETCH_INTERVAL);
|
||||
|
||||
// returned function will be called on component unmount
|
||||
return () => {
|
||||
clearInterval(getStatusIntervalId);
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<ServerStatusContext.Provider value={status}>
|
||||
{children}
|
||||
</ServerStatusContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
ServerStatusProvider.propTypes = {
|
||||
children: PropTypes.element.isRequired,
|
||||
};
|
||||
|
||||
export default ServerStatusProvider;
|
||||
Reference in New Issue
Block a user