mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
getLocalTransport no longer authenticates with the SFU up front and hands the resulting config to the connection. Instead the ConnectionManager tags the connection whose transport equals the local one as the publisher, and every Connection fetches its own SFU config for its role. The local member now only joins the MatrixRTC session once its connection is authenticated, so that the LiveKit room exists before remote members try to get a subscriber token for it. Subscribers authenticating with the OpenID flow lack permission to create the room and would otherwise fail without retrying, causing a cascade of leaves and rejoins at the start of a call.
112 lines
3.2 KiB
TypeScript
112 lines
3.2 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 { customLivekitUrl } 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({
|
|
livekit_service_url: "https://lk.example.org",
|
|
type: "livekit",
|
|
});
|
|
});
|
|
|
|
describe("transport configuration mechanisms", () => {
|
|
let client: MockedObject<
|
|
Pick<MatrixClient, "getDomain" | "_unstable_getRTCTransports">
|
|
>;
|
|
beforeEach(() => {
|
|
mockConfig({});
|
|
customLivekitUrl.setValue(customLivekitUrl.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({
|
|
livekit_service_url: "https://lk.example.org",
|
|
type: "livekit",
|
|
});
|
|
});
|
|
|
|
it("supports getting transport via user settings", async () => {
|
|
customLivekitUrl.setValue("https://lk.example.org");
|
|
|
|
expect(await getLocalTransport(client)).toStrictEqual({
|
|
livekit_service_url: "https://lk.example.org",
|
|
type: "livekit",
|
|
});
|
|
});
|
|
|
|
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({
|
|
livekit_service_url: "https://lk.example.org",
|
|
type: "livekit",
|
|
});
|
|
});
|
|
|
|
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"));
|
|
});
|
|
});
|
|
});
|