fix: add .well-known fallback for MatrixRTC discovery

MatrixRTC transport discovery for MSC4143 is unstable-only and some
deployments still advertise foci via /.well-known/matrix/client
(org.matrix.msc4143.rtc_foci).

Try /unstable/org.matrix.msc4143/rtc/transports first, then fall back to
well-known so LiveKit can be used where configured.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
David Langley 2026-03-04 22:22:11 +00:00
parent 63075503c2
commit b3118d4859

View File

@ -84,17 +84,29 @@ export function useDocumentRTC(
const connect = async (): Promise<void> => {
// 1. Get available transports from the homeserver.
let transports;
// MSC4143 is still unstable, and some deployments only advertise foci via .well-known.
const transports: unknown[] = [];
try {
transports = await client._unstable_getRTCTransports();
transports.push(...(await client._unstable_getRTCTransports()));
} catch (e) {
logger.info("[DocumentRTC] Homeserver does not support /rtc/transports, falling back to Matrix events", e);
return;
logger.info("[DocumentRTC] Homeserver does not support /rtc/transports (MSC4143), trying .well-known fallback", e);
}
try {
await client.waitForClientWellKnown();
const foci = client.getClientWellKnown()?.["org.matrix.msc4143.rtc_foci"];
if (Array.isArray(foci)) {
transports.push(...foci);
} else if (foci) {
transports.push(foci);
}
} catch (e) {
logger.info("[DocumentRTC] Failed to read .well-known MatrixRTC foci", e);
}
const livekitTransport = transports.find(isLivekitTransportConfig);
if (!livekitTransport) {
logger.info("[DocumentRTC] No LiveKit transport in /rtc/transports, falling back to Matrix events");
logger.info("[DocumentRTC] No LiveKit transport configured, falling back to Matrix events");
return;
}