-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 (#111)
* Refactor MatrixClientBackedController.ts Signed-off-by: Michael Telatynski <[email protected]> * Disable ICE fallback based on well-known configuration Signed-off-by: Michael Telatynski <[email protected]> * Add tests Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
- Loading branch information
Showing
7 changed files
with
119 additions
and
15 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")); | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
test/settings/controllers/FallbackIceServerController-test.ts
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,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(); | ||
}); | ||
}); |