Disable ICE fallback based on well-known configuration (#111)
* Refactor MatrixClientBackedController.ts Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Disable ICE fallback based on well-known configuration Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
8a263ac1b0
commit
9895a8fb4f
7 changed files with 119 additions and 15 deletions
|
@ -765,7 +765,6 @@ export default class LegacyCallHandler extends EventEmitter {
|
||||||
cancelButton: _t("action|ok"),
|
cancelButton: _t("action|ok"),
|
||||||
onFinished: (allow) => {
|
onFinished: (allow) => {
|
||||||
SettingsStore.setValue("fallbackICEServerAllowed", null, SettingLevel.DEVICE, allow);
|
SettingsStore.setValue("fallbackICEServerAllowed", null, SettingLevel.DEVICE, allow);
|
||||||
cli.setFallbackICEServerAllowed(!!allow);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
undefined,
|
undefined,
|
||||||
|
|
|
@ -112,10 +112,6 @@ export default class VoiceUserSettingsTab extends React.Component<{}, IState> {
|
||||||
this.context.setForceTURN(!p2p);
|
this.context.setForceTURN(!p2p);
|
||||||
};
|
};
|
||||||
|
|
||||||
private changeFallbackICEServerAllowed = (allow: boolean): void => {
|
|
||||||
this.context.setFallbackICEServerAllowed(allow);
|
|
||||||
};
|
|
||||||
|
|
||||||
private renderDeviceOptions(devices: Array<MediaDeviceInfo>, category: MediaDeviceKindEnum): Array<JSX.Element> {
|
private renderDeviceOptions(devices: Array<MediaDeviceInfo>, category: MediaDeviceKindEnum): Array<JSX.Element> {
|
||||||
return devices.map((d) => {
|
return devices.map((d) => {
|
||||||
return (
|
return (
|
||||||
|
@ -226,7 +222,7 @@ export default class VoiceUserSettingsTab extends React.Component<{}, IState> {
|
||||||
server: new URL(FALLBACK_ICE_SERVER).pathname,
|
server: new URL(FALLBACK_ICE_SERVER).pathname,
|
||||||
})}
|
})}
|
||||||
level={SettingLevel.DEVICE}
|
level={SettingLevel.DEVICE}
|
||||||
onChange={this.changeFallbackICEServerAllowed}
|
hideIfCannotSet
|
||||||
/>
|
/>
|
||||||
</SettingsSubsection>
|
</SettingsSubsection>
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
|
|
|
@ -37,6 +37,7 @@ import ServerSupportUnstableFeatureController from "./controllers/ServerSupportU
|
||||||
import { WatchManager } from "./WatchManager";
|
import { WatchManager } from "./WatchManager";
|
||||||
import { CustomTheme } from "../theme";
|
import { CustomTheme } from "../theme";
|
||||||
import AnalyticsController from "./controllers/AnalyticsController";
|
import AnalyticsController from "./controllers/AnalyticsController";
|
||||||
|
import FallbackIceServerController from "./controllers/FallbackIceServerController";
|
||||||
|
|
||||||
export const defaultWatchManager = new WatchManager();
|
export const defaultWatchManager = new WatchManager();
|
||||||
|
|
||||||
|
@ -980,6 +981,7 @@ export const SETTINGS: { [setting: string]: ISetting } = {
|
||||||
description: _td("settings|voip|enable_fallback_ice_server_description"),
|
description: _td("settings|voip|enable_fallback_ice_server_description"),
|
||||||
// This is a tri-state value, where `null` means "prompt the user".
|
// This is a tri-state value, where `null` means "prompt the user".
|
||||||
default: null,
|
default: null,
|
||||||
|
controller: new FallbackIceServerController(),
|
||||||
},
|
},
|
||||||
"showImages": {
|
"showImages": {
|
||||||
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
|
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
|
||||||
|
|
52
src/settings/controllers/FallbackIceServerController.ts
Normal file
52
src/settings/controllers/FallbackIceServerController.ts
Normal file
|
@ -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"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,7 +18,7 @@ import SettingController from "./SettingController";
|
||||||
* This class performs no logic and should be overridden.
|
* This class performs no logic and should be overridden.
|
||||||
*/
|
*/
|
||||||
export default abstract class MatrixClientBackedController extends SettingController {
|
export default abstract class MatrixClientBackedController extends SettingController {
|
||||||
private static _matrixClient: MatrixClient;
|
private static _matrixClient?: MatrixClient;
|
||||||
private static instances: MatrixClientBackedController[] = [];
|
private static instances: MatrixClientBackedController[] = [];
|
||||||
|
|
||||||
public static set matrixClient(client: MatrixClient) {
|
public static set matrixClient(client: MatrixClient) {
|
||||||
|
@ -26,7 +26,7 @@ export default abstract class MatrixClientBackedController extends SettingContro
|
||||||
MatrixClientBackedController._matrixClient = client;
|
MatrixClientBackedController._matrixClient = client;
|
||||||
|
|
||||||
for (const instance of MatrixClientBackedController.instances) {
|
for (const instance of MatrixClientBackedController.instances) {
|
||||||
instance.initMatrixClient(oldClient, client);
|
instance.initMatrixClient(client, oldClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ export default abstract class MatrixClientBackedController extends SettingContro
|
||||||
MatrixClientBackedController.instances.push(this);
|
MatrixClientBackedController.instances.push(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get client(): MatrixClient {
|
public get client(): MatrixClient | undefined {
|
||||||
return MatrixClientBackedController._matrixClient;
|
return MatrixClientBackedController._matrixClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient): void;
|
protected abstract initMatrixClient(newClient: MatrixClient, oldClient?: MatrixClient): void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
|
||||||
|
|
||||||
import { SettingLevel } from "../SettingLevel";
|
import { SettingLevel } from "../SettingLevel";
|
||||||
import MatrixClientBackedController from "./MatrixClientBackedController";
|
import MatrixClientBackedController from "./MatrixClientBackedController";
|
||||||
import { WatchManager } from "../WatchManager";
|
import { WatchManager } from "../WatchManager";
|
||||||
|
@ -53,9 +51,9 @@ export default class ServerSupportUnstableFeatureController extends MatrixClient
|
||||||
this.watchers.notifyUpdate(this.settingName, null, level, settingValue);
|
this.watchers.notifyUpdate(this.settingName, null, level, settingValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient): Promise<void> {
|
protected async initMatrixClient(): Promise<void> {
|
||||||
// Check for stable version support first
|
// Check for stable version support first
|
||||||
if (this.stableVersion && (await this.client.isVersionSupported(this.stableVersion))) {
|
if (this.stableVersion && (await this.client!.isVersionSupported(this.stableVersion))) {
|
||||||
this.disabled = false;
|
this.disabled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +64,7 @@ export default class ServerSupportUnstableFeatureController extends MatrixClient
|
||||||
for (const featureGroup of this.unstableFeatureGroups) {
|
for (const featureGroup of this.unstableFeatureGroups) {
|
||||||
const featureSupportList = await Promise.all(
|
const featureSupportList = await Promise.all(
|
||||||
featureGroup.map(async (feature) => {
|
featureGroup.map(async (feature) => {
|
||||||
const isFeatureSupported = await this.client.doesServerSupportUnstableFeature(feature);
|
const isFeatureSupported = await this.client!.doesServerSupportUnstableFeature(feature);
|
||||||
return isFeatureSupported;
|
return isFeatureSupported;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
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 fetchMockJest from "fetch-mock-jest";
|
||||||
|
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
|
import { SettingLevel } from "../../../src/settings/SettingLevel";
|
||||||
|
import FallbackIceServerController from "../../../src/settings/controllers/FallbackIceServerController.ts";
|
||||||
|
import MatrixClientBackedController from "../../../src/settings/controllers/MatrixClientBackedController.ts";
|
||||||
|
import SettingsStore from "../../../src/settings/SettingsStore.ts";
|
||||||
|
|
||||||
|
describe("FallbackIceServerController", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
fetchMockJest.get("https://matrix.org/_matrix/client/versions", { versions: ["v1.4"] });
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update MatrixClient's state when the setting is updated", async () => {
|
||||||
|
const client = new MatrixClient({
|
||||||
|
baseUrl: "https://matrix.org",
|
||||||
|
userId: "@alice:matrix.org",
|
||||||
|
accessToken: "token",
|
||||||
|
});
|
||||||
|
MatrixClientBackedController.matrixClient = client;
|
||||||
|
|
||||||
|
expect(client.isFallbackICEServerAllowed()).toBeFalsy();
|
||||||
|
await SettingsStore.setValue("fallbackICEServerAllowed", null, SettingLevel.DEVICE, true);
|
||||||
|
expect(client.isFallbackICEServerAllowed()).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should force the setting to be disabled if disable_fallback_ice=true", async () => {
|
||||||
|
const controller = new FallbackIceServerController();
|
||||||
|
const client = new MatrixClient({
|
||||||
|
baseUrl: "https://matrix.org",
|
||||||
|
userId: "@alice:matrix.org",
|
||||||
|
accessToken: "token",
|
||||||
|
});
|
||||||
|
MatrixClientBackedController.matrixClient = client;
|
||||||
|
expect(controller.settingDisabled).toBeFalsy();
|
||||||
|
|
||||||
|
client["clientWellKnown"] = {
|
||||||
|
"io.element.voip": {
|
||||||
|
disable_fallback_ice: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
client.emit(ClientEvent.ClientWellKnown, client["clientWellKnown"]);
|
||||||
|
|
||||||
|
expect(controller.settingDisabled).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue