diff --git a/src/apps/dashboard/routes/playback/trickplay.tsx b/src/apps/dashboard/routes/playback/trickplay.tsx index b09c2746a3..7f5336575f 100644 --- a/src/apps/dashboard/routes/playback/trickplay.tsx +++ b/src/apps/dashboard/routes/playback/trickplay.tsx @@ -11,6 +11,7 @@ import InputElement from '../../../../elements/InputElement'; import LinkTrickplayAcceleration from '../../../../components/dashboard/playback/trickplay/LinkTrickplayAcceleration'; import loading from '../../../../components/loading/loading'; import toast from '../../../../components/toast/toast'; +import ServerConnections from '../../../../components/ServerConnections'; function onSaveComplete() { loading.hide(); @@ -46,10 +47,10 @@ const PlaybackTrickplay: FunctionComponent = () => { const loadData = useCallback(() => { loading.show(); - window.ApiClient.getServerConfiguration().then(function (config) { + ServerConnections.currentApiClient()?.getServerConfiguration().then(function (config) { loadConfig(config); }).catch(err => { - console.error('[playbacktrickplay] failed to fetch server config', err); + console.error('[PlaybackTrickplay] failed to fetch server config', err); }); }, [loadConfig]); @@ -62,6 +63,13 @@ const PlaybackTrickplay: FunctionComponent = () => { } const saveConfig = (config: ServerConfiguration) => { + const apiClient = ServerConnections.currentApiClient(); + + if (!apiClient) { + console.error('[PlaybackTrickplay] No current apiclient instance'); + return; + } + if (!config.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.ProcessThreads = parseInt((page.querySelector('#txtProcessThreads') as HTMLInputElement).value || '1', 10); - window.ApiClient.updateServerConfiguration(config).then(() => { + apiClient.updateServerConfiguration(config).then(() => { onSaveComplete(); }).catch(err => { - console.error('[playbacktrickplay] failed to update config', err); + console.error('[PlaybackTrickplay] failed to update config', err); }); }; 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); }).catch(err => { - console.error('[playbacktrickplay] failed to fetch server config', err); + console.error('[PlaybackTrickplay] failed to fetch server config', err); }); e.preventDefault(); diff --git a/src/controllers/playback/video/index.js b/src/controllers/playback/video/index.js index 3cd98c77e9..deac178c73 100644 --- a/src/controllers/playback/video/index.js +++ b/src/controllers/playback/video/index.js @@ -151,15 +151,17 @@ export default function (view) { trickplayResolution = null; const mediaSourceId = currentPlayer.streamInfo.mediaSource.Id; - let trickplayResolutions; - if (item.Trickplay && (trickplayResolutions = item.Trickplay[mediaSourceId])) { + const trickplayResolutions = item.Trickplay?.[mediaSourceId]; + if (trickplayResolutions) { // Prefer highest resolution <= 20% of total screen resolution width let bestWidth; const maxWidth = window.screen.width * window.devicePixelRatio * 0.2; for (const [, info] of Object.entries(trickplayResolutions)) { if (!bestWidth || (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];