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
|
// 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,
|
// fallback: another member's SFU may let us publish (MSC4195). LiveKit only,
|
||||||
// so it stays out of the backend interface
|
// so it stays out of the backend interface
|
||||||
const transportsFromBackends = async (): Promise<Transport[]> =>
|
const transportFromBackends = async (): Promise<Transport | null> =>
|
||||||
backend.transportType === "livekit"
|
backend.transportType === "livekit"
|
||||||
? findRemotePublishLivekitTransport({
|
? findRemotePublishLivekitTransport({
|
||||||
client,
|
client,
|
||||||
@@ -146,20 +146,22 @@ export function createRTCParticipation(
|
|||||||
roomId: room.roomId,
|
roomId: room.roomId,
|
||||||
slotId: jsSdkSession.slotId,
|
slotId: jsSdkSession.slotId,
|
||||||
logger,
|
logger,
|
||||||
}).then((transport) => (transport === null ? [] : [transport]))
|
})
|
||||||
: [];
|
: null;
|
||||||
|
|
||||||
const preparedTransport$ = from(
|
const preparedTransport$ = from(
|
||||||
discoverLocalTransport(
|
discoverLocalTransport(
|
||||||
client,
|
client,
|
||||||
backend.transportType,
|
backend.transportType,
|
||||||
options,
|
options,
|
||||||
transportsFromBackends,
|
transportFromBackends,
|
||||||
logger,
|
logger,
|
||||||
).then(async (transport): Promise<PreparedTransport> => ({
|
).then(
|
||||||
|
async (transport): Promise<PreparedTransport> => ({
|
||||||
transport,
|
transport,
|
||||||
...(await backend.prepareLocalTransport(transport)),
|
...(await backend.prepareLocalTransport(transport)),
|
||||||
})),
|
}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
const localMembership = createLocalMembership$({
|
const localMembership = createLocalMembership$({
|
||||||
|
|||||||
@@ -25,11 +25,6 @@ const bobsTransport: Transport = {
|
|||||||
url: "wss://sfu.bob.com",
|
url: "wss://sfu.bob.com",
|
||||||
server_name: "bob.com",
|
server_name: "bob.com",
|
||||||
};
|
};
|
||||||
const carolsTransport: Transport = {
|
|
||||||
type: "livekit",
|
|
||||||
url: "wss://sfu.carol.com",
|
|
||||||
server_name: "carol.com",
|
|
||||||
};
|
|
||||||
|
|
||||||
function client(
|
function client(
|
||||||
advertised: Transport[],
|
advertised: Transport[],
|
||||||
@@ -41,9 +36,9 @@ function client(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fromBackends(
|
function fromBackends(
|
||||||
transports: Transport[] = [],
|
transport: Transport|null = null,
|
||||||
): ReturnType<typeof vi.fn<() => Promise<Transport[]>>> {
|
): ReturnType<typeof vi.fn<() => Promise<Transport|null>>> {
|
||||||
return vi.fn(async () => Promise.resolve(transports));
|
return vi.fn(async () => Promise.resolve(transport));
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("discoverLocalTransport", () => {
|
describe("discoverLocalTransport", () => {
|
||||||
@@ -87,7 +82,7 @@ describe("discoverLocalTransport", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("prefers a local transport over the backends' without asking them", async () => {
|
it("prefers a local transport over the backends' without asking them", async () => {
|
||||||
const backends = fromBackends([bobsTransport]);
|
const backends = fromBackends(bobsTransport);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
discoverLocalTransport(
|
discoverLocalTransport(
|
||||||
@@ -101,18 +96,6 @@ describe("discoverLocalTransport", () => {
|
|||||||
expect(backends).not.toHaveBeenCalled();
|
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 () => {
|
it("fails naming the homeserver where there is no transport at all", async () => {
|
||||||
const promise = discoverLocalTransport(
|
const promise = discoverLocalTransport(
|
||||||
client([]),
|
client([]),
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export async function discoverLocalTransport(
|
|||||||
transport: override,
|
transport: override,
|
||||||
fallbackTransport,
|
fallbackTransport,
|
||||||
}: Pick<RTCParticipationOptions, "transport" | "fallbackTransport">,
|
}: Pick<RTCParticipationOptions, "transport" | "fallbackTransport">,
|
||||||
transportsFromBackends: () => Promise<Transport[]>,
|
transportFromBackends: () => Promise<Transport | null>,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
): Promise<Transport> {
|
): Promise<Transport> {
|
||||||
const transport =
|
const transport =
|
||||||
@@ -38,7 +38,7 @@ export async function discoverLocalTransport(
|
|||||||
fallbackTransport,
|
fallbackTransport,
|
||||||
logger,
|
logger,
|
||||||
}).discoverPreferredTransport()) ??
|
}).discoverPreferredTransport()) ??
|
||||||
(await transportsFromBackends()).at(0) ??
|
(await transportFromBackends()) ??
|
||||||
null;
|
null;
|
||||||
if (transport === null)
|
if (transport === null)
|
||||||
throw new MatrixRTCTransportMissingError(client.getDomain() ?? "");
|
throw new MatrixRTCTransportMissingError(client.getDomain() ?? "");
|
||||||
|
|||||||
Reference in New Issue
Block a user