2022-09-07 10:00:28 +03:00
|
|
|
import React, { useContext, useState, useEffect, FC } from 'react';
|
2021-01-31 12:38:20 +03:00
|
|
|
import { Typography, Slider } from 'antd';
|
2021-02-07 06:38:58 +03:00
|
|
|
import { ServerStatusContext } from '../../utils/server-status-context';
|
|
|
|
import { AlertMessageContext } from '../../utils/alert-message-context';
|
|
|
|
import {
|
|
|
|
API_VIDEO_SEGMENTS,
|
|
|
|
RESET_TIMEOUT,
|
|
|
|
postConfigUpdateToAPI,
|
|
|
|
} from '../../utils/config-constants';
|
2021-01-31 12:38:20 +03:00
|
|
|
import {
|
2021-02-04 19:04:00 +03:00
|
|
|
createInputStatus,
|
|
|
|
StatusState,
|
|
|
|
STATUS_ERROR,
|
|
|
|
STATUS_PROCESSING,
|
|
|
|
STATUS_SUCCESS,
|
2021-02-07 06:38:58 +03:00
|
|
|
} from '../../utils/input-statuses';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { FormStatusIndicator } from './FormStatusIndicator';
|
2021-01-17 11:40:46 +03:00
|
|
|
|
|
|
|
const { Title } = Typography;
|
|
|
|
|
|
|
|
const SLIDER_MARKS = {
|
2021-05-06 03:19:12 +03:00
|
|
|
0: 'Lowest',
|
2023-03-15 07:34:24 +03:00
|
|
|
1: ' ',
|
|
|
|
2: ' ',
|
|
|
|
3: ' ',
|
2021-05-06 03:19:12 +03:00
|
|
|
4: 'Highest',
|
2021-01-17 11:40:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const SLIDER_COMMENTS = {
|
2021-05-06 04:21:40 +03:00
|
|
|
0: 'Lowest latency, lowest error tolerance (Not recommended, may not work for all content/configurations.)',
|
2021-05-06 03:19:12 +03:00
|
|
|
1: 'Low latency, low error tolerance',
|
|
|
|
2: 'Medium latency, medium error tolerance (Default)',
|
|
|
|
3: 'High latency, high error tolerance',
|
|
|
|
4: 'Highest latency, highest error tolerance',
|
2021-01-17 11:40:46 +03:00
|
|
|
};
|
|
|
|
|
2023-01-10 07:57:29 +03:00
|
|
|
// eslint-disable-next-line import/prefer-default-export
|
2022-09-07 10:00:28 +03:00
|
|
|
export const VideoLatency: FC = () => {
|
2021-02-04 19:04:00 +03:00
|
|
|
const [submitStatus, setSubmitStatus] = useState<StatusState>(null);
|
2021-01-18 23:11:48 +03:00
|
|
|
const [selectedOption, setSelectedOption] = useState(null);
|
2021-01-17 11:40:46 +03:00
|
|
|
|
|
|
|
const serverStatusData = useContext(ServerStatusContext);
|
2021-02-04 23:41:35 +03:00
|
|
|
const { setMessage } = useContext(AlertMessageContext);
|
2021-01-17 11:40:46 +03:00
|
|
|
const { serverConfig, setFieldInConfigState } = serverStatusData || {};
|
|
|
|
const { videoSettings } = serverConfig || {};
|
|
|
|
|
|
|
|
let resetTimer = null;
|
|
|
|
|
|
|
|
if (!videoSettings) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-01-18 23:11:48 +03:00
|
|
|
useEffect(() => {
|
|
|
|
setSelectedOption(videoSettings.latencyLevel);
|
|
|
|
}, [videoSettings]);
|
2021-01-17 11:40:46 +03:00
|
|
|
|
|
|
|
const resetStates = () => {
|
|
|
|
setSubmitStatus(null);
|
|
|
|
resetTimer = null;
|
|
|
|
clearTimeout(resetTimer);
|
2021-01-31 12:38:20 +03:00
|
|
|
};
|
|
|
|
|
2021-01-17 11:40:46 +03:00
|
|
|
// posts all the variants at once as an array obj
|
|
|
|
const postUpdateToAPI = async (postValue: any) => {
|
2021-02-04 19:04:00 +03:00
|
|
|
setSubmitStatus(createInputStatus(STATUS_PROCESSING));
|
|
|
|
|
2021-01-17 11:40:46 +03:00
|
|
|
await postConfigUpdateToAPI({
|
|
|
|
apiPath: API_VIDEO_SEGMENTS,
|
|
|
|
data: { value: postValue },
|
|
|
|
onSuccess: () => {
|
|
|
|
setFieldInConfigState({
|
2021-01-31 12:38:20 +03:00
|
|
|
fieldName: 'latencyLevel',
|
|
|
|
value: postValue,
|
|
|
|
path: 'videoSettings',
|
2021-01-17 11:40:46 +03:00
|
|
|
});
|
2021-02-04 23:41:35 +03:00
|
|
|
setSubmitStatus(createInputStatus(STATUS_SUCCESS, 'Latency buffer level updated.'));
|
2021-01-17 11:40:46 +03:00
|
|
|
|
|
|
|
resetTimer = setTimeout(resetStates, RESET_TIMEOUT);
|
2021-02-04 23:41:35 +03:00
|
|
|
if (serverStatusData.online) {
|
2021-02-07 06:38:58 +03:00
|
|
|
setMessage(
|
|
|
|
'Your latency buffer setting will take effect the next time you begin a live stream.',
|
|
|
|
);
|
2021-02-04 23:41:35 +03:00
|
|
|
}
|
2021-01-17 11:40:46 +03:00
|
|
|
},
|
|
|
|
onError: (message: string) => {
|
2021-02-04 19:04:00 +03:00
|
|
|
setSubmitStatus(createInputStatus(STATUS_ERROR, message));
|
|
|
|
|
2021-01-17 11:40:46 +03:00
|
|
|
resetTimer = setTimeout(resetStates, RESET_TIMEOUT);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-01-18 23:11:48 +03:00
|
|
|
const handleChange = value => {
|
|
|
|
postUpdateToAPI(value);
|
2021-01-17 11:40:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2021-02-15 05:46:34 +03:00
|
|
|
<div className="config-video-latency-container">
|
2021-02-13 10:55:59 +03:00
|
|
|
<Title level={3} className="section-title">
|
|
|
|
Latency Buffer
|
|
|
|
</Title>
|
|
|
|
<p className="description">
|
|
|
|
While it's natural to want to keep your latency as low as possible, you may experience
|
2021-05-06 03:19:53 +03:00
|
|
|
reduced error tolerance and stability the lower you go. The lowest setting is not
|
|
|
|
recommended.
|
2021-01-17 11:40:46 +03:00
|
|
|
</p>
|
2021-02-13 10:55:59 +03:00
|
|
|
<p className="description">
|
|
|
|
For interactive live streams you may want to experiment with a lower latency, for
|
|
|
|
non-interactive broadcasts you may want to increase it.{' '}
|
2021-02-26 23:38:55 +03:00
|
|
|
<a
|
2021-03-04 11:53:50 +03:00
|
|
|
href="https://owncast.online/docs/encoding#latency-buffer?source=admin"
|
2021-02-26 23:38:55 +03:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
Read to learn more.
|
|
|
|
</a>
|
2021-02-13 10:55:59 +03:00
|
|
|
</p>
|
|
|
|
|
2021-02-04 19:04:00 +03:00
|
|
|
<div className="segment-slider-container">
|
2021-01-31 12:38:20 +03:00
|
|
|
<Slider
|
2021-02-15 11:08:52 +03:00
|
|
|
tipFormatter={value => SLIDER_COMMENTS[value]}
|
2021-01-18 23:11:48 +03:00
|
|
|
onChange={handleChange}
|
2021-05-06 03:19:12 +03:00
|
|
|
min={0}
|
|
|
|
max={4}
|
2021-01-17 11:40:46 +03:00
|
|
|
marks={SLIDER_MARKS}
|
2021-01-17 13:01:40 +03:00
|
|
|
defaultValue={selectedOption}
|
2021-01-17 11:40:46 +03:00
|
|
|
value={selectedOption}
|
|
|
|
/>
|
2021-02-15 06:04:38 +03:00
|
|
|
<p className="selected-value-note">{SLIDER_COMMENTS[selectedOption]}</p>
|
2021-02-13 10:55:59 +03:00
|
|
|
<FormStatusIndicator status={submitStatus} />
|
2021-01-17 11:40:46 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|