|
| 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 | +} |
0 commit comments