mirror of
https://github.com/owncast/owncast.git
synced 2024-11-28 19:19:06 +03:00
d1f3fffe2f
* refactor: move/rename BanUserButton file * refactor: move/rename Chart file * refactor: update generic component filenames to PascalCase * refactor: update config component filenames to PascalCase * refactor: update AdminLayout component filename to PascalCase * refactor: update/move VideoJS component * chore(eslint): disable bad react/require-default-props rule * refactor: normalize ActionButton component * refactor: normalize ActionButtonRow component * refactor: normalize FollowButton component * refactor: normalize NotifyButton component * refactor: normalize ChatActionMessage component * refactor: normalize ChatContainer component * refactor: normalize ChatJoinMessage component * refactor: normalize ChatModerationActionMenu component * refactor: normalize ChatModerationDetailsModal component * refactor: normalize ChatModeratorNotification component * refactor: normalize ChatSocialMessage component * refactor: normalize ChatSystemMessage component * refactor: normalize ChatTextField component * refactor: normalize ChatUserBadge component * refactor: normalize ChatUserMessage component * refactor: normalize ContentHeader component * refactor: normalize OwncastLogo component * refactor: normalize UserDropdown component * chore(eslint): modify react/function-component-definition rule * refactor: normalize CodecSelector component * refactor: update a bunch of functional components using eslint * refactor: update a bunch of functional components using eslint, pt2 * refactor: update a bunch of functional components using eslint, pt3 * refactor: replace all component->component default imports with named imports * refactor: replace all component-stories->component default imports with named imports * refactor: remove default exports from most components * chore(eslint): add eslint config files for the components and pages dirs * fix: use-before-define error in ChatContainer * Fix ChatContainer import * Only process .tsx files in Next builds Co-authored-by: Gabe Kangas <gabek@real-ity.com>
133 lines
4 KiB
TypeScript
133 lines
4 KiB
TypeScript
import React, { useContext, useState, useEffect, FC } from 'react';
|
|
import { Typography, Slider } from 'antd';
|
|
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';
|
|
import {
|
|
createInputStatus,
|
|
StatusState,
|
|
STATUS_ERROR,
|
|
STATUS_PROCESSING,
|
|
STATUS_SUCCESS,
|
|
} from '../../utils/input-statuses';
|
|
import { FormStatusIndicator } from './FormStatusIndicator';
|
|
|
|
const { Title } = Typography;
|
|
|
|
const SLIDER_MARKS = {
|
|
0: 'Lowest',
|
|
1: '',
|
|
2: '',
|
|
3: '',
|
|
4: 'Highest',
|
|
};
|
|
|
|
const SLIDER_COMMENTS = {
|
|
0: 'Lowest latency, lowest error tolerance (Not recommended, may not work for all content/configurations.)',
|
|
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',
|
|
};
|
|
|
|
export const VideoLatency: FC = () => {
|
|
const [submitStatus, setSubmitStatus] = useState<StatusState>(null);
|
|
const [selectedOption, setSelectedOption] = useState(null);
|
|
|
|
const serverStatusData = useContext(ServerStatusContext);
|
|
const { setMessage } = useContext(AlertMessageContext);
|
|
const { serverConfig, setFieldInConfigState } = serverStatusData || {};
|
|
const { videoSettings } = serverConfig || {};
|
|
|
|
let resetTimer = null;
|
|
|
|
if (!videoSettings) {
|
|
return null;
|
|
}
|
|
|
|
useEffect(() => {
|
|
setSelectedOption(videoSettings.latencyLevel);
|
|
}, [videoSettings]);
|
|
|
|
const resetStates = () => {
|
|
setSubmitStatus(null);
|
|
resetTimer = null;
|
|
clearTimeout(resetTimer);
|
|
};
|
|
|
|
// posts all the variants at once as an array obj
|
|
const postUpdateToAPI = async (postValue: any) => {
|
|
setSubmitStatus(createInputStatus(STATUS_PROCESSING));
|
|
|
|
await postConfigUpdateToAPI({
|
|
apiPath: API_VIDEO_SEGMENTS,
|
|
data: { value: postValue },
|
|
onSuccess: () => {
|
|
setFieldInConfigState({
|
|
fieldName: 'latencyLevel',
|
|
value: postValue,
|
|
path: 'videoSettings',
|
|
});
|
|
setSubmitStatus(createInputStatus(STATUS_SUCCESS, 'Latency buffer level updated.'));
|
|
|
|
resetTimer = setTimeout(resetStates, RESET_TIMEOUT);
|
|
if (serverStatusData.online) {
|
|
setMessage(
|
|
'Your latency buffer setting will take effect the next time you begin a live stream.',
|
|
);
|
|
}
|
|
},
|
|
onError: (message: string) => {
|
|
setSubmitStatus(createInputStatus(STATUS_ERROR, message));
|
|
|
|
resetTimer = setTimeout(resetStates, RESET_TIMEOUT);
|
|
},
|
|
});
|
|
};
|
|
|
|
const handleChange = value => {
|
|
postUpdateToAPI(value);
|
|
};
|
|
|
|
return (
|
|
<div className="config-video-latency-container">
|
|
<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
|
|
reduced error tolerance and stability the lower you go. The lowest setting is not
|
|
recommended.
|
|
</p>
|
|
<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.{' '}
|
|
<a
|
|
href="https://owncast.online/docs/encoding#latency-buffer?source=admin"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
Read to learn more.
|
|
</a>
|
|
</p>
|
|
|
|
<div className="segment-slider-container">
|
|
<Slider
|
|
tipFormatter={value => SLIDER_COMMENTS[value]}
|
|
onChange={handleChange}
|
|
min={0}
|
|
max={4}
|
|
marks={SLIDER_MARKS}
|
|
defaultValue={selectedOption}
|
|
value={selectedOption}
|
|
/>
|
|
<p className="selected-value-note">{SLIDER_COMMENTS[selectedOption]}</p>
|
|
<FormStatusIndicator status={submitStatus} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|