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.
|
|
|
|
|
2023-02-23 00:21:00 +07:00
|
|
|
import React, { useState, useEffect, FC, ReactElement } from 'react';
|
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
|
|
|
|
2023-05-20 21:15:25 -07:00
|
|
|
const initialServerConfigState: ConfigDetails = {
|
2022-11-28 20:22:26 -08:00
|
|
|
streamKeys: [],
|
2023-02-27 17:08:52 -08:00
|
|
|
streamKeyOverridden: false,
|
2022-11-28 20:22:26 -08:00
|
|
|
adminPassword: '',
|
2020-12-30 18:07:15 -08:00
|
|
|
instanceDetails: {
|
2021-04-12 00:07:08 -07:00
|
|
|
customStyles: '',
|
2023-01-18 22:38:24 -08:00
|
|
|
customJavascript: '',
|
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: '',
|
2022-11-12 20:26:55 -08:00
|
|
|
appearanceVariables: {},
|
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,
|
2023-05-30 14:05:24 -07:00
|
|
|
videoServingEndpoint: '',
|
2021-01-31 23:40:39 -08:00
|
|
|
s3: {
|
|
|
|
accessKey: '',
|
|
|
|
acl: '',
|
|
|
|
bucket: '',
|
|
|
|
enabled: false,
|
|
|
|
endpoint: '',
|
|
|
|
region: '',
|
|
|
|
secret: '',
|
2023-08-02 13:35:47 -07:00
|
|
|
pathPrefix: '',
|
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: '' },
|
|
|
|
},
|
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,
|
2024-04-09 22:25:41 -07:00
|
|
|
chatSpamProtectionEnabled: true,
|
|
|
|
chatSlurFilterEnabled: 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,
|
2023-05-30 11:09:51 -07:00
|
|
|
disableSearchIndexing: 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
|
|
|
},
|
2023-03-12 01:08:29 +05:30
|
|
|
error: {
|
|
|
|
type: null,
|
|
|
|
msg: null,
|
|
|
|
},
|
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
|
2023-05-20 21:15:25 -07:00
|
|
|
setFieldInConfigState: (_args: UpdateArgs) => null,
|
2020-11-13 04:43:27 -08:00
|
|
|
});
|
2020-11-05 18:30:14 -08:00
|
|
|
|
2023-02-23 00:21:00 +07:00
|
|
|
export type ServerStatusProviderProps = {
|
|
|
|
children: ReactElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
const ServerStatusProvider: FC<ServerStatusProviderProps> = ({ 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);
|
2023-03-12 01:08:29 +05:30
|
|
|
|
|
|
|
if (result instanceof Error) {
|
|
|
|
throw result;
|
|
|
|
}
|
|
|
|
|
|
|
|
setStatus({ ...result, error: { type: null, msg: null } });
|
2020-11-05 18:30:14 -08:00
|
|
|
} catch (error) {
|
2023-03-12 01:08:29 +05:30
|
|
|
setStatus(initialStatus => ({
|
|
|
|
...initialStatus,
|
|
|
|
error: {
|
|
|
|
type: 'OWNCAST_SERVICE_UNREACHABLE',
|
|
|
|
msg: 'Cannot connect to the Owncast service. Please check you are connected to the internet and the Owncast server is running.',
|
|
|
|
},
|
|
|
|
}));
|
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);
|
2023-03-12 01:08:29 +05:30
|
|
|
|
|
|
|
if (result instanceof Error) {
|
|
|
|
throw result;
|
|
|
|
}
|
|
|
|
|
2020-11-13 04:43:27 -08:00
|
|
|
setConfig(result);
|
|
|
|
} catch (error) {
|
2023-03-12 01:08:29 +05:30
|
|
|
console.error(error);
|
2020-11-13 04:43:27 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2021-01-31 23:40:39 -08:00
|
|
|
export default ServerStatusProvider;
|