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

Commit 70b7f52

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

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-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/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,56 @@
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 { MatrixClientPeg } from "../../MatrixClientPeg.ts";
12+
import SettingsStore from "../SettingsStore.ts";
13+
import MatrixClientBackedController from "./MatrixClientBackedController.ts";
14+
15+
/**
16+
* Settings controller for the fallback ICE server setting.
17+
* This setting may be forcibly disabled by well-known value ["io.element.voip"]["disable_fallback_ice"].
18+
* This controller will update the MatrixClient's knowledge when the setting is changed.
19+
*/
20+
export default class FallbackIceServerController extends MatrixClientBackedController {
21+
private disabled = false;
22+
23+
public constructor() {
24+
super();
25+
}
26+
27+
private checkWellKnown(wellKnown: IClientWellKnown): void {
28+
this.disabled = !!wellKnown["io.element.voip"]?.["disable_fallback_ice"];
29+
}
30+
31+
protected async initMatrixClient(newClient: MatrixClient, oldClient?: MatrixClient): Promise<void> {
32+
oldClient?.off(ClientEvent.ClientWellKnown, this.checkWellKnown);
33+
newClient.on(ClientEvent.ClientWellKnown, this.checkWellKnown);
34+
const wellKnown = newClient.getClientWellKnown();
35+
if (wellKnown) this.checkWellKnown(wellKnown);
36+
}
37+
38+
public getValueOverride(): any {
39+
if (this.disabled) {
40+
return false;
41+
}
42+
43+
return null; // no override
44+
}
45+
46+
public get settingDisabled(): boolean | string {
47+
return this.disabled;
48+
}
49+
50+
public onChange(_level: SettingLevel, _roomId: string | null, _newValue: any): void {
51+
const cli = MatrixClientPeg.get();
52+
if (cli) {
53+
cli.setFallbackICEServerAllowed(!SettingsStore.getValue("webRtcAllowPeerToPeer"));
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)