From b9e07ade92364cdaccd92eb11698af8865bdf630 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Tue, 8 Nov 2022 13:45:54 +1100 Subject: [PATCH] Fix seeking (#3096) * Update apikey when generating/clearing * Fix seeking on systems with api key --- ui/v2.5/src/components/ScenePlayer/ScenePlayer.tsx | 4 +++- .../components/Settings/SettingsSecurityPanel.tsx | 13 ++++++++++--- ui/v2.5/src/components/Settings/context.tsx | 14 +++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ui/v2.5/src/components/ScenePlayer/ScenePlayer.tsx b/ui/v2.5/src/components/ScenePlayer/ScenePlayer.tsx index b1dc302cb..38abbd184 100644 --- a/ui/v2.5/src/components/ScenePlayer/ScenePlayer.tsx +++ b/ui/v2.5/src/components/ScenePlayer/ScenePlayer.tsx @@ -397,8 +397,10 @@ export const ScenePlayer: React.FC = ({ const sourceSelector = player.sourceSelector(); sourceSelector.setSources( scene.sceneStreams.map((stream) => { + const src = new URL(stream.url); const isDirect = - stream.url.endsWith("/stream") || stream.url.endsWith("/stream.m3u8"); + src.pathname.endsWith("/stream") || + src.pathname.endsWith("/stream.m3u8"); return { src: stream.url, diff --git a/ui/v2.5/src/components/Settings/SettingsSecurityPanel.tsx b/ui/v2.5/src/components/Settings/SettingsSecurityPanel.tsx index 0af6813a9..02d1fae1d 100644 --- a/ui/v2.5/src/components/Settings/SettingsSecurityPanel.tsx +++ b/ui/v2.5/src/components/Settings/SettingsSecurityPanel.tsx @@ -71,9 +71,14 @@ export const SettingsSecurityPanel: React.FC = () => { const intl = useIntl(); const Toast = useToast(); - const { general, apiKey, loading, error, saveGeneral } = React.useContext( - SettingStateContext - ); + const { + general, + apiKey, + loading, + error, + saveGeneral, + refetch, + } = React.useContext(SettingStateContext); const [generateAPIKey] = useGenerateAPIKey(); @@ -84,6 +89,7 @@ export const SettingsSecurityPanel: React.FC = () => { input: {}, }, }); + refetch(); } catch (e) { Toast.error(e); } @@ -98,6 +104,7 @@ export const SettingsSecurityPanel: React.FC = () => { }, }, }); + refetch(); } catch (e) { Toast.error(e); } diff --git a/ui/v2.5/src/components/Settings/context.tsx b/ui/v2.5/src/components/Settings/context.tsx index d0aeafefc..9df77a1ef 100644 --- a/ui/v2.5/src/components/Settings/context.tsx +++ b/ui/v2.5/src/components/Settings/context.tsx @@ -46,6 +46,8 @@ export interface ISettingsContextState { saveScraping: (input: Partial) => void; saveDLNA: (input: Partial) => void; saveUI: (input: Partial) => void; + + refetch: () => void; } export const SettingStateContext = React.createContext({ @@ -64,12 +66,13 @@ export const SettingStateContext = React.createContext({ saveScraping: () => {}, saveDLNA: () => {}, saveUI: () => {}, + refetch: () => {}, }); export const SettingsContext: React.FC = ({ children }) => { const Toast = useToast(); - const { data, error, loading } = useConfiguration(); + const { data, error, loading, refetch } = useConfiguration(); const initialRef = useRef(false); const [general, setGeneral] = useState({}); @@ -125,9 +128,14 @@ export const SettingsContext: React.FC = ({ children }) => { }, [saveError, Toast]); useEffect(() => { + if (!data?.configuration || error) return; + + // always set api key + setApiKey(data.configuration.general.apiKey); + // only initialise once - assume we have control over these settings and // they aren't modified elsewhere - if (!data?.configuration || error || initialRef.current) return; + if (initialRef.current) return; initialRef.current = true; setGeneral({ ...withoutTypename(data.configuration.general) }); @@ -136,7 +144,6 @@ export const SettingsContext: React.FC = ({ children }) => { setScraping({ ...withoutTypename(data.configuration.scraping) }); setDLNA({ ...withoutTypename(data.configuration.dlna) }); setUI(data.configuration.ui); - setApiKey(data.configuration.general.apiKey); }, [data, error]); const resetSuccess = useMemo( @@ -509,6 +516,7 @@ export const SettingsContext: React.FC = ({ children }) => { saveScraping, saveDLNA, saveUI, + refetch, }} > {maybeRenderLoadingIndicator()}