Files
cinny/src/app/plugins/call/CallWidgetDriver.rtcTransports.test.ts
T
jaredandClaude Opus 5 b74f9f5699
CI / Build & Quality Checks (push) Successful in 1m30s
CI / Docker image build & smoke test (push) Skipped
CI / Secret scan (gitleaks) (push) Successful in 11s
CI / Trigger Desktop Build (push) Successful in 9s
CI / Playwright smoke (e2e) (push) Successful in 2m59s
fix(call): actually resolve .well-known rtc_foci for MSC4515 — SDK cache is empty at runtime
81a6d9c9 wired getRtcTransports() but its .well-known fallback read
mx.getClientWellKnown(), which the SDK only populates when the client
is started with clientWellKnownPollPeriod — cinny never sets it, so on
the live client the fallback returned [] and calls still failed with
MISSING_MATRIX_RTC_TRANSPORT after deploy. (The unit test faked a
populated cache and hid this.)

The driver now fetches the client .well-known itself, once, via
AutoDiscovery.getRawClientConfig(domain) — the same resolver Element
Call used before 0.22 — and only when the SDK has nothing cached. Test
added for the uncached path (asserts a single fetch); verified the
resolver returns the livekit focus for matrix.lotusguild.org.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
2026-09-14 19:39:40 -04:00

91 lines
3.4 KiB
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import type { MatrixClient } from 'matrix-js-sdk';
import { AutoDiscovery } from 'matrix-js-sdk';
import { CallWidgetDriver } from './CallWidgetDriver';
// MSC4515: Element Call (widget mode) asks the host for RTC transports. Without a
// working answer every call fails with MISSING_MATRIX_RTC_TRANSPORT.
function fakeClient(opts: {
serverTransports?: unknown[] | Error;
wellKnown?: Record<string, unknown>;
}): MatrixClient {
return {
getDeviceId: () => 'DEV',
getSafeUserId: () => '@me:example.org',
_unstable_getRTCTransports: async () => {
if (opts.serverTransports instanceof Error) throw opts.serverTransports;
return opts.serverTransports ?? [];
},
getClientWellKnown: () => opts.wellKnown,
getDomain: () => 'example.org',
} as unknown as MatrixClient;
}
const focus = { type: 'livekit', livekit_service_url: 'https://matrix.example.org' };
test('getRtcTransports prefers the homeserver MSC4143 endpoint', async () => {
const driver = new CallWidgetDriver(fakeClient({ serverTransports: [focus] }), '!r:x');
const r = await driver.getRtcTransports();
assert.deepEqual(r.rtc_transports, [focus]);
});
test('getRtcTransports falls back to .well-known rtc_foci when the endpoint 404s', async () => {
const driver = new CallWidgetDriver(
fakeClient({
serverTransports: new Error('404'),
wellKnown: { 'org.matrix.msc4143.rtc_foci': [focus, { junk: true }, null] },
}),
'!r:x',
);
const r = await driver.getRtcTransports();
assert.deepEqual(r.rtc_transports, [focus]);
});
test('getRtcTransports fetches .well-known itself when the SDK has nothing cached (the live cinny case)', async () => {
// cinny never sets clientWellKnownPollPeriod, so getClientWellKnown() is undefined
// at runtime; the driver must resolve it via AutoDiscovery instead.
const orig = AutoDiscovery.getRawClientConfig;
let calls = 0;
AutoDiscovery.getRawClientConfig = async () => {
calls += 1;
return { 'org.matrix.msc4143.rtc_foci': [focus] } as never;
};
try {
const driver = new CallWidgetDriver(
fakeClient({ serverTransports: new Error('404'), wellKnown: undefined }),
'!r:x',
);
const r1 = await driver.getRtcTransports();
const r2 = await driver.getRtcTransports();
assert.deepEqual(r1.rtc_transports, [focus]);
assert.deepEqual(r2.rtc_transports, [focus]);
assert.equal(calls, 1, 'well-known is fetched once per driver');
} finally {
AutoDiscovery.getRawClientConfig = orig;
}
});
test('getRtcTransports returns an empty list when nothing is advertised', async () => {
const orig = AutoDiscovery.getRawClientConfig;
AutoDiscovery.getRawClientConfig = async () => ({ 'm.homeserver': {} }) as never;
try {
const driver = new CallWidgetDriver(
fakeClient({ serverTransports: [], wellKnown: { 'm.homeserver': {} } }),
'!r:x',
);
const r = await driver.getRtcTransports();
assert.deepEqual(r.rtc_transports, []);
} finally {
AutoDiscovery.getRawClientConfig = orig;
}
});
test('the MSC4515 capability is granted to the call widget', async () => {
const driver = new CallWidgetDriver(fakeClient({}), '!r:x');
const allowed = await driver.validateCapabilities(
new Set(['org.matrix.msc4515.rtc_transports', 'org.example.not_allowed']),
);
assert.deepEqual(Array.from(allowed), ['org.matrix.msc4515.rtc_transports']);
});