mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Additional code review
This commit is contained in:
parent
55d57eedcc
commit
5a9378012c
2 changed files with 26 additions and 10 deletions
|
@ -11,6 +11,7 @@ import InputElement from '../../../../elements/InputElement';
|
||||||
import LinkTrickplayAcceleration from '../../../../components/dashboard/playback/trickplay/LinkTrickplayAcceleration';
|
import LinkTrickplayAcceleration from '../../../../components/dashboard/playback/trickplay/LinkTrickplayAcceleration';
|
||||||
import loading from '../../../../components/loading/loading';
|
import loading from '../../../../components/loading/loading';
|
||||||
import toast from '../../../../components/toast/toast';
|
import toast from '../../../../components/toast/toast';
|
||||||
|
import ServerConnections from '../../../../components/ServerConnections';
|
||||||
|
|
||||||
function onSaveComplete() {
|
function onSaveComplete() {
|
||||||
loading.hide();
|
loading.hide();
|
||||||
|
@ -46,10 +47,10 @@ const PlaybackTrickplay: FunctionComponent = () => {
|
||||||
const loadData = useCallback(() => {
|
const loadData = useCallback(() => {
|
||||||
loading.show();
|
loading.show();
|
||||||
|
|
||||||
window.ApiClient.getServerConfiguration().then(function (config) {
|
ServerConnections.currentApiClient()?.getServerConfiguration().then(function (config) {
|
||||||
loadConfig(config);
|
loadConfig(config);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error('[playbacktrickplay] failed to fetch server config', err);
|
console.error('[PlaybackTrickplay] failed to fetch server config', err);
|
||||||
});
|
});
|
||||||
}, [loadConfig]);
|
}, [loadConfig]);
|
||||||
|
|
||||||
|
@ -62,6 +63,13 @@ const PlaybackTrickplay: FunctionComponent = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveConfig = (config: ServerConfiguration) => {
|
const saveConfig = (config: ServerConfiguration) => {
|
||||||
|
const apiClient = ServerConnections.currentApiClient();
|
||||||
|
|
||||||
|
if (!apiClient) {
|
||||||
|
console.error('[PlaybackTrickplay] No current apiclient instance');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!config.TrickplayOptions) {
|
if (!config.TrickplayOptions) {
|
||||||
throw new Error('Unexpected null TrickplayOptions');
|
throw new Error('Unexpected null TrickplayOptions');
|
||||||
}
|
}
|
||||||
|
@ -78,20 +86,26 @@ const PlaybackTrickplay: FunctionComponent = () => {
|
||||||
options.JpegQuality = Math.min(100, parseInt((page.querySelector('#txtJpegQuality') as HTMLInputElement).value || '90', 10));
|
options.JpegQuality = Math.min(100, parseInt((page.querySelector('#txtJpegQuality') as HTMLInputElement).value || '90', 10));
|
||||||
options.ProcessThreads = parseInt((page.querySelector('#txtProcessThreads') as HTMLInputElement).value || '1', 10);
|
options.ProcessThreads = parseInt((page.querySelector('#txtProcessThreads') as HTMLInputElement).value || '1', 10);
|
||||||
|
|
||||||
window.ApiClient.updateServerConfiguration(config).then(() => {
|
apiClient.updateServerConfiguration(config).then(() => {
|
||||||
onSaveComplete();
|
onSaveComplete();
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error('[playbacktrickplay] failed to update config', err);
|
console.error('[PlaybackTrickplay] failed to update config', err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = (e: Event) => {
|
const onSubmit = (e: Event) => {
|
||||||
loading.show();
|
const apiClient = ServerConnections.currentApiClient();
|
||||||
|
|
||||||
window.ApiClient.getServerConfiguration().then(function (config) {
|
if (!apiClient) {
|
||||||
|
console.error('[PlaybackTrickplay] No current apiclient instance');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.show();
|
||||||
|
apiClient.getServerConfiguration().then(function (config) {
|
||||||
saveConfig(config);
|
saveConfig(config);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error('[playbacktrickplay] failed to fetch server config', err);
|
console.error('[PlaybackTrickplay] failed to fetch server config', err);
|
||||||
});
|
});
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
|
@ -151,15 +151,17 @@ export default function (view) {
|
||||||
trickplayResolution = null;
|
trickplayResolution = null;
|
||||||
|
|
||||||
const mediaSourceId = currentPlayer.streamInfo.mediaSource.Id;
|
const mediaSourceId = currentPlayer.streamInfo.mediaSource.Id;
|
||||||
let trickplayResolutions;
|
const trickplayResolutions = item.Trickplay?.[mediaSourceId];
|
||||||
if (item.Trickplay && (trickplayResolutions = item.Trickplay[mediaSourceId])) {
|
if (trickplayResolutions) {
|
||||||
// Prefer highest resolution <= 20% of total screen resolution width
|
// Prefer highest resolution <= 20% of total screen resolution width
|
||||||
let bestWidth;
|
let bestWidth;
|
||||||
const maxWidth = window.screen.width * window.devicePixelRatio * 0.2;
|
const maxWidth = window.screen.width * window.devicePixelRatio * 0.2;
|
||||||
for (const [, info] of Object.entries(trickplayResolutions)) {
|
for (const [, info] of Object.entries(trickplayResolutions)) {
|
||||||
if (!bestWidth
|
if (!bestWidth
|
||||||
|| (info.Width < bestWidth && bestWidth > maxWidth) // Objects not guaranteed to be sorted in any order, first width might be > maxWidth.
|
|| (info.Width < bestWidth && bestWidth > maxWidth) // Objects not guaranteed to be sorted in any order, first width might be > maxWidth.
|
||||||
|| (info.Width > bestWidth && info.Width <= maxWidth)) bestWidth = info.Width;
|
|| (info.Width > bestWidth && info.Width <= maxWidth)) {
|
||||||
|
bestWidth = info.Width;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bestWidth) trickplayResolution = trickplayResolutions[bestWidth];
|
if (bestWidth) trickplayResolution = trickplayResolutions[bestWidth];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue