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

Commit 067a652

Browse files
committed
Disable ICE fallback based on well-known configuration
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 3a24061 commit 067a652

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-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,52 @@
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+
const wellKnown = newClient.getClientWellKnown();
34+
if (wellKnown) this.checkWellKnown(wellKnown);
35+
}
36+
37+
public getValueOverride(): any {
38+
if (this.disabled) {
39+
return false;
40+
}
41+
42+
return null; // no override
43+
}
44+
45+
public get settingDisabled(): boolean | string {
46+
return this.disabled;
47+
}
48+
49+
public onChange(_level: SettingLevel, _roomId: string | null, _newValue: any): void {
50+
this.client?.setFallbackICEServerAllowed(!!SettingsStore.getValue("fallbackICEServerAllowed"));
51+
}
52+
}

0 commit comments

Comments
 (0)