2021-01-28 12:08:57 +01:00
|
|
|
import React, { useState, useContext, useEffect } from 'react';
|
2021-01-31 04:25:44 +01:00
|
|
|
import { Button, Input, Tooltip } from 'antd';
|
|
|
|
import { CopyOutlined, RedoOutlined } from '@ant-design/icons';
|
|
|
|
|
2021-01-28 12:08:57 +01:00
|
|
|
import TextField, { TEXTFIELD_TYPE_NUMBER, TEXTFIELD_TYPE_PASSWORD } from './form-textfield';
|
|
|
|
|
|
|
|
import { ServerStatusContext } from '../../../utils/server-status-context';
|
|
|
|
import { TEXTFIELD_PROPS_FFMPEG, TEXTFIELD_PROPS_RTMP_PORT, TEXTFIELD_PROPS_STREAM_KEY, TEXTFIELD_PROPS_WEB_PORT, } from './constants';
|
|
|
|
|
|
|
|
import configStyles from '../../../styles/config-pages.module.scss';
|
2021-01-30 10:39:58 +01:00
|
|
|
import { UpdateArgs } from '../../../types/config-section';
|
2021-01-28 12:08:57 +01:00
|
|
|
|
|
|
|
export default function EditInstanceDetails() {
|
|
|
|
const [formDataValues, setFormDataValues] = useState(null);
|
|
|
|
const serverStatusData = useContext(ServerStatusContext);
|
|
|
|
const { serverConfig } = serverStatusData || {};
|
|
|
|
|
|
|
|
const { streamKey, ffmpegPath, rtmpServerPort, webServerPort } = serverConfig;
|
|
|
|
|
2021-01-31 04:25:44 +01:00
|
|
|
const [copyIsVisible, setCopyVisible] = useState(false);
|
|
|
|
|
|
|
|
const COPY_TOOLTIP_TIMEOUT = 3000;
|
|
|
|
|
2021-01-28 12:08:57 +01:00
|
|
|
useEffect(() => {
|
|
|
|
setFormDataValues({
|
|
|
|
streamKey, ffmpegPath, rtmpServerPort, webServerPort
|
|
|
|
});
|
|
|
|
}, [serverConfig]);
|
|
|
|
|
|
|
|
if (!formDataValues) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-01-30 10:39:58 +01:00
|
|
|
const handleFieldChange = ({ fieldName, value }: UpdateArgs) => {
|
2021-01-28 12:08:57 +01:00
|
|
|
setFormDataValues({
|
|
|
|
...formDataValues,
|
|
|
|
[fieldName]: value,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-01-31 04:25:44 +01:00
|
|
|
function generateStreamKey () {
|
|
|
|
let key = '';
|
|
|
|
for (let i = 0; i < 3; i+=1) {
|
|
|
|
key += Math.random().toString(36).substring(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleFieldChange({ fieldName: 'streamKey', value: key });
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyStreamKey () {
|
|
|
|
navigator.clipboard.writeText(formDataValues.streamKey)
|
|
|
|
.then(() => {
|
|
|
|
setCopyVisible(true);
|
|
|
|
setTimeout(() => setCopyVisible(false), COPY_TOOLTIP_TIMEOUT);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-01-28 12:08:57 +01:00
|
|
|
return (
|
|
|
|
<div className={configStyles.publicDetailsContainer}>
|
|
|
|
<div className={configStyles.textFieldsSection}>
|
|
|
|
<TextField
|
|
|
|
fieldName="streamKey"
|
|
|
|
{...TEXTFIELD_PROPS_STREAM_KEY}
|
|
|
|
value={formDataValues.streamKey}
|
|
|
|
initialValue={streamKey}
|
|
|
|
type={TEXTFIELD_TYPE_PASSWORD}
|
|
|
|
onChange={handleFieldChange}
|
|
|
|
/>
|
2021-01-31 04:25:44 +01:00
|
|
|
<div>
|
|
|
|
<span style={{fontSize: '0.75em', color: '#ff7777', marginRight: '0.5em'}}>
|
|
|
|
Save this key somewhere safe,
|
|
|
|
you will need it to stream or login to the admin dashboard!
|
|
|
|
</span>
|
|
|
|
<Tooltip className="copy-tooltip"
|
|
|
|
title="Copied!"
|
|
|
|
trigger=""
|
|
|
|
visible={copyIsVisible}>
|
|
|
|
<Button type="primary"
|
|
|
|
icon={<CopyOutlined />}
|
|
|
|
size="small"
|
|
|
|
onClick={copyStreamKey}
|
|
|
|
/>
|
|
|
|
</Tooltip>
|
|
|
|
<Button type="primary"
|
|
|
|
icon={<RedoOutlined />}
|
|
|
|
size="small"
|
|
|
|
onClick={generateStreamKey}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-01-28 12:08:57 +01:00
|
|
|
<TextField
|
|
|
|
fieldName="ffmpegPath"
|
|
|
|
{...TEXTFIELD_PROPS_FFMPEG}
|
|
|
|
value={formDataValues.ffmpegPath}
|
|
|
|
initialValue={ffmpegPath}
|
|
|
|
onChange={handleFieldChange}
|
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
fieldName="webServerPort"
|
|
|
|
{...TEXTFIELD_PROPS_WEB_PORT}
|
|
|
|
value={formDataValues.webServerPort}
|
|
|
|
initialValue={webServerPort}
|
|
|
|
type={TEXTFIELD_TYPE_NUMBER}
|
|
|
|
onChange={handleFieldChange}
|
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
fieldName="rtmpServerPort"
|
|
|
|
{...TEXTFIELD_PROPS_RTMP_PORT}
|
|
|
|
value={formDataValues.rtmpServerPort}
|
|
|
|
initialValue={rtmpServerPort}
|
|
|
|
type={TEXTFIELD_TYPE_NUMBER}
|
|
|
|
onChange={handleFieldChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|