Skip to content

Commit 4148a05

Browse files
committed
Reset overwrite url if it is invalid (does fail to reach sfu)
1 parent 3491a68 commit 4148a05

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

locales/en/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"save": "Save",
7373
"saving": "Saving..."
7474
},
75+
"custom_url_update_reason_invalid": "Auto reset, custom url was invalid!",
7576
"debug_tile_layout_label": "Debug tile layout",
7677
"device_id": "Device ID: {{id}}",
7778
"duplicate_tiles_label": "Number of additional tile copies per participant",

src/settings/DeveloperSettingsTab.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
matrixRTCMode as matrixRTCModeSetting,
4242
customLivekitUrl as customLivekitUrlSetting,
4343
MatrixRTCMode,
44+
useSettingWithLastUpdateReason,
4445
} from "./settings";
4546
import type { Room as LivekitRoom } from "livekit-client";
4647
import styles from "./DeveloperSettingsTab.module.css";
@@ -92,9 +93,8 @@ export const DeveloperSettingsTab: FC<Props> = ({
9293
alwaysShowIphoneEarpieceSetting,
9394
);
9495

95-
const [customLivekitUrl, setCustomLivekitUrl] = useSetting(
96-
customLivekitUrlSetting,
97-
);
96+
const [customLivekitUrl, setCustomLivekitUrl, customLivekitUrlUpdateReason] =
97+
useSettingWithLastUpdateReason(customLivekitUrlSetting);
9898
const [customLivekitUrlTextBuffer, setCustomLivekitUrlTextBuffer] =
9999
useState(customLivekitUrl);
100100
useEffect(() => {
@@ -220,7 +220,8 @@ export const DeveloperSettingsTab: FC<Props> = ({
220220
onSubmit={(e) => e.preventDefault()}
221221
helpLabel={
222222
customLivekitUrl === null
223-
? t("developer_mode.custom_livekit_url.from_config")
223+
? t("developer_mode.custom_livekit_url.from_config") +
224+
(customLivekitUrlUpdateReason ?? "")
224225
: t("developer_mode.custom_livekit_url.current_url") +
225226
customLivekitUrl
226227
}

src/settings/settings.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,20 @@ export class Setting<T> {
3434

3535
this._value$ = new BehaviorSubject(initialValue);
3636
this.value$ = this._value$;
37+
this._lastUpdateReason$ = new BehaviorSubject<string | null>(null);
38+
this.lastUpdateReason$ = this._lastUpdateReason$;
3739
}
3840

3941
private readonly key: string;
4042

4143
private readonly _value$: BehaviorSubject<T>;
44+
private readonly _lastUpdateReason$: BehaviorSubject<string | null>;
4245
public readonly value$: Behavior<T>;
46+
public readonly lastUpdateReason$: Behavior<string | null>;
4347

44-
public readonly setValue = (value: T): void => {
48+
public readonly setValue = (value: T, reason?: string): void => {
4549
this._value$.next(value);
50+
this._lastUpdateReason$.next(reason ?? null);
4651
localStorage.setItem(this.key, JSON.stringify(value));
4752
};
4853
public readonly getValue = (): T => {
@@ -57,6 +62,19 @@ export function useSetting<T>(setting: Setting<T>): [T, (value: T) => void] {
5762
return [useBehavior(setting.value$), setting.setValue];
5863
}
5964

65+
/**
66+
* React hook that returns a settings's current value and a setter.
67+
*/
68+
export function useSettingWithLastUpdateReason<T>(
69+
setting: Setting<T>,
70+
): [T, (value: T) => void, string | null] {
71+
return [
72+
useBehavior(setting.value$),
73+
setting.setValue,
74+
useBehavior(setting.lastUpdateReason$),
75+
];
76+
}
77+
6078
// null = undecided
6179
export const optInAnalytics = new Setting<boolean | null>(
6280
"opt-in-analytics",

src/state/CallViewModel/localMember/LocalTransport.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
} from "rxjs";
2424
import { logger as rootLogger } from "matrix-js-sdk/lib/logger";
2525
import { AutoDiscovery } from "matrix-js-sdk/lib/autodiscovery";
26+
import { t } from "i18next";
2627

2728
import { type Behavior } from "../../Behavior.ts";
2829
import { type Epoch, type ObservableScope } from "../../ObservableScope.ts";
@@ -178,11 +179,25 @@ async function makeTransport(
178179

179180
if (!transport) throw new MatrixRTCTransportMissingError(domain ?? ""); // this will call the jwt/sfu/get endpoint to pre create the livekit room.
180181

181-
await getSFUConfigWithOpenID(
182-
client,
183-
transport.livekit_service_url,
184-
transport.livekit_alias,
185-
);
182+
try {
183+
await getSFUConfigWithOpenID(
184+
client,
185+
transport.livekit_service_url,
186+
transport.livekit_alias,
187+
);
188+
} catch (e) {
189+
if (urlFromDevSettings !== undefined) {
190+
logger.error(
191+
"Failed to get SFU config with dev settings overwrite, Resetting dev settings",
192+
);
193+
customLivekitUrl.setValue(
194+
null,
195+
`\n${t("developer_mode.custom_url_update_reason_invalid")}`,
196+
);
197+
} else {
198+
throw e;
199+
}
200+
}
186201

187202
return transport;
188203
}

0 commit comments

Comments
 (0)