diff --git a/locales/en/app.json b/locales/en/app.json index 9e8fbbd34..78e1390e1 100644 --- a/locales/en/app.json +++ b/locales/en/app.json @@ -72,6 +72,7 @@ "save": "Save", "saving": "Saving..." }, + "custom_url_update_reason_invalid": "Auto reset, custom url was invalid!", "debug_tile_layout_label": "Debug tile layout", "device_id": "Device ID: {{id}}", "duplicate_tiles_label": "Number of additional tile copies per participant", diff --git a/src/settings/DeveloperSettingsTab.tsx b/src/settings/DeveloperSettingsTab.tsx index 254aaf0f4..77775ad73 100644 --- a/src/settings/DeveloperSettingsTab.tsx +++ b/src/settings/DeveloperSettingsTab.tsx @@ -41,6 +41,7 @@ import { matrixRTCMode as matrixRTCModeSetting, customLivekitUrl as customLivekitUrlSetting, MatrixRTCMode, + useSettingWithLastUpdateReason, } from "./settings"; import type { Room as LivekitRoom } from "livekit-client"; import styles from "./DeveloperSettingsTab.module.css"; @@ -92,9 +93,8 @@ export const DeveloperSettingsTab: FC = ({ alwaysShowIphoneEarpieceSetting, ); - const [customLivekitUrl, setCustomLivekitUrl] = useSetting( - customLivekitUrlSetting, - ); + const [customLivekitUrl, setCustomLivekitUrl, customLivekitUrlUpdateReason] = + useSettingWithLastUpdateReason(customLivekitUrlSetting); const [customLivekitUrlTextBuffer, setCustomLivekitUrlTextBuffer] = useState(customLivekitUrl); useEffect(() => { @@ -220,7 +220,8 @@ export const DeveloperSettingsTab: FC = ({ onSubmit={(e) => e.preventDefault()} helpLabel={ customLivekitUrl === null - ? t("developer_mode.custom_livekit_url.from_config") + ? t("developer_mode.custom_livekit_url.from_config") + + (customLivekitUrlUpdateReason ?? "") : t("developer_mode.custom_livekit_url.current_url") + customLivekitUrl } diff --git a/src/settings/settings.ts b/src/settings/settings.ts index f85e1414b..85af45792 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -34,15 +34,20 @@ export class Setting { this._value$ = new BehaviorSubject(initialValue); this.value$ = this._value$; + this._lastUpdateReason$ = new BehaviorSubject(null); + this.lastUpdateReason$ = this._lastUpdateReason$; } private readonly key: string; private readonly _value$: BehaviorSubject; + private readonly _lastUpdateReason$: BehaviorSubject; public readonly value$: Behavior; + public readonly lastUpdateReason$: Behavior; - public readonly setValue = (value: T): void => { + public readonly setValue = (value: T, reason?: string): void => { this._value$.next(value); + this._lastUpdateReason$.next(reason ?? null); localStorage.setItem(this.key, JSON.stringify(value)); }; public readonly getValue = (): T => { @@ -57,6 +62,19 @@ export function useSetting(setting: Setting): [T, (value: T) => void] { return [useBehavior(setting.value$), setting.setValue]; } +/** + * React hook that returns a settings's current value and a setter. + */ +export function useSettingWithLastUpdateReason( + setting: Setting, +): [T, (value: T) => void, string | null] { + return [ + useBehavior(setting.value$), + setting.setValue, + useBehavior(setting.lastUpdateReason$), + ]; +} + // null = undecided export const optInAnalytics = new Setting( "opt-in-analytics", diff --git a/src/state/CallViewModel/localMember/LocalTransport.ts b/src/state/CallViewModel/localMember/LocalTransport.ts index 0a85bbc13..8926e97be 100644 --- a/src/state/CallViewModel/localMember/LocalTransport.ts +++ b/src/state/CallViewModel/localMember/LocalTransport.ts @@ -23,6 +23,7 @@ import { } from "rxjs"; import { logger as rootLogger } from "matrix-js-sdk/lib/logger"; import { AutoDiscovery } from "matrix-js-sdk/lib/autodiscovery"; +import { t } from "i18next"; import { type Behavior } from "../../Behavior.ts"; import { type Epoch, type ObservableScope } from "../../ObservableScope.ts"; @@ -178,11 +179,25 @@ async function makeTransport( if (!transport) throw new MatrixRTCTransportMissingError(domain ?? ""); // this will call the jwt/sfu/get endpoint to pre create the livekit room. - await getSFUConfigWithOpenID( - client, - transport.livekit_service_url, - transport.livekit_alias, - ); + try { + await getSFUConfigWithOpenID( + client, + transport.livekit_service_url, + transport.livekit_alias, + ); + } catch (e) { + if (urlFromDevSettings !== undefined) { + logger.error( + "Failed to get SFU config with dev settings overwrite, Resetting dev settings", + ); + customLivekitUrl.setValue( + null, + `\n${t("developer_mode.custom_url_update_reason_invalid")}`, + ); + } else { + throw e; + } + } return transport; }