array -> prop|null in discoverLocalTransport

This commit is contained in:
Timo K.
2026-10-14 19:01:14 +02:00
parent bc557dfb5d
commit 281fff0e9f
3 changed files with 16 additions and 31 deletions
+10 -8
View File
@@ -135,7 +135,7 @@ export function createRTCParticipation(
// If the backend is LiveKit, we check it for transports as well, as a
// fallback: another member's SFU may let us publish (MSC4195). LiveKit only,
// so it stays out of the backend interface
const transportsFromBackends = async (): Promise<Transport[]> =>
const transportFromBackends = async (): Promise<Transport | null> =>
backend.transportType === "livekit"
? findRemotePublishLivekitTransport({
client,
@@ -146,20 +146,22 @@ export function createRTCParticipation(
roomId: room.roomId,
slotId: jsSdkSession.slotId,
logger,
}).then((transport) => (transport === null ? [] : [transport]))
: [];
})
: null;
const preparedTransport$ = from(
discoverLocalTransport(
client,
backend.transportType,
options,
transportsFromBackends,
transportFromBackends,
logger,
).then(async (transport): Promise<PreparedTransport> => ({
transport,
...(await backend.prepareLocalTransport(transport)),
})),
).then(
async (transport): Promise<PreparedTransport> => ({
transport,
...(await backend.prepareLocalTransport(transport)),
}),
),
);
const localMembership = createLocalMembership$({
+4 -21
View File
@@ -25,11 +25,6 @@ const bobsTransport: Transport = {
url: "wss://sfu.bob.com",
server_name: "bob.com",
};
const carolsTransport: Transport = {
type: "livekit",
url: "wss://sfu.carol.com",
server_name: "carol.com",
};
function client(
advertised: Transport[],
@@ -41,9 +36,9 @@ function client(
}
function fromBackends(
transports: Transport[] = [],
): ReturnType<typeof vi.fn<() => Promise<Transport[]>>> {
return vi.fn(async () => Promise.resolve(transports));
transport: Transport|null = null,
): ReturnType<typeof vi.fn<() => Promise<Transport|null>>> {
return vi.fn(async () => Promise.resolve(transport));
}
describe("discoverLocalTransport", () => {
@@ -87,7 +82,7 @@ describe("discoverLocalTransport", () => {
});
it("prefers a local transport over the backends' without asking them", async () => {
const backends = fromBackends([bobsTransport]);
const backends = fromBackends(bobsTransport);
await expect(
discoverLocalTransport(
@@ -101,18 +96,6 @@ describe("discoverLocalTransport", () => {
expect(backends).not.toHaveBeenCalled();
});
it("takes the first transport the backends provide where there is no local one", async () => {
await expect(
discoverLocalTransport(
client([]),
"livekit",
{},
fromBackends([bobsTransport, carolsTransport]),
logger,
),
).resolves.toEqual(bobsTransport);
});
it("fails naming the homeserver where there is no transport at all", async () => {
const promise = discoverLocalTransport(
client([]),
+2 -2
View File
@@ -27,7 +27,7 @@ export async function discoverLocalTransport(
transport: override,
fallbackTransport,
}: Pick<RTCParticipationOptions, "transport" | "fallbackTransport">,
transportsFromBackends: () => Promise<Transport[]>,
transportFromBackends: () => Promise<Transport | null>,
logger: Logger,
): Promise<Transport> {
const transport =
@@ -38,7 +38,7 @@ export async function discoverLocalTransport(
fallbackTransport,
logger,
}).discoverPreferredTransport()) ??
(await transportsFromBackends()).at(0) ??
(await transportFromBackends()) ??
null;
if (transport === null)
throw new MatrixRTCTransportMissingError(client.getDomain() ?? "");