|
| 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 fetchMockJest from "fetch-mock-jest"; |
| 9 | +import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/matrix"; |
| 10 | + |
| 11 | +import { SettingLevel } from "../../../src/settings/SettingLevel"; |
| 12 | +import FallbackIceServerController from "../../../src/settings/controllers/FallbackIceServerController.ts"; |
| 13 | +import MatrixClientBackedController from "../../../src/settings/controllers/MatrixClientBackedController.ts"; |
| 14 | +import SettingsStore from "../../../src/settings/SettingsStore.ts"; |
| 15 | + |
| 16 | +describe("FallbackIceServerController", () => { |
| 17 | + beforeEach(() => { |
| 18 | + fetchMockJest.get("https://matrix.org/_matrix/client/versions", { versions: ["v1.4"] }); |
| 19 | + }); |
| 20 | + |
| 21 | + afterEach(() => { |
| 22 | + jest.restoreAllMocks(); |
| 23 | + }); |
| 24 | + |
| 25 | + it("should update MatrixClient's state when the setting is updated", async () => { |
| 26 | + const client = new MatrixClient({ |
| 27 | + baseUrl: "https://matrix.org", |
| 28 | + userId: "@alice:matrix.org", |
| 29 | + accessToken: "token", |
| 30 | + }); |
| 31 | + MatrixClientBackedController.matrixClient = client; |
| 32 | + |
| 33 | + expect(client.isFallbackICEServerAllowed()).toBeFalsy(); |
| 34 | + await SettingsStore.setValue("fallbackICEServerAllowed", null, SettingLevel.DEVICE, true); |
| 35 | + expect(client.isFallbackICEServerAllowed()).toBeTruthy(); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should force the setting to be disabled if disable_fallback_ice=true", async () => { |
| 39 | + const controller = new FallbackIceServerController(); |
| 40 | + const client = new MatrixClient({ |
| 41 | + baseUrl: "https://matrix.org", |
| 42 | + userId: "@alice:matrix.org", |
| 43 | + accessToken: "token", |
| 44 | + }); |
| 45 | + MatrixClientBackedController.matrixClient = client; |
| 46 | + expect(controller.settingDisabled).toBeFalsy(); |
| 47 | + |
| 48 | + client["clientWellKnown"] = { |
| 49 | + "io.element.voip": { |
| 50 | + disable_fallback_ice: true, |
| 51 | + }, |
| 52 | + }; |
| 53 | + client.emit(ClientEvent.ClientWellKnown, client["clientWellKnown"]); |
| 54 | + |
| 55 | + expect(controller.settingDisabled).toBeTruthy(); |
| 56 | + }); |
| 57 | +}); |
0 commit comments