From 281fff0e9f09ab0968a244c806a3f9a4e3f5c2cd Mon Sep 17 00:00:00 2001 From: "Timo K." Date: Wed, 14 Oct 2026 19:01:14 +0200 Subject: [PATCH] array -> prop|null in discoverLocalTransport --- sdk/src/RTCParticipation.ts | 18 +++++++++-------- sdk/src/matrixrtc/LocalTransport.test.ts | 25 ++++-------------------- sdk/src/matrixrtc/LocalTransport.ts | 4 ++-- 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/sdk/src/RTCParticipation.ts b/sdk/src/RTCParticipation.ts index eb00aae35..4195d8988 100644 --- a/sdk/src/RTCParticipation.ts +++ b/sdk/src/RTCParticipation.ts @@ -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 => + const transportFromBackends = async (): Promise => 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 => ({ - transport, - ...(await backend.prepareLocalTransport(transport)), - })), + ).then( + async (transport): Promise => ({ + transport, + ...(await backend.prepareLocalTransport(transport)), + }), + ), ); const localMembership = createLocalMembership$({ diff --git a/sdk/src/matrixrtc/LocalTransport.test.ts b/sdk/src/matrixrtc/LocalTransport.test.ts index b81958e2e..d030b2b2d 100644 --- a/sdk/src/matrixrtc/LocalTransport.test.ts +++ b/sdk/src/matrixrtc/LocalTransport.test.ts @@ -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 Promise>> { - return vi.fn(async () => Promise.resolve(transports)); + transport: Transport|null = null, +): ReturnType Promise>> { + 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([]), diff --git a/sdk/src/matrixrtc/LocalTransport.ts b/sdk/src/matrixrtc/LocalTransport.ts index 4c967ce39..0f3272861 100644 --- a/sdk/src/matrixrtc/LocalTransport.ts +++ b/sdk/src/matrixrtc/LocalTransport.ts @@ -27,7 +27,7 @@ export async function discoverLocalTransport( transport: override, fallbackTransport, }: Pick, - transportsFromBackends: () => Promise, + transportFromBackends: () => Promise, logger: Logger, ): Promise { 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() ?? "");