mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
The developer setting that overrode the LiveKit service URL becomes a JSON transport, so that a `url`-only or combined transport can be tested against a homeserver that does not advertise one yet. The settings modal shows each LiveKit room's role instead of a never-populated isLocal flag.
127 lines
3.5 KiB
TypeScript
127 lines
3.5 KiB
TypeScript
/*
|
|
Copyright 2025 Element Creations Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import {
|
|
afterEach,
|
|
beforeEach,
|
|
describe,
|
|
expect,
|
|
it,
|
|
type MockedObject,
|
|
vi,
|
|
} from "vitest";
|
|
import fetchMock from "fetch-mock";
|
|
|
|
import { mockConfig } from "../../../utils/test";
|
|
import { getLocalTransport } from "./LocalTransport";
|
|
import { MatrixRTCTransportMissingError } from "../../../utils/errors";
|
|
import { customTransport } from "../../../settings/settings";
|
|
import { type MatrixClient } from "matrix-js-sdk";
|
|
|
|
describe("LocalTransport", () => {
|
|
beforeEach(() => vi.clearAllMocks());
|
|
|
|
it("throws if config is missing", async () => {
|
|
await expect(
|
|
getLocalTransport({
|
|
_unstable_getRTCTransports: async () => Promise.resolve([]),
|
|
getDomain: () => "example.org",
|
|
}),
|
|
).rejects.toThrow(new MatrixRTCTransportMissingError("example.org"));
|
|
});
|
|
|
|
it("returns preferred transport", async () => {
|
|
// Use config so transport discovery succeeds
|
|
mockConfig({
|
|
livekit: { livekit_service_url: "https://lk.example.org" },
|
|
});
|
|
|
|
expect(
|
|
await getLocalTransport({
|
|
_unstable_getRTCTransports: async () => Promise.resolve([]),
|
|
getDomain: () => "example.org",
|
|
}),
|
|
).toStrictEqual({
|
|
transport: {
|
|
livekit_service_url: "https://lk.example.org",
|
|
type: "livekit",
|
|
},
|
|
serverName: "example.org",
|
|
});
|
|
});
|
|
|
|
describe("transport configuration mechanisms", () => {
|
|
let client: MockedObject<
|
|
Pick<MatrixClient, "getDomain" | "_unstable_getRTCTransports">
|
|
>;
|
|
beforeEach(() => {
|
|
mockConfig({});
|
|
customTransport.setValue(customTransport.defaultValue);
|
|
client = {
|
|
getDomain: vi.fn().mockReturnValue("example.org"),
|
|
_unstable_getRTCTransports: vi.fn().mockResolvedValue([]),
|
|
};
|
|
});
|
|
|
|
afterEach(() => {
|
|
fetchMock.reset();
|
|
});
|
|
|
|
it("supports getting transport via application config", async () => {
|
|
mockConfig({
|
|
livekit: { livekit_service_url: "https://lk.example.org" },
|
|
});
|
|
|
|
expect(await getLocalTransport(client)).toStrictEqual({
|
|
transport: {
|
|
livekit_service_url: "https://lk.example.org",
|
|
type: "livekit",
|
|
},
|
|
serverName: "example.org",
|
|
});
|
|
});
|
|
|
|
it("supports getting transport via user settings", async () => {
|
|
customTransport.setValue({
|
|
type: "livekit",
|
|
livekit_service_url: "https://lk.example.org",
|
|
});
|
|
|
|
expect(await getLocalTransport(client)).toStrictEqual({
|
|
transport: {
|
|
livekit_service_url: "https://lk.example.org",
|
|
type: "livekit",
|
|
},
|
|
serverName: "example.org",
|
|
});
|
|
});
|
|
|
|
it("supports getting transport via backend", async () => {
|
|
client._unstable_getRTCTransports.mockResolvedValue([
|
|
{ type: "livekit", livekit_service_url: "https://lk.example.org" },
|
|
]);
|
|
|
|
expect(await getLocalTransport(client)).toStrictEqual({
|
|
transport: {
|
|
livekit_service_url: "https://lk.example.org",
|
|
type: "livekit",
|
|
},
|
|
serverName: "example.org",
|
|
});
|
|
});
|
|
|
|
it("throws if no options are available", async () => {
|
|
await expect(
|
|
getLocalTransport({
|
|
getDomain: () => "example.org",
|
|
_unstable_getRTCTransports: async () => Promise.resolve([]),
|
|
}),
|
|
).rejects.toThrow(new MatrixRTCTransportMissingError("example.org"));
|
|
});
|
|
});
|
|
});
|