mirror of
https://github.com/owncast/owncast.git
synced 2024-11-26 23:24:29 +03:00
b10ba1dcc2
* First pass at displaying user data in admin * Hide chat blurb on home page if chat is disabled * Hide sidebar chat section if chat is disabled * Block/unblock user interface for https://github.com/owncast/owncast/issues/1096 * Simplify past display name handling * Updates to reflect the api access token change * Update paths * Clean up the new access token page * Fix linter * Update linter workflow action * Cleanup * Fix exception rendering table row * Commit next-env file that seems to be required with next 11 * chat refactor - admin adjustments (#250) * add useragent parser; clean up some html; * some ui changes - use modal instead of popover to confirm block/unblock user - update styles, table styles for consistency - rename some user/chat labels in nav and content * format user info modal a bit * add some sort of mild treatment and delay while processing ban of users * rename button to 'ban' * add some notes * Prettified Code! * fix disableChat toggle for nav bar * Support sorting the disabled user list * Fix linter error around table sorting * No longer restoring messages on unban so change message prompt * Standardize on forbiddenUsername terminology * The linter broke the webhooks page. Fixed it. Linter is probably pissed. * Move chat welcome message to chat config * Other submenus don't have icons so remove these ones Co-authored-by: gingervitis <omqmail@gmail.com> Co-authored-by: gabek <gabek@users.noreply.github.com>
142 lines
3.2 KiB
TypeScript
142 lines
3.2 KiB
TypeScript
// TODO: add a notication after updating info that changes will take place either on a new stream or server restart. may be different for each field.
|
|
|
|
import React, { useState, useEffect } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { STATUS, fetchData, FETCH_INTERVAL, SERVER_CONFIG } from './apis';
|
|
import { ConfigDetails, UpdateArgs } from '../types/config-section';
|
|
import { DEFAULT_VARIANT_STATE } from './config-constants';
|
|
|
|
export const initialServerConfigState: ConfigDetails = {
|
|
streamKey: '',
|
|
instanceDetails: {
|
|
customStyles: '',
|
|
extraPageContent: '',
|
|
logo: '',
|
|
name: '',
|
|
nsfw: false,
|
|
socialHandles: [],
|
|
streamTitle: '',
|
|
summary: '',
|
|
tags: [],
|
|
title: '',
|
|
welcomeMessage: '',
|
|
},
|
|
ffmpegPath: '',
|
|
rtmpServerPort: '',
|
|
webServerPort: '',
|
|
s3: {
|
|
accessKey: '',
|
|
acl: '',
|
|
bucket: '',
|
|
enabled: false,
|
|
endpoint: '',
|
|
region: '',
|
|
secret: '',
|
|
servingEndpoint: '',
|
|
},
|
|
yp: {
|
|
enabled: false,
|
|
instanceUrl: '',
|
|
},
|
|
videoSettings: {
|
|
latencyLevel: 4,
|
|
cpuUsageLevel: 3,
|
|
videoQualityVariants: [DEFAULT_VARIANT_STATE],
|
|
},
|
|
externalActions: [],
|
|
supportedCodecs: [],
|
|
videoCodec: '',
|
|
forbiddenUsernames: [],
|
|
chatDisabled: false,
|
|
};
|
|
|
|
const initialServerStatusState = {
|
|
broadcastActive: false,
|
|
broadcaster: null,
|
|
currentBroadcast: null,
|
|
online: false,
|
|
viewerCount: 0,
|
|
sessionMaxViewerCount: 0,
|
|
sessionPeakViewerCount: 0,
|
|
overallPeakViewerCount: 0,
|
|
versionNumber: '0.0.0',
|
|
streamTitle: '',
|
|
chatDisabled: false,
|
|
};
|
|
|
|
export const ServerStatusContext = React.createContext({
|
|
...initialServerStatusState,
|
|
serverConfig: initialServerConfigState,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
setFieldInConfigState: (args: UpdateArgs) => null,
|
|
});
|
|
|
|
const ServerStatusProvider = ({ children }) => {
|
|
const [status, setStatus] = useState(initialServerStatusState);
|
|
const [config, setConfig] = useState(initialServerConfigState);
|
|
|
|
const getStatus = async () => {
|
|
try {
|
|
const result = await fetchData(STATUS);
|
|
setStatus({ ...result });
|
|
} catch (error) {
|
|
// todo
|
|
}
|
|
};
|
|
const getConfig = async () => {
|
|
try {
|
|
const result = await fetchData(SERVER_CONFIG);
|
|
setConfig(result);
|
|
} catch (error) {
|
|
// todo
|
|
}
|
|
};
|
|
|
|
const setFieldInConfigState = ({ fieldName, value, path }: UpdateArgs) => {
|
|
const updatedConfig = path
|
|
? {
|
|
...config,
|
|
[path]: {
|
|
...config[path],
|
|
[fieldName]: value,
|
|
},
|
|
}
|
|
: {
|
|
...config,
|
|
[fieldName]: value,
|
|
};
|
|
setConfig(updatedConfig);
|
|
};
|
|
|
|
useEffect(() => {
|
|
let getStatusIntervalId = null;
|
|
|
|
getStatus();
|
|
getStatusIntervalId = setInterval(getStatus, FETCH_INTERVAL);
|
|
|
|
getConfig();
|
|
|
|
// returned function will be called on component unmount
|
|
return () => {
|
|
clearInterval(getStatusIntervalId);
|
|
};
|
|
}, []);
|
|
|
|
const providerValue = {
|
|
...status,
|
|
serverConfig: config,
|
|
|
|
setFieldInConfigState,
|
|
};
|
|
return (
|
|
<ServerStatusContext.Provider value={providerValue}>{children}</ServerStatusContext.Provider>
|
|
);
|
|
};
|
|
|
|
ServerStatusProvider.propTypes = {
|
|
children: PropTypes.element.isRequired,
|
|
};
|
|
|
|
export default ServerStatusProvider;
|