2021-01-17 00:40:46 -08:00
|
|
|
// 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.
|
|
|
|
|
2020-11-05 18:30:14 -08:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2021-01-29 10:26:55 -08:00
|
|
|
import PropTypes from 'prop-types';
|
2020-11-05 18:30:14 -08:00
|
|
|
|
2020-11-13 04:43:27 -08:00
|
|
|
import { STATUS, fetchData, FETCH_INTERVAL, SERVER_CONFIG } from './apis';
|
2021-04-12 00:07:08 -07:00
|
|
|
import { ConfigDetails, UpdateArgs } from '../types/config-section';
|
2021-02-06 22:38:58 -05:00
|
|
|
import { DEFAULT_VARIANT_STATE } from './config-constants';
|
2020-11-05 18:30:14 -08:00
|
|
|
|
2021-01-03 00:29:37 -08:00
|
|
|
export const initialServerConfigState: ConfigDetails = {
|
2020-11-13 04:43:27 -08:00
|
|
|
streamKey: '',
|
2020-12-30 18:07:15 -08:00
|
|
|
instanceDetails: {
|
2021-04-12 00:07:08 -07:00
|
|
|
customStyles: '',
|
2021-01-03 00:29:37 -08:00
|
|
|
extraPageContent: '',
|
|
|
|
logo: '',
|
|
|
|
name: '',
|
|
|
|
nsfw: false,
|
2021-01-19 10:34:06 -08:00
|
|
|
socialHandles: [],
|
2021-01-03 00:29:37 -08:00
|
|
|
streamTitle: '',
|
|
|
|
summary: '',
|
2020-12-30 18:07:15 -08:00
|
|
|
tags: [],
|
2021-01-03 00:29:37 -08:00
|
|
|
title: '',
|
2021-04-12 00:07:08 -07:00
|
|
|
welcomeMessage: '',
|
2022-08-16 21:44:37 -07:00
|
|
|
offlineMessage: '',
|
2020-12-30 18:07:15 -08:00
|
|
|
},
|
2021-01-03 00:29:37 -08:00
|
|
|
ffmpegPath: '',
|
|
|
|
rtmpServerPort: '',
|
|
|
|
webServerPort: '',
|
2022-03-06 17:12:37 -08:00
|
|
|
socketHostOverride: null,
|
2021-01-31 23:40:39 -08:00
|
|
|
s3: {
|
|
|
|
accessKey: '',
|
|
|
|
acl: '',
|
|
|
|
bucket: '',
|
|
|
|
enabled: false,
|
|
|
|
endpoint: '',
|
|
|
|
region: '',
|
|
|
|
secret: '',
|
|
|
|
servingEndpoint: '',
|
2021-10-29 02:33:32 +02:00
|
|
|
forcePathStyle: false,
|
2021-01-31 23:40:39 -08:00
|
|
|
},
|
2020-11-13 04:43:27 -08:00
|
|
|
yp: {
|
|
|
|
enabled: false,
|
2021-01-03 00:29:37 -08:00
|
|
|
instanceUrl: '',
|
2020-11-13 04:43:27 -08:00
|
|
|
},
|
|
|
|
videoSettings: {
|
2021-01-18 12:11:48 -08:00
|
|
|
latencyLevel: 4,
|
2021-01-30 22:53:00 -08:00
|
|
|
cpuUsageLevel: 3,
|
2021-01-10 02:37:22 -08:00
|
|
|
videoQualityVariants: [DEFAULT_VARIANT_STATE],
|
2021-01-31 23:40:39 -08:00
|
|
|
},
|
2022-01-12 13:52:37 -08:00
|
|
|
federation: {
|
|
|
|
enabled: false,
|
|
|
|
isPrivate: false,
|
|
|
|
username: '',
|
|
|
|
goLiveMessage: '',
|
|
|
|
showEngagement: true,
|
|
|
|
blockedDomains: [],
|
|
|
|
},
|
2022-03-23 08:57:09 -07:00
|
|
|
notifications: {
|
|
|
|
browser: { enabled: false, goLiveMessage: '' },
|
|
|
|
discord: { enabled: false, webhook: '', goLiveMessage: '' },
|
|
|
|
twitter: {
|
|
|
|
enabled: false,
|
|
|
|
goLiveMessage: '',
|
|
|
|
apiKey: '',
|
|
|
|
apiSecret: '',
|
|
|
|
accessToken: '',
|
|
|
|
accessTokenSecret: '',
|
|
|
|
bearerToken: '',
|
|
|
|
},
|
|
|
|
},
|
2021-03-15 15:27:19 -07:00
|
|
|
externalActions: [],
|
2021-03-22 20:34:52 -07:00
|
|
|
supportedCodecs: [],
|
|
|
|
videoCodec: '',
|
2021-07-19 22:02:02 -07:00
|
|
|
forbiddenUsernames: [],
|
2022-01-12 19:17:14 +01:00
|
|
|
suggestedUsernames: [],
|
2021-07-19 22:02:02 -07:00
|
|
|
chatDisabled: false,
|
2022-03-05 22:36:38 -08:00
|
|
|
chatJoinMessagesEnabled: true,
|
2022-03-07 00:06:07 -08:00
|
|
|
chatEstablishedUserMode: false,
|
2022-06-26 00:46:55 -07:00
|
|
|
hideViewerCount: false,
|
2020-11-13 04:43:27 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
const initialServerStatusState = {
|
2020-11-05 18:30:14 -08:00
|
|
|
broadcastActive: false,
|
|
|
|
broadcaster: null,
|
2021-02-06 22:38:58 -05:00
|
|
|
currentBroadcast: null,
|
2020-11-05 18:30:14 -08:00
|
|
|
online: false,
|
|
|
|
viewerCount: 0,
|
2020-11-13 03:43:28 -08:00
|
|
|
sessionMaxViewerCount: 0,
|
2020-11-05 18:30:14 -08:00
|
|
|
sessionPeakViewerCount: 0,
|
|
|
|
overallPeakViewerCount: 0,
|
|
|
|
versionNumber: '0.0.0',
|
2021-02-01 22:20:59 -08:00
|
|
|
streamTitle: '',
|
2021-07-19 22:02:02 -07:00
|
|
|
chatDisabled: false,
|
2022-03-24 23:04:20 -07:00
|
|
|
health: {
|
|
|
|
healthy: true,
|
|
|
|
healthPercentage: 100,
|
|
|
|
message: '',
|
2022-03-27 16:28:14 -07:00
|
|
|
representation: 0,
|
2022-03-24 23:04:20 -07:00
|
|
|
},
|
2020-11-05 18:30:14 -08:00
|
|
|
};
|
|
|
|
|
2020-11-13 04:43:27 -08:00
|
|
|
export const ServerStatusContext = React.createContext({
|
|
|
|
...initialServerStatusState,
|
|
|
|
serverConfig: initialServerConfigState,
|
2020-12-26 18:04:23 -08:00
|
|
|
|
2021-02-06 22:38:58 -05:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
setFieldInConfigState: (args: UpdateArgs) => null,
|
2020-11-13 04:43:27 -08:00
|
|
|
});
|
2020-11-05 18:30:14 -08:00
|
|
|
|
|
|
|
const ServerStatusProvider = ({ children }) => {
|
2020-11-13 04:43:27 -08:00
|
|
|
const [status, setStatus] = useState(initialServerStatusState);
|
|
|
|
const [config, setConfig] = useState(initialServerConfigState);
|
2020-11-05 18:30:14 -08:00
|
|
|
|
|
|
|
const getStatus = async () => {
|
|
|
|
try {
|
|
|
|
const result = await fetchData(STATUS);
|
|
|
|
setStatus({ ...result });
|
|
|
|
} catch (error) {
|
2020-11-13 03:43:28 -08:00
|
|
|
// todo
|
2020-11-05 18:30:14 -08:00
|
|
|
}
|
|
|
|
};
|
2020-11-13 04:43:27 -08:00
|
|
|
const getConfig = async () => {
|
|
|
|
try {
|
|
|
|
const result = await fetchData(SERVER_CONFIG);
|
|
|
|
setConfig(result);
|
|
|
|
} catch (error) {
|
|
|
|
// todo
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-03 01:54:04 -08:00
|
|
|
const setFieldInConfigState = ({ fieldName, value, path }: UpdateArgs) => {
|
2021-01-31 23:40:39 -08:00
|
|
|
const updatedConfig = path
|
|
|
|
? {
|
|
|
|
...config,
|
|
|
|
[path]: {
|
|
|
|
...config[path],
|
|
|
|
[fieldName]: value,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
...config,
|
|
|
|
[fieldName]: value,
|
|
|
|
};
|
2020-12-26 18:04:23 -08:00
|
|
|
setConfig(updatedConfig);
|
2021-01-03 23:32:47 -08:00
|
|
|
};
|
2020-12-26 18:04:23 -08:00
|
|
|
|
2020-11-05 18:30:14 -08:00
|
|
|
useEffect(() => {
|
|
|
|
let getStatusIntervalId = null;
|
|
|
|
|
|
|
|
getStatus();
|
|
|
|
getStatusIntervalId = setInterval(getStatus, FETCH_INTERVAL);
|
2020-11-13 04:43:27 -08:00
|
|
|
|
|
|
|
getConfig();
|
|
|
|
|
2021-01-31 23:40:39 -08:00
|
|
|
// returned function will be called on component unmount
|
2020-11-05 18:30:14 -08:00
|
|
|
return () => {
|
|
|
|
clearInterval(getStatusIntervalId);
|
2021-01-31 23:40:39 -08:00
|
|
|
};
|
2021-01-03 23:32:47 -08:00
|
|
|
}, []);
|
2020-11-05 18:30:14 -08:00
|
|
|
|
2022-06-26 00:46:55 -07:00
|
|
|
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
2020-11-13 04:43:27 -08:00
|
|
|
const providerValue = {
|
2021-01-31 23:40:39 -08:00
|
|
|
...status,
|
|
|
|
serverConfig: config,
|
2020-12-26 18:04:23 -08:00
|
|
|
|
2021-01-31 23:40:39 -08:00
|
|
|
setFieldInConfigState,
|
2020-11-13 04:43:27 -08:00
|
|
|
};
|
2020-11-05 18:30:14 -08:00
|
|
|
return (
|
2021-01-31 23:40:39 -08:00
|
|
|
<ServerStatusContext.Provider value={providerValue}>{children}</ServerStatusContext.Provider>
|
2020-11-05 18:30:14 -08:00
|
|
|
);
|
2021-01-31 23:40:39 -08:00
|
|
|
};
|
2020-11-05 18:30:14 -08:00
|
|
|
|
|
|
|
ServerStatusProvider.propTypes = {
|
|
|
|
children: PropTypes.element.isRequired,
|
|
|
|
};
|
|
|
|
|
2021-01-31 23:40:39 -08:00
|
|
|
export default ServerStatusProvider;
|