Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 9884516

Browse files
committed
Disable ICE fallback based on well-known configuration
Signed-off-by: Michael Telatynski <[email protected]>
1 parent 3a24061 commit 9884516

7 files changed

+69
-6
lines changed

src/LegacyCallHandler.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,6 @@ export default class LegacyCallHandler extends EventEmitter {
764764
cancelButton: _t("action|ok"),
765765
onFinished: (allow) => {
766766
SettingsStore.setValue("fallbackICEServerAllowed", null, SettingLevel.DEVICE, allow);
767-
cli.setFallbackICEServerAllowed(!!allow);
768767
},
769768
},
770769
undefined,

src/Lifecycle.ts

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import {
7575
} from "./utils/tokens/tokens";
7676
import { TokenRefresher } from "./utils/oidc/TokenRefresher";
7777
import { checkBrowserSupport } from "./SupportedBrowser";
78+
import MatrixClientBackedController from "./settings/controllers/MatrixClientBackedController.ts";
7879

7980
const HOMESERVER_URL_KEY = "mx_hs_url";
8081
const ID_SERVER_URL_KEY = "mx_is_url";
@@ -1037,6 +1038,7 @@ async function startMatrixClient(
10371038

10381039
// Now that we have a MatrixClientPeg, update the Jitsi info
10391040
Jitsi.getInstance().start();
1041+
MatrixClientBackedController.start();
10401042

10411043
// dispatch that we finished starting up to wire up any other bits
10421044
// of the matrix client that cannot be set prior to starting up.

src/components/views/settings/tabs/user/VoiceUserSettingsTab.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ export default class VoiceUserSettingsTab extends React.Component<{}, IState> {
112112
this.context.setForceTURN(!p2p);
113113
};
114114

115-
private changeFallbackICEServerAllowed = (allow: boolean): void => {
116-
this.context.setFallbackICEServerAllowed(allow);
117-
};
118-
119115
private renderDeviceOptions(devices: Array<MediaDeviceInfo>, category: MediaDeviceKindEnum): Array<JSX.Element> {
120116
return devices.map((d) => {
121117
return (
@@ -226,7 +222,7 @@ export default class VoiceUserSettingsTab extends React.Component<{}, IState> {
226222
server: new URL(FALLBACK_ICE_SERVER).pathname,
227223
})}
228224
level={SettingLevel.DEVICE}
229-
onChange={this.changeFallbackICEServerAllowed}
225+
hideIfCannotSet
230226
/>
231227
</SettingsSubsection>
232228
</SettingsSection>

src/settings/Settings.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import ServerSupportUnstableFeatureController from "./controllers/ServerSupportU
3737
import { WatchManager } from "./WatchManager";
3838
import { CustomTheme } from "../theme";
3939
import AnalyticsController from "./controllers/AnalyticsController";
40+
import FallbackIceServerController from "./controllers/FallbackIceServerController";
4041

4142
export const defaultWatchManager = new WatchManager();
4243

@@ -992,6 +993,7 @@ export const SETTINGS: { [setting: string]: ISetting } = {
992993
description: _td("settings|voip|enable_fallback_ice_server_description"),
993994
// This is a tri-state value, where `null` means "prompt the user".
994995
default: null,
996+
controller: new FallbackIceServerController(),
995997
},
996998
"showImages": {
997999
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2024 New Vector Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
5+
Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
import { ClientEvent, IClientWellKnown, MatrixClient } from "matrix-js-sdk/src/matrix";
9+
10+
import { SettingLevel } from "../SettingLevel";
11+
import SettingsStore from "../SettingsStore.ts";
12+
import MatrixClientBackedController from "./MatrixClientBackedController.ts";
13+
14+
/**
15+
* Settings controller for the fallback ICE server setting.
16+
* This setting may be forcibly disabled by well-known value ["io.element.voip"]["disable_fallback_ice"].
17+
* This controller will update the MatrixClient's knowledge when the setting is changed.
18+
*/
19+
export default class FallbackIceServerController extends MatrixClientBackedController {
20+
private disabled = false;
21+
22+
public constructor() {
23+
super();
24+
}
25+
26+
private checkWellKnown(wellKnown: IClientWellKnown): void {
27+
this.disabled = !!wellKnown["io.element.voip"]?.["disable_fallback_ice"];
28+
}
29+
30+
protected async initMatrixClient(newClient: MatrixClient, oldClient?: MatrixClient): Promise<void> {
31+
oldClient?.off(ClientEvent.ClientWellKnown, this.checkWellKnown);
32+
newClient.on(ClientEvent.ClientWellKnown, this.checkWellKnown);
33+
}
34+
35+
protected async startMatrixClient(): Promise<void> {
36+
if (!this.client) return;
37+
this.checkWellKnown(await this.client.waitForClientWellKnown());
38+
}
39+
40+
public getValueOverride(): any {
41+
if (this.disabled) {
42+
return false;
43+
}
44+
45+
return null; // no override
46+
}
47+
48+
public get settingDisabled(): boolean | string {
49+
return this.disabled;
50+
}
51+
52+
public onChange(_level: SettingLevel, _roomId: string | null, _newValue: any): void {
53+
this.client?.setFallbackICEServerAllowed(!SettingsStore.getValue("fallbackICEServerAllowed"));
54+
}
55+
}

src/settings/controllers/MatrixClientBackedController.ts

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ export default abstract class MatrixClientBackedController extends SettingContro
3030
}
3131
}
3232

33+
public static start(): void {
34+
for (const instance of MatrixClientBackedController.instances) {
35+
instance.startMatrixClient();
36+
}
37+
}
38+
3339
protected constructor() {
3440
super();
3541

@@ -41,4 +47,5 @@ export default abstract class MatrixClientBackedController extends SettingContro
4147
}
4248

4349
protected abstract initMatrixClient(newClient: MatrixClient, oldClient?: MatrixClient): void;
50+
protected abstract startMatrixClient(): void;
4451
}

src/settings/controllers/ServerSupportUnstableFeatureController.ts

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export default class ServerSupportUnstableFeatureController extends MatrixClient
8181
this.disabled = !isEnabled;
8282
}
8383

84+
protected async startMatrixClient(): Promise<void> {}
85+
8486
public getValueOverride(
8587
level: SettingLevel,
8688
roomId: string | null,

0 commit comments

Comments
 (0)