2021-01-28 14:08:57 +03:00
|
|
|
import React, { useState, useContext, useEffect } from 'react';
|
2023-01-11 03:39:12 +03:00
|
|
|
import { Button, Collapse, Typography, Tooltip } from 'antd';
|
2023-01-16 09:31:36 +03:00
|
|
|
import dynamic from 'next/dynamic';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { TEXTFIELD_TYPE_NUMBER, TEXTFIELD_TYPE_PASSWORD, TEXTFIELD_TYPE_URL } from './TextField';
|
|
|
|
import { TextFieldWithSubmit } from './TextFieldWithSubmit';
|
2021-02-07 06:38:58 +03:00
|
|
|
import { ServerStatusContext } from '../../utils/server-status-context';
|
|
|
|
import { AlertMessageContext } from '../../utils/alert-message-context';
|
2021-01-31 12:38:20 +03:00
|
|
|
import {
|
|
|
|
TEXTFIELD_PROPS_FFMPEG,
|
|
|
|
TEXTFIELD_PROPS_RTMP_PORT,
|
2022-03-07 04:12:37 +03:00
|
|
|
TEXTFIELD_PROPS_SOCKET_HOST_OVERRIDE,
|
2022-11-29 07:22:26 +03:00
|
|
|
TEXTFIELD_PROPS_ADMIN_PASSWORD,
|
2021-01-31 12:38:20 +03:00
|
|
|
TEXTFIELD_PROPS_WEB_PORT,
|
2021-02-07 06:38:58 +03:00
|
|
|
} from '../../utils/config-constants';
|
|
|
|
import { UpdateArgs } from '../../types/config-section';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { ResetYP } from './ResetYP';
|
2021-02-13 10:55:59 +03:00
|
|
|
|
2023-01-10 03:09:13 +03:00
|
|
|
// Lazy loaded components
|
|
|
|
|
2023-01-16 09:31:36 +03:00
|
|
|
const CopyOutlined = dynamic(() => import('@ant-design/icons/CopyOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const RedoOutlined = dynamic(() => import('@ant-design/icons/RedoOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
2021-02-13 10:55:59 +03:00
|
|
|
const { Panel } = Collapse;
|
2021-01-28 14:08:57 +03:00
|
|
|
|
2023-01-10 07:57:29 +03:00
|
|
|
// eslint-disable-next-line react/function-component-definition
|
|
|
|
export default function EditInstanceDetails() {
|
2021-01-28 14:08:57 +03:00
|
|
|
const [formDataValues, setFormDataValues] = useState(null);
|
|
|
|
const serverStatusData = useContext(ServerStatusContext);
|
2021-02-04 10:24:12 +03:00
|
|
|
const { setMessage } = useContext(AlertMessageContext);
|
|
|
|
|
2021-01-28 14:08:57 +03:00
|
|
|
const { serverConfig } = serverStatusData || {};
|
|
|
|
|
2022-11-29 07:22:26 +03:00
|
|
|
const { adminPassword, ffmpegPath, rtmpServerPort, webServerPort, yp, socketHostOverride } =
|
2022-03-07 04:12:37 +03:00
|
|
|
serverConfig;
|
2021-01-28 14:08:57 +03:00
|
|
|
|
2021-01-31 12:38:20 +03:00
|
|
|
const [copyIsVisible, setCopyVisible] = useState(false);
|
2021-01-31 06:25:44 +03:00
|
|
|
|
|
|
|
const COPY_TOOLTIP_TIMEOUT = 3000;
|
|
|
|
|
2021-01-28 14:08:57 +03:00
|
|
|
useEffect(() => {
|
|
|
|
setFormDataValues({
|
2022-11-29 07:22:26 +03:00
|
|
|
adminPassword,
|
2021-01-31 12:38:20 +03:00
|
|
|
ffmpegPath,
|
|
|
|
rtmpServerPort,
|
|
|
|
webServerPort,
|
2022-03-07 04:12:37 +03:00
|
|
|
socketHostOverride,
|
2021-01-28 14:08:57 +03:00
|
|
|
});
|
|
|
|
}, [serverConfig]);
|
|
|
|
|
|
|
|
if (!formDataValues) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-01-30 12:39:58 +03:00
|
|
|
const handleFieldChange = ({ fieldName, value }: UpdateArgs) => {
|
2021-01-28 14:08:57 +03:00
|
|
|
setFormDataValues({
|
|
|
|
...formDataValues,
|
|
|
|
[fieldName]: value,
|
|
|
|
});
|
2021-01-31 12:38:20 +03:00
|
|
|
};
|
2021-01-28 14:08:57 +03:00
|
|
|
|
2021-02-04 10:24:12 +03:00
|
|
|
const showConfigurationRestartMessage = () => {
|
2021-02-04 19:04:00 +03:00
|
|
|
setMessage('Updating server settings requires a restart of your Owncast server.');
|
|
|
|
};
|
2021-02-04 10:24:12 +03:00
|
|
|
|
2021-02-04 23:41:35 +03:00
|
|
|
const showStreamKeyChangeMessage = () => {
|
2021-02-07 06:38:58 +03:00
|
|
|
setMessage(
|
|
|
|
'Changing your stream key will log you out of the admin and block you from streaming until you change the key in your broadcasting software.',
|
|
|
|
);
|
2021-02-04 23:41:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const showFfmpegChangeMessage = () => {
|
|
|
|
if (serverStatusData.online) {
|
|
|
|
setMessage('The updated ffmpeg path will be used when starting your next live stream.');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-31 12:38:20 +03:00
|
|
|
function generateStreamKey() {
|
2021-01-31 06:25:44 +03:00
|
|
|
let key = '';
|
2021-01-31 12:38:20 +03:00
|
|
|
for (let i = 0; i < 3; i += 1) {
|
2021-01-31 06:25:44 +03:00
|
|
|
key += Math.random().toString(36).substring(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleFieldChange({ fieldName: 'streamKey', value: key });
|
|
|
|
}
|
|
|
|
|
2021-01-31 12:38:20 +03:00
|
|
|
function copyStreamKey() {
|
|
|
|
navigator.clipboard.writeText(formDataValues.streamKey).then(() => {
|
|
|
|
setCopyVisible(true);
|
|
|
|
setTimeout(() => setCopyVisible(false), COPY_TOOLTIP_TIMEOUT);
|
|
|
|
});
|
2021-01-31 06:25:44 +03:00
|
|
|
}
|
|
|
|
|
2021-01-31 12:38:20 +03:00
|
|
|
return (
|
2021-02-15 11:08:52 +03:00
|
|
|
<div className="edit-server-details-container">
|
2021-02-01 11:36:27 +03:00
|
|
|
<div className="field-container field-streamkey-container">
|
|
|
|
<div className="left-side">
|
|
|
|
<TextFieldWithSubmit
|
2022-11-29 07:22:26 +03:00
|
|
|
fieldName="adminPassword"
|
|
|
|
{...TEXTFIELD_PROPS_ADMIN_PASSWORD}
|
|
|
|
value={formDataValues.adminPassword}
|
|
|
|
initialValue={adminPassword}
|
2021-02-01 11:36:27 +03:00
|
|
|
type={TEXTFIELD_TYPE_PASSWORD}
|
|
|
|
onChange={handleFieldChange}
|
2021-02-04 23:41:35 +03:00
|
|
|
onSubmit={showStreamKeyChangeMessage}
|
2021-02-01 11:36:27 +03:00
|
|
|
/>
|
|
|
|
<div className="streamkey-actions">
|
2021-02-02 01:12:26 +03:00
|
|
|
<Tooltip title="Generate a stream key">
|
|
|
|
<Button icon={<RedoOutlined />} size="small" onClick={generateStreamKey} />
|
|
|
|
</Tooltip>
|
|
|
|
|
|
|
|
<Tooltip
|
|
|
|
className="copy-tooltip"
|
|
|
|
title={copyIsVisible ? 'Copied!' : 'Copy to clipboard'}
|
|
|
|
>
|
2021-02-01 11:36:27 +03:00
|
|
|
<Button icon={<CopyOutlined />} size="small" onClick={copyStreamKey} />
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-01-28 14:08:57 +03:00
|
|
|
</div>
|
2021-02-01 10:40:39 +03:00
|
|
|
<TextFieldWithSubmit
|
|
|
|
fieldName="ffmpegPath"
|
|
|
|
{...TEXTFIELD_PROPS_FFMPEG}
|
|
|
|
value={formDataValues.ffmpegPath}
|
|
|
|
initialValue={ffmpegPath}
|
|
|
|
onChange={handleFieldChange}
|
2021-02-04 23:41:35 +03:00
|
|
|
onSubmit={showFfmpegChangeMessage}
|
2021-02-01 10:40:39 +03:00
|
|
|
/>
|
|
|
|
<TextFieldWithSubmit
|
|
|
|
fieldName="webServerPort"
|
|
|
|
{...TEXTFIELD_PROPS_WEB_PORT}
|
|
|
|
value={formDataValues.webServerPort}
|
|
|
|
initialValue={webServerPort}
|
|
|
|
type={TEXTFIELD_TYPE_NUMBER}
|
|
|
|
onChange={handleFieldChange}
|
2021-02-04 10:24:12 +03:00
|
|
|
onSubmit={showConfigurationRestartMessage}
|
2021-02-01 10:40:39 +03:00
|
|
|
/>
|
|
|
|
<TextFieldWithSubmit
|
|
|
|
fieldName="rtmpServerPort"
|
|
|
|
{...TEXTFIELD_PROPS_RTMP_PORT}
|
|
|
|
value={formDataValues.rtmpServerPort}
|
|
|
|
initialValue={rtmpServerPort}
|
|
|
|
type={TEXTFIELD_TYPE_NUMBER}
|
|
|
|
onChange={handleFieldChange}
|
2021-02-04 10:24:12 +03:00
|
|
|
onSubmit={showConfigurationRestartMessage}
|
2021-02-01 10:40:39 +03:00
|
|
|
/>
|
2022-03-07 04:12:37 +03:00
|
|
|
<Collapse className="advanced-settings">
|
|
|
|
<Panel header="Advanced Settings" key="1">
|
|
|
|
<Typography.Paragraph>
|
|
|
|
If you have a CDN in front of your entire Owncast instance, specify your origin server
|
|
|
|
here for the websocket to connect to. Most people will never need to set this.
|
|
|
|
</Typography.Paragraph>
|
|
|
|
<TextFieldWithSubmit
|
|
|
|
fieldName="socketHostOverride"
|
|
|
|
{...TEXTFIELD_PROPS_SOCKET_HOST_OVERRIDE}
|
|
|
|
value={formDataValues.socketHostOverride}
|
|
|
|
initialValue={socketHostOverride || ''}
|
|
|
|
type={TEXTFIELD_TYPE_URL}
|
|
|
|
onChange={handleFieldChange}
|
|
|
|
/>
|
|
|
|
{yp.enabled && <ResetYP />}
|
|
|
|
</Panel>
|
|
|
|
</Collapse>
|
2021-01-31 12:38:20 +03:00
|
|
|
</div>
|
|
|
|
);
|
2023-01-10 07:57:29 +03:00
|
|
|
}
|