This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable ICE fallback based on well-known configuration
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
- Loading branch information
Showing
4 changed files
with
55 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |