Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locales/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions src/settings/DeveloperSettingsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -92,9 +93,8 @@ export const DeveloperSettingsTab: FC<Props> = ({
alwaysShowIphoneEarpieceSetting,
);

const [customLivekitUrl, setCustomLivekitUrl] = useSetting(
customLivekitUrlSetting,
);
const [customLivekitUrl, setCustomLivekitUrl, customLivekitUrlUpdateReason] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test it here somehow, even just a basic attempt to auth? We can do nicer UX here and set the input to busy, let it run to test whether the URL works and that way the URL doesn't change unexpectedly. We can also show a nice error string :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this is worthit for a dev tool? I almost though i am doing too nice ux for a devtool

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if it was a days effort then maybe but this should a relatively trivial bit of code. I think even devs should have a nice experience :)

useSettingWithLastUpdateReason(customLivekitUrlSetting);
const [customLivekitUrlTextBuffer, setCustomLivekitUrlTextBuffer] =
useState(customLivekitUrl);
useEffect(() => {
Expand Down Expand Up @@ -220,7 +220,8 @@ export const DeveloperSettingsTab: FC<Props> = ({
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
}
Expand Down
20 changes: 19 additions & 1 deletion src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ export class Setting<T> {

this._value$ = new BehaviorSubject(initialValue);
this.value$ = this._value$;
this._lastUpdateReason$ = new BehaviorSubject<string | null>(null);
this.lastUpdateReason$ = this._lastUpdateReason$;
}

private readonly key: string;

private readonly _value$: BehaviorSubject<T>;
private readonly _lastUpdateReason$: BehaviorSubject<string | null>;
public readonly value$: Behavior<T>;
public readonly lastUpdateReason$: Behavior<string | null>;

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 => {
Expand All @@ -57,6 +62,19 @@ export function useSetting<T>(setting: Setting<T>): [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<T>(
setting: Setting<T>,
): [T, (value: T) => void, string | null] {
return [
useBehavior(setting.value$),
setting.setValue,
useBehavior(setting.lastUpdateReason$),
];
}

// null = undecided
export const optInAnalytics = new Setting<boolean | null>(
"opt-in-analytics",
Expand Down
25 changes: 20 additions & 5 deletions src/state/CallViewModel/localMember/LocalTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
Loading