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