mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
array -> prop|null in discoverLocalTransport
This commit is contained in:
@@ -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$({
|
||||
|
||||
@@ -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([]),
|
||||
|
||||
@@ -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() ?? "");
|
||||
|
||||
Reference in New Issue
Block a user