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

Commit

Permalink
Disable ICE fallback based on well-known configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
  • Loading branch information
t3chguy committed Oct 2, 2024
1 parent 3a24061 commit 067a652
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/LegacyCallHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,6 @@ export default class LegacyCallHandler extends EventEmitter {
cancelButton: _t("action|ok"),
onFinished: (allow) => {
SettingsStore.setValue("fallbackICEServerAllowed", null, SettingLevel.DEVICE, allow);
cli.setFallbackICEServerAllowed(!!allow);
},
},
undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ export default class VoiceUserSettingsTab extends React.Component<{}, IState> {
this.context.setForceTURN(!p2p);
};

private changeFallbackICEServerAllowed = (allow: boolean): void => {
this.context.setFallbackICEServerAllowed(allow);
};

private renderDeviceOptions(devices: Array<MediaDeviceInfo>, category: MediaDeviceKindEnum): Array<JSX.Element> {
return devices.map((d) => {
return (
Expand Down Expand Up @@ -226,7 +222,7 @@ export default class VoiceUserSettingsTab extends React.Component<{}, IState> {
server: new URL(FALLBACK_ICE_SERVER).pathname,
})}
level={SettingLevel.DEVICE}
onChange={this.changeFallbackICEServerAllowed}
hideIfCannotSet
/>
</SettingsSubsection>
</SettingsSection>
Expand Down
2 changes: 2 additions & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import ServerSupportUnstableFeatureController from "./controllers/ServerSupportU
import { WatchManager } from "./WatchManager";
import { CustomTheme } from "../theme";
import AnalyticsController from "./controllers/AnalyticsController";
import FallbackIceServerController from "./controllers/FallbackIceServerController";

export const defaultWatchManager = new WatchManager();

Expand Down Expand Up @@ -992,6 +993,7 @@ export const SETTINGS: { [setting: string]: ISetting } = {
description: _td("settings|voip|enable_fallback_ice_server_description"),
// This is a tri-state value, where `null` means "prompt the user".
default: null,
controller: new FallbackIceServerController(),
},
"showImages": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
Expand Down
52 changes: 52 additions & 0 deletions src/settings/controllers/FallbackIceServerController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2024 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
*/

import { ClientEvent, IClientWellKnown, MatrixClient } from "matrix-js-sdk/src/matrix";

import { SettingLevel } from "../SettingLevel";
import SettingsStore from "../SettingsStore.ts";
import MatrixClientBackedController from "./MatrixClientBackedController.ts";

/**
* Settings controller for the fallback ICE server setting.
* This setting may be forcibly disabled by well-known value ["io.element.voip"]["disable_fallback_ice"].
* This controller will update the MatrixClient's knowledge when the setting is changed.
*/
export default class FallbackIceServerController extends MatrixClientBackedController {
private disabled = false;

public constructor() {
super();
}

private checkWellKnown = (wellKnown: IClientWellKnown): void => {
this.disabled = !!wellKnown["io.element.voip"]?.["disable_fallback_ice"];
};

protected async initMatrixClient(newClient: MatrixClient, oldClient?: MatrixClient): Promise<void> {
oldClient?.off(ClientEvent.ClientWellKnown, this.checkWellKnown);
newClient.on(ClientEvent.ClientWellKnown, this.checkWellKnown);
const wellKnown = newClient.getClientWellKnown();
if (wellKnown) this.checkWellKnown(wellKnown);
}

public getValueOverride(): any {
if (this.disabled) {
return false;
}

return null; // no override
}

public get settingDisabled(): boolean | string {
return this.disabled;
}

public onChange(_level: SettingLevel, _roomId: string | null, _newValue: any): void {
this.client?.setFallbackICEServerAllowed(!!SettingsStore.getValue("fallbackICEServerAllowed"));
}
}

0 comments on commit 067a652

Please sign in to comment.