Retain compatiblity in compatiblity mode

This commit is contained in:
Johannes Marbach
2026-10-12 15:40:27 +02:00
parent 49223e720b
commit 68107d119e
13 changed files with 247 additions and 65 deletions
+23 -4
View File
@@ -8,6 +8,7 @@ Please see LICENSE in the repository root for full details.
import { expect, type Page, test } from "@playwright/test"; import { expect, type Page, test } from "@playwright/test";
import { SpaHelpers } from "./spa-helpers"; import { SpaHelpers } from "./spa-helpers";
import { type RtcMode } from "./widget/test-helpers.ts";
const sfuUrl = "wss://matrix-rtc.m.localhost/livekit/sfu"; const sfuUrl = "wss://matrix-rtc.m.localhost/livekit/sfu";
const serviceUrl = "https://matrix-rtc.m.localhost/livekit/jwt"; const serviceUrl = "https://matrix-rtc.m.localhost/livekit/jwt";
@@ -41,6 +42,8 @@ type Flow = "cs-api" | "service-legacy" | "service-default";
const cases: { const cases: {
hostShape: Shape; hostShape: Shape;
guestShape: Shape; guestShape: Shape;
/** The MatrixRTC mode both sides use; the default is compatibility mode. */
mode?: RtcMode;
hostFlows: Flow[]; hostFlows: Flow[];
guestFlows: Flow[]; guestFlows: Flow[];
}[] = [ }[] = [
@@ -51,8 +54,19 @@ const cases: {
guestFlows: ["cs-api"], guestFlows: ["cs-api"],
}, },
{ {
// In compatibility mode both publish a membership state event, so both
// must keep the legacy participant identity that clients predating MSC4195
// expect, which only the JWT service assigns.
hostShape: "both", hostShape: "both",
guestShape: "both", guestShape: "both",
hostFlows: ["service-legacy"],
guestFlows: ["service-legacy"],
},
{
// In Matrix 2.0 mode nobody expects a legacy identity, so the CS API wins.
hostShape: "both",
guestShape: "both",
mode: "2_0",
hostFlows: ["cs-api"], hostFlows: ["cs-api"],
guestFlows: ["cs-api"], guestFlows: ["cs-api"],
}, },
@@ -64,8 +78,8 @@ const cases: {
}, },
]; ];
for (const { hostShape, guestShape, hostFlows, guestFlows } of cases) { for (const { hostShape, guestShape, mode, hostFlows, guestFlows } of cases) {
test(`One to one call with ${hostShape} host and ${guestShape} guest transport`, async ({ test(`One to one call with ${hostShape} host and ${guestShape} guest transport${mode === "2_0" ? " in Matrix 2.0 mode" : ""}`, async ({
browser, browser,
page, page,
browserName, browserName,
@@ -76,7 +90,7 @@ for (const { hostShape, guestShape, hostFlows, guestFlows } of cases) {
await advertiseTransport(page, shapes[hostShape]); await advertiseTransport(page, shapes[hostShape]);
const hostRequests = recordAuthRequests(page); const hostRequests = recordAuthRequests(page);
await page.goto("/"); await page.goto("/");
await SpaHelpers.createCall(page, "Androl", "HelloCall", true); await SpaHelpers.createCall(page, "Androl", "HelloCall", true, mode);
const inviteLink = await SpaHelpers.getCallInviteLink(page); const inviteLink = await SpaHelpers.getCallInviteLink(page);
// The guest joins. // The guest joins.
@@ -84,7 +98,12 @@ for (const { hostShape, guestShape, hostFlows, guestFlows } of cases) {
const guestPage = await guestContext.newPage(); const guestPage = await guestContext.newPage();
await advertiseTransport(guestPage, shapes[guestShape]); await advertiseTransport(guestPage, shapes[guestShape]);
const guestRequests = recordAuthRequests(guestPage); const guestRequests = recordAuthRequests(guestPage);
await SpaHelpers.joinCallFromInviteLink(guestPage, inviteLink, "Pevara"); await SpaHelpers.joinCallFromInviteLink(
guestPage,
inviteLink,
"Pevara",
mode,
);
// Wait for the call to connect and render. // Wait for the call to connect and render.
await SpaHelpers.expectVideoTilesCount(page, 2); await SpaHelpers.expectVideoTilesCount(page, 2);
+67
View File
@@ -21,6 +21,7 @@ import { delegateDelayedLeave, getSFUConfig } from ".";
import { mocked } from "storybook/test"; import { mocked } from "storybook/test";
import { ConnectionError, MatrixError } from "matrix-js-sdk"; import { ConnectionError, MatrixError } from "matrix-js-sdk";
import { NoMatrix2AuthorizationService } from "../../utils/errors"; import { NoMatrix2AuthorizationService } from "../../utils/errors";
import { MatrixRTCMode } from "../../config/ConfigOptions";
import { type CallMembershipIdentityParts } from "matrix-js-sdk/lib/matrixrtc/EncryptionManager"; import { type CallMembershipIdentityParts } from "matrix-js-sdk/lib/matrixrtc/EncryptionManager";
vi.mock("./openID", () => ({ getSFUConfig: vi.fn() })); vi.mock("./openID", () => ({ getSFUConfig: vi.fn() }));
@@ -83,6 +84,7 @@ describe("getSFUConfig", () => {
membership, membership,
serverName: "example.org", serverName: "example.org",
role: "subscriber" as const, role: "subscriber" as const,
matrixRTCMode: MatrixRTCMode.Matrix_2_0,
roomId, roomId,
slotId, slotId,
logger, logger,
@@ -169,6 +171,53 @@ describe("getSFUConfig", () => {
expect(openID.getSFUConfig).not.toHaveBeenCalled(); expect(openID.getSFUConfig).not.toHaveBeenCalled();
}); });
it("uses OpenID when publishing in compatibility mode with url + livekit_service_url transport", async () => {
// Subscribers predating MSC4195 expect a legacy participant identity from
// anyone advertising a state event, which only the JWT service assigns
expect(
await getSFUConfig({
...defaultParams,
transport: urlAndServiceUrlTransport,
role: "publisher",
matrixRTCMode: MatrixRTCMode.Compatibility,
}),
).toEqual(
expect.objectContaining({
jwt: openIDJWTToken,
livekitAlias: "via OpenID",
}),
);
expect(client._unstable_getLivekitToken).not.toHaveBeenCalled();
expect(openID.getSFUConfig).toHaveBeenCalledWith(
expect.objectContaining({ role: "publisher" }),
);
});
it("uses CS API when publishing in compatibility mode with url transport", async () => {
expect(
await getSFUConfig({
...defaultParams,
transport: urlTransport,
role: "publisher",
matrixRTCMode: MatrixRTCMode.Compatibility,
}),
).toEqual(expect.objectContaining({ jwt: csApiJWTToken }));
expect(client._unstable_getLivekitToken).toHaveBeenCalled();
expect(openID.getSFUConfig).not.toHaveBeenCalled();
});
it("uses CS API when subscribing in compatibility mode with url + livekit_service_url transport", async () => {
expect(
await getSFUConfig({
...defaultParams,
transport: urlAndServiceUrlTransport,
matrixRTCMode: MatrixRTCMode.Compatibility,
}),
).toEqual(expect.objectContaining({ jwt: csApiJWTToken }));
expect(client._unstable_getLivekitToken).toHaveBeenCalled();
expect(openID.getSFUConfig).not.toHaveBeenCalled();
});
it("does not fall back to OpenID on connection error", async () => { it("does not fall back to OpenID on connection error", async () => {
const client_ = { const client_ = {
...client, ...client,
@@ -198,6 +247,7 @@ describe("delegateDelayedLeave", () => {
roomId, roomId,
slotId, slotId,
delayId: "delay123", delayId: "delay123",
matrixRTCMode: MatrixRTCMode.Matrix_2_0,
logger, logger,
}; };
@@ -236,6 +286,23 @@ describe("delegateDelayedLeave", () => {
expect(openID.getSFUConfig).not.toHaveBeenCalled(); expect(openID.getSFUConfig).not.toHaveBeenCalled();
}); });
it("uses OpenID in compatibility mode with url + livekit_service_url transport", async () => {
// Must match the flow that got the token, so the identities line up
await delegateDelayedLeave({
...defaultParams,
transport: urlAndServiceUrlTransport,
matrixRTCMode: MatrixRTCMode.Compatibility,
});
expect(client._unstable_delegateDelayedLeave).not.toHaveBeenCalled();
expect(openID.getSFUConfig).toHaveBeenCalledWith(
expect.objectContaining({
role: "publisher",
delayId: "delay123",
delayEndpointBaseUrl: client.baseUrl,
}),
);
});
it("does not fall back to OpenID with url + livekit_service_url transport", async () => { it("does not fall back to OpenID with url + livekit_service_url transport", async () => {
client._unstable_delegateDelayedLeave.mockRejectedValueOnce( client._unstable_delegateDelayedLeave.mockRejectedValueOnce(
unsupportedError, unsupportedError,
+75 -27
View File
@@ -14,6 +14,7 @@ import * as openID from "./openID";
import * as csApi from "./csApi"; import * as csApi from "./csApi";
import { type SFUConfig } from "./types"; import { type SFUConfig } from "./types";
import { NoMatrix2AuthorizationService } from "../../utils/errors"; import { NoMatrix2AuthorizationService } from "../../utils/errors";
import { MatrixRTCMode } from "../../config/ConfigOptions";
export type { ClientOpenIDParts } from "./openID"; export type { ClientOpenIDParts } from "./openID";
export type { ClientGetTokenParts, ClientDelegationParts } from "./csApi"; export type { ClientGetTokenParts, ClientDelegationParts } from "./csApi";
@@ -66,6 +67,11 @@ export interface GetSFUConfigParams {
* Whether we want to publish or only subscribe on the {@link transport}. * Whether we want to publish or only subscribe on the {@link transport}.
*/ */
role: "publisher" | "subscriber"; role: "publisher" | "subscriber";
/**
* The MatrixRTC mode, which decides the format of our membership event and
* so the participant identity a publisher must have.
*/
matrixRTCMode: MatrixRTCMode;
logger: Logger; logger: Logger;
} }
@@ -80,53 +86,52 @@ export async function getSFUConfig({
roomId, roomId,
slotId, slotId,
role, role,
matrixRTCMode,
logger, logger,
}: GetSFUConfigParams): Promise<SFUConfig> { }: GetSFUConfigParams): Promise<SFUConfig> {
if ("url" in transport) { const viaOpenID = async (serviceUrl: string): Promise<SFUConfig> =>
await openID.getSFUConfig({
client,
membership,
serviceUrl,
roomId,
slotId,
role,
logger,
});
const flow = chooseAuthFlow(transport, role, matrixRTCMode);
if (flow.kind === "openID") return await viaOpenID(flow.serviceUrl);
try { try {
return await csApi.getSFUConfig({ return await csApi.getSFUConfig({
client, client,
membership, membership,
url: transport.url, url: flow.url,
serverName, serverName,
roomId, roomId,
slotId, slotId,
}); });
} catch (e) { } catch (e) {
if (isEndpointUnsupported(e)) { if (!isEndpointUnsupported(e)) throw e;
// Publishers should never fall back. If a homeserver advertises a `url` // Publishers should never fall back. If a homeserver advertises a `url`
// but doesn't support MSC4195 itself, that's a misconfiguration which // but doesn't support MSC4195 itself, that's a misconfiguration which
// the admin should know about so they can prepare for the future // the admin should know about so they can prepare for the future
// deprecation of `livekit_service_url`. // deprecation of `livekit_service_url`.
const mayFallBack = const mayFallBack =
role === "subscriber" && "livekit_service_url" in transport; role === "subscriber" && "livekit_service_url" in transport;
if (mayFallBack) { if (!mayFallBack) {
logger.warn(
`Homeserver does not support the MSC4195 get_token endpoint, falling back to the OpenID flow with service ${transport.livekit_service_url}`,
);
// Fall through
} else {
logger.error( logger.error(
`Homeserver does not support the MSC4195 get_token endpoint, cannot get token for transport ${transport.url}`, `Homeserver does not support the MSC4195 get_token endpoint, cannot get token for transport ${flow.url}`,
); );
throw new NoMatrix2AuthorizationService(e as Error); throw new NoMatrix2AuthorizationService(e as Error);
} }
} else { logger.warn(
throw e; `Homeserver does not support the MSC4195 get_token endpoint, falling back to the OpenID flow with service ${transport.livekit_service_url}`,
);
return await viaOpenID(transport.livekit_service_url);
} }
} }
}
return await openID.getSFUConfig({
client,
membership,
serviceUrl: transport.livekit_service_url,
roomId,
slotId,
role,
logger,
});
}
export interface DelegateDelayedLeaveParams { export interface DelegateDelayedLeaveParams {
/** /**
@@ -154,6 +159,10 @@ export interface DelegateDelayedLeaveParams {
* The delay ID of the leave event to be delegated. * The delay ID of the leave event to be delegated.
*/ */
delayId: string; delayId: string;
/**
* The MatrixRTC mode, which decides the format of our membership event.
*/
matrixRTCMode: MatrixRTCMode;
logger: Logger; logger: Logger;
} }
@@ -168,17 +177,19 @@ export async function delegateDelayedLeave({
roomId, roomId,
slotId, slotId,
delayId, delayId,
matrixRTCMode,
logger, logger,
}: DelegateDelayedLeaveParams): Promise<void> { }: DelegateDelayedLeaveParams): Promise<void> {
// It's important that we use the same flow (CS API or OpenID) as whatever we // It's important that we use the same flow (CS API or OpenID) as whatever we
// would've used to get a JWT token for this transport, since the participant // would've used to get a JWT token for this transport, since the participant
// identity computed by the service needs to match. // identity computed by the service needs to match.
if ("url" in transport) { const flow = chooseAuthFlow(transport, "publisher", matrixRTCMode);
if (flow.kind === "csApi") {
try { try {
await csApi.delegateDelayedLeave({ await csApi.delegateDelayedLeave({
client, client,
membership, membership,
url: transport.url, url: flow.url,
roomId, roomId,
slotId, slotId,
delayId, delayId,
@@ -196,7 +207,7 @@ export async function delegateDelayedLeave({
await openID.getSFUConfig({ await openID.getSFUConfig({
client, client,
membership, membership,
serviceUrl: transport.livekit_service_url, serviceUrl: flow.serviceUrl,
roomId, roomId,
slotId, slotId,
role: "publisher", role: "publisher",
@@ -206,3 +217,40 @@ export async function delegateDelayedLeave({
}); });
} }
} }
/**
* The flow with which the local member authenticates against a transport.
*/
export type AuthFlow =
| { kind: "csApi"; url: string }
| { kind: "openID"; serviceUrl: string };
/**
* Chooses between the MSC4195 CS API and the legacy OpenID flow against the
* transport's JWT service.
*
* Only the JWT service's `/sfu/get` endpoint assigns the legacy participant
* identity that clients predating MSC4195 expect from anyone advertising a
* membership state event, which is what compatibility mode sends. So a
* publisher in compatibility mode keeps using the JWT service wherever the
* transport still offers one, even if it also has a `url`. Subscribers may use
* the CS API regardless, as nobody matches their identity.
* @param transport The transport to authenticate against.
* @param role Whether we want to publish or only subscribe on the transport.
* @param matrixRTCMode The MatrixRTC mode, which decides the format of our
* membership event.
*/
export function chooseAuthFlow(
transport: UnstableLivekitTransport,
role: "publisher" | "subscriber",
matrixRTCMode: MatrixRTCMode,
): AuthFlow {
if ("url" in transport) {
const useCsApi =
!("livekit_service_url" in transport) ||
role === "subscriber" ||
matrixRTCMode === MatrixRTCMode.Matrix_2_0;
if (useCsApi) return { kind: "csApi", url: transport.url };
}
return { kind: "openID", serviceUrl: transport.livekit_service_url };
}
+8 -1
View File
@@ -530,6 +530,7 @@ export const DeveloperSettingsTab: FC<Props> = ({
roomId, roomId,
slotId: "org.example.fake-slot#room", slotId: "org.example.fake-slot#room",
role: "publisher", role: "publisher",
matrixRTCMode: effectiveMatrixRTCMode,
logger, logger,
}); });
setCustomLivekitUrlUpdateError(null); setCustomLivekitUrlUpdateError(null);
@@ -540,7 +541,13 @@ export const DeveloperSettingsTab: FC<Props> = ({
); );
} }
}, },
[customTransportTextBuffer, setCustomTransport, client, roomId], [
customTransportTextBuffer,
setCustomTransport,
client,
roomId,
effectiveMatrixRTCMode,
],
)} )}
value={customTransportTextBuffer ?? ""} value={customTransportTextBuffer ?? ""}
onChange={useCallback( onChange={useCallback(
+2
View File
@@ -575,6 +575,7 @@ export function createCallViewModel$(
client, client,
matrixRoom.roomId, matrixRoom.roomId,
matrixRTCSession.slotId, matrixRTCSession.slotId,
matrixRTCMode,
mediaDevices, mediaDevices,
trackProcessorState$, trackProcessorState$,
livekitKeyProvider, livekitKeyProvider,
@@ -665,6 +666,7 @@ export function createCallViewModel$(
).pipe(map(([delayId]) => delayId ?? null)), ).pipe(map(([delayId]) => delayId ?? null)),
matrixRTCSession.delayId ?? null, matrixRTCSession.delayId ?? null,
), ),
matrixRTCMode,
logger: logger.getChild(`[${Date.now()}]`), logger: logger.getChild(`[${Date.now()}]`),
}); });
@@ -230,6 +230,7 @@ export function withCallViewModel(mode: MatrixRTCMode) {
client: room.client, client: room.client,
roomId: room.roomId, roomId: room.roomId,
slotId: "m.call#ROOM", slotId: "m.call#ROOM",
matrixRTCMode: mode,
livekitRoomFactory, livekitRoomFactory,
}, },
logger, logger,
@@ -346,21 +346,27 @@ describe("LocalMembership", () => {
.mockResolvedValue(); .mockResolvedValue();
afterEach(() => delegationSpy.mockClear()); afterEach(() => delegationSpy.mockClear());
// The transport has both a `url` and a `livekit_service_url`. In Matrix 2.0
// mode we publish through the CS API, so the homeserver delegates; in
// compatibility mode we publish through the JWT service, so that delegates.
it.each([ it.each([
["no", null, timings], ["no", MatrixRTCMode.Compatibility, null, timings],
["no", MatrixRTCMode.Matrix_2_0, null, timings],
[ [
"homeserver", "homeserver",
MatrixRTCMode.Matrix_2_0,
"https://matrix.example.org/_matrix/client/unstable/io.element.msc4195/rtc/livekit/delegate_delayed_leave", "https://matrix.example.org/_matrix/client/unstable/io.element.msc4195/rtc/livekit/delegate_delayed_leave",
delegatedTimings, delegatedTimings,
], ],
[ [
"transport", "transport",
MatrixRTCMode.Compatibility,
"https://jwt.example.org/delegate_delayed_leave", "https://jwt.example.org/delegate_delayed_leave",
delegatedTimings, delegatedTimings,
], ],
])( ])(
"joins session with %s delegation support", "joins session with %s delegation support in %s mode",
async (_serviceName, delegationUrl, delayedLeaveTimings) => { async (_serviceName, matrixRTCMode, delegationUrl, delayedLeaveTimings) => {
const scope = testScope(); const scope = testScope();
const joinMatrixRTC = vi.fn(); const joinMatrixRTC = vi.fn();
const delayId$ = new BehaviorSubject<string | null>(null); const delayId$ = new BehaviorSubject<string | null>(null);
@@ -377,6 +383,7 @@ describe("LocalMembership", () => {
joinMatrixRTC, joinMatrixRTC,
localTransport$: constant(mockTransportLocator), localTransport$: constant(mockTransportLocator),
delayId$, delayId$,
matrixRTCMode,
}); });
localMembership.requestJoinAndPublish(); localMembership.requestJoinAndPublish();
@@ -403,6 +410,7 @@ describe("LocalMembership", () => {
transport: mockTransport, transport: mockTransport,
roomId: "!test-room-id:example.org", roomId: "!test-room-id:example.org",
delayId, delayId,
matrixRTCMode,
logger: expect.anything(), logger: expect.anything(),
}); });
@@ -82,6 +82,7 @@ import {
type ClientDelegationParts, type ClientDelegationParts,
delegateDelayedLeave, delegateDelayedLeave,
type ClientOpenIDParts, type ClientOpenIDParts,
chooseAuthFlow,
type TransportLocator, type TransportLocator,
} from "../../../livekit/auth"; } from "../../../livekit/auth";
@@ -164,6 +165,8 @@ interface Props {
hostBridge: HostBridge; hostBridge: HostBridge;
baseUrl: string; baseUrl: string;
delayId$: Behavior<string | null>; delayId$: Behavior<string | null>;
/** The MatrixRTC mode, which decides the format of our membership event. */
matrixRTCMode: MatrixRTCMode;
logger: Logger; logger: Logger;
} }
@@ -211,6 +214,7 @@ export const createLocalMembership$ = ({
hostBridge, hostBridge,
ownMembershipIdentity, ownMembershipIdentity,
delayId$, delayId$,
matrixRTCMode,
}: Props): { }: Props): {
/** /**
* This request to start audio and video tracks. * This request to start audio and video tracks.
@@ -312,17 +316,17 @@ export const createLocalMembership$ = ({
const joinParams$ = scope.behavior( const joinParams$ = scope.behavior(
localTransport$.pipe( localTransport$.pipe(
switchMap(async ({ transport }) => { switchMap(async ({ transport }) => {
const transportSupportsDelegation = // Delegation goes through whichever service authenticates us as a
"livekit_service_url" in transport && // publisher, so only that service's support counts
(await checkDelegationSupport( const flow = chooseAuthFlow(transport, "publisher", matrixRTCMode);
transport.livekit_service_url + "/delegate_delayed_leave", const delegationSupported =
`transport ${transport.livekit_service_url}`, flow.kind === "openID"
)); ? await checkDelegationSupport(
return { flow.serviceUrl + "/delegate_delayed_leave",
transport, `transport ${flow.serviceUrl}`,
delegationSupported: )
transportSupportsDelegation || (await homeserverSupportsDelegation), : await homeserverSupportsDelegation;
}; return { transport, delegationSupported };
}), }),
), ),
null, null,
@@ -731,6 +735,7 @@ export const createLocalMembership$ = ({
slotId: matrixRTCSession.slotId, slotId: matrixRTCSession.slotId,
roomId, roomId,
delayId, delayId,
matrixRTCMode,
logger, logger,
}); });
logger.info("Delayed leave successfully delegated"); logger.info("Delayed leave successfully delegated");
@@ -42,6 +42,7 @@ import {
} from "./Connection.ts"; } from "./Connection.ts";
import { ObservableScope } from "../../ObservableScope.ts"; import { ObservableScope } from "../../ObservableScope.ts";
import { FailToGetOpenIdToken } from "../../../utils/errors.ts"; import { FailToGetOpenIdToken } from "../../../utils/errors.ts";
import { MatrixRTCMode } from "../../../config/ConfigOptions.ts";
import { testJWTToken } from "../../../utils/test-fixtures.ts"; import { testJWTToken } from "../../../utils/test-fixtures.ts";
import { mockRemoteParticipant, ownMemberMock } from "../../../utils/test.ts"; import { mockRemoteParticipant, ownMemberMock } from "../../../utils/test.ts";
import { import {
@@ -123,6 +124,7 @@ function setupRemoteConnection(): Connection {
client, client,
roomId: ROOM_ID, roomId: ROOM_ID,
slotId: SLOT_ID, slotId: SLOT_ID,
matrixRTCMode: MatrixRTCMode.Matrix_2_0,
role: "subscriber", role: "subscriber",
transport, transport,
serverName: "m.localhost", serverName: "m.localhost",
@@ -172,6 +174,7 @@ describe("Start connection states", () => {
client, client,
roomId: ROOM_ID, roomId: ROOM_ID,
slotId: SLOT_ID, slotId: SLOT_ID,
matrixRTCMode: MatrixRTCMode.Matrix_2_0,
role: "subscriber", role: "subscriber",
transport, transport,
serverName: "m.localhost", serverName: "m.localhost",
@@ -192,6 +195,7 @@ describe("Start connection states", () => {
client, client,
roomId: ROOM_ID, roomId: ROOM_ID,
slotId: SLOT_ID, slotId: SLOT_ID,
matrixRTCMode: MatrixRTCMode.Matrix_2_0,
role: "subscriber", role: "subscriber",
transport, transport,
serverName: "m.localhost", serverName: "m.localhost",
@@ -247,6 +251,7 @@ describe("Start connection states", () => {
client, client,
roomId: ROOM_ID, roomId: ROOM_ID,
slotId: SLOT_ID, slotId: SLOT_ID,
matrixRTCMode: MatrixRTCMode.Matrix_2_0,
role: "subscriber", role: "subscriber",
transport, transport,
serverName: "m.localhost", serverName: "m.localhost",
@@ -311,6 +316,7 @@ describe("Start connection states", () => {
client, client,
roomId: ROOM_ID, roomId: ROOM_ID,
slotId: SLOT_ID, slotId: SLOT_ID,
matrixRTCMode: MatrixRTCMode.Matrix_2_0,
role: "subscriber", role: "subscriber",
transport, transport,
serverName: "m.localhost", serverName: "m.localhost",
@@ -561,6 +567,7 @@ describe("remote track logging", () => {
client, client,
roomId: ROOM_ID, roomId: ROOM_ID,
slotId: SLOT_ID, slotId: SLOT_ID,
matrixRTCMode: MatrixRTCMode.Matrix_2_0,
role: "subscriber", role: "subscriber",
transport, transport,
serverName: "m.localhost", serverName: "m.localhost",
@@ -44,12 +44,15 @@ import {
type ClientOpenIDParts, type ClientOpenIDParts,
type SFUConfig, type SFUConfig,
} from "../../../livekit/auth"; } from "../../../livekit/auth";
import { type MatrixRTCMode } from "../../../config/ConfigOptions.ts";
export interface ConnectionOpts { export interface ConnectionOpts {
/** The identity parts to use on this connection */ /** The identity parts to use on this connection */
ownMembershipIdentity: CallMembershipIdentityParts; ownMembershipIdentity: CallMembershipIdentityParts;
/** Whether we want to publish or only subscribe on this connection. */ /** Whether we want to publish or only subscribe on this connection. */
role: "publisher" | "subscriber"; role: "publisher" | "subscriber";
/** The MatrixRTC mode, which decides the format of our membership event. */
matrixRTCMode: MatrixRTCMode;
/** The media transport to connect to. */ /** The media transport to connect to. */
transport: UnstableLivekitTransport; transport: UnstableLivekitTransport;
/** The name of the homeserver to which the {@link transport} belongs. */ /** The name of the homeserver to which the {@link transport} belongs. */
@@ -138,6 +141,7 @@ export class Connection {
private readonly client: ClientGetTokenParts & ClientOpenIDParts; private readonly client: ClientGetTokenParts & ClientOpenIDParts;
private readonly roomId: string; private readonly roomId: string;
private readonly slotId: string; private readonly slotId: string;
private readonly matrixRTCMode: MatrixRTCMode;
private readonly logger: Logger; private readonly logger: Logger;
private readonly ownMembershipIdentity: CallMembershipIdentityParts; private readonly ownMembershipIdentity: CallMembershipIdentityParts;
/** /**
@@ -151,6 +155,7 @@ export class Connection {
this.ownMembershipIdentity = opts.ownMembershipIdentity; this.ownMembershipIdentity = opts.ownMembershipIdentity;
this.roomId = opts.roomId; this.roomId = opts.roomId;
this.slotId = opts.slotId; this.slotId = opts.slotId;
this.matrixRTCMode = opts.matrixRTCMode;
this.logger = logger.getChild( this.logger = logger.getChild(
`[Connection ${JSON.stringify(opts.transport)}]`, `[Connection ${JSON.stringify(opts.transport)}]`,
); );
@@ -394,6 +399,7 @@ export class Connection {
serverName: this.serverName, serverName: this.serverName,
roomId: this.roomId, roomId: this.roomId,
slotId: this.slotId, slotId: this.slotId,
matrixRTCMode: this.matrixRTCMode,
logger: this.logger, logger: this.logger,
}); });
} }
@@ -39,6 +39,7 @@ import {
type ClientGetTokenParts, type ClientGetTokenParts,
type ClientOpenIDParts, type ClientOpenIDParts,
} from "../../../livekit/auth"; } from "../../../livekit/auth";
import { type MatrixRTCMode } from "../../../config/ConfigOptions.ts";
// TODO evaluate if this should be done like the Publisher Factory // TODO evaluate if this should be done like the Publisher Factory
export interface ConnectionFactory { export interface ConnectionFactory {
@@ -61,6 +62,7 @@ export class ECConnectionFactory implements ConnectionFactory {
* @param client - The OpenID client parts for authentication, needed to get openID and JWT tokens. * @param client - The OpenID client parts for authentication, needed to get openID and JWT tokens.
* @param roomId - The ID of the Matrix room in which the session takes place. * @param roomId - The ID of the Matrix room in which the session takes place.
* @param slotId - The ID of the MatrixRTC slot in which the session takes place. * @param slotId - The ID of the MatrixRTC slot in which the session takes place.
* @param matrixRTCMode - The MatrixRTC mode, which decides the format of our membership event.
* @param devices - Used for video/audio out/in capture options. * @param devices - Used for video/audio out/in capture options.
* @param processorState$ - Effects like background blur (only for publishing connection?) * @param processorState$ - Effects like background blur (only for publishing connection?)
* @param livekitKeyProvider - Optional key provider for end-to-end encryption. * @param livekitKeyProvider - Optional key provider for end-to-end encryption.
@@ -71,6 +73,7 @@ export class ECConnectionFactory implements ConnectionFactory {
private client: ClientGetTokenParts & ClientOpenIDParts, private client: ClientGetTokenParts & ClientOpenIDParts,
private readonly roomId: string, private readonly roomId: string,
private readonly slotId: string, private readonly slotId: string,
private readonly matrixRTCMode: MatrixRTCMode,
private devices: MediaDevices, private devices: MediaDevices,
private processorState$: Behavior<ProcessorState>, private processorState$: Behavior<ProcessorState>,
livekitKeyProvider: BaseKeyProvider | undefined, livekitKeyProvider: BaseKeyProvider | undefined,
@@ -117,6 +120,7 @@ export class ECConnectionFactory implements ConnectionFactory {
{ {
roomId: this.roomId, roomId: this.roomId,
slotId: this.slotId, slotId: this.slotId,
matrixRTCMode: this.matrixRTCMode,
role, role,
transport, transport,
serverName, serverName,
@@ -36,6 +36,7 @@ import {
cameraCodec, cameraCodec,
} from "../../../settings/settings.ts"; } from "../../../settings/settings.ts";
import { testJWTToken } from "../../../utils/test-fixtures.ts"; import { testJWTToken } from "../../../utils/test-fixtures.ts";
import { MatrixRTCMode } from "../../../config/ConfigOptions.ts";
// At the top of your test file, after imports // At the top of your test file, after imports
vi.mock("livekit-client", async (importOriginal) => { vi.mock("livekit-client", async (importOriginal) => {
@@ -84,6 +85,7 @@ describe("ECConnectionFactory - Audio inputs options", () => {
mockClient, mockClient,
"!roomid:example.org", "!roomid:example.org",
"m.call#ROOM", "m.call#ROOM",
MatrixRTCMode.Matrix_2_0,
mockMediaDevices({}), mockMediaDevices({}),
new BehaviorSubject<ProcessorState>({ new BehaviorSubject<ProcessorState>({
supported: true, supported: true,
@@ -129,6 +131,7 @@ describe("ECConnectionFactory - ControlledAudioDevice", () => {
mockClient, mockClient,
"!roomid:example.org", "!roomid:example.org",
"m.call#ROOM", "m.call#ROOM",
MatrixRTCMode.Matrix_2_0,
mockMediaDevices({ mockMediaDevices({
audioOutput: { audioOutput: {
available$: constant(new Map<never, never>()), available$: constant(new Map<never, never>()),
@@ -173,6 +176,7 @@ describe("ECConnectionFactory - Camera quality settings", () => {
mockClient, mockClient,
"!roomid:example.org", "!roomid:example.org",
"m.call#ROOM", "m.call#ROOM",
MatrixRTCMode.Matrix_2_0,
mockMediaDevices({}), mockMediaDevices({}),
new BehaviorSubject<ProcessorState>({ new BehaviorSubject<ProcessorState>({
supported: true, supported: true,
@@ -213,6 +217,7 @@ describe("ECConnectionFactory - Camera quality settings", () => {
mockClient, mockClient,
"!roomid:example.org", "!roomid:example.org",
"m.call#ROOM", "m.call#ROOM",
MatrixRTCMode.Matrix_2_0,
mockMediaDevices({}), mockMediaDevices({}),
new BehaviorSubject<ProcessorState>({ new BehaviorSubject<ProcessorState>({
supported: true, supported: true,
@@ -254,6 +259,7 @@ describe("ECConnectionFactory - Camera quality settings", () => {
mockClient, mockClient,
"!roomid:example.org", "!roomid:example.org",
"m.call#ROOM", "m.call#ROOM",
MatrixRTCMode.Matrix_2_0,
mockMediaDevices({}), mockMediaDevices({}),
new BehaviorSubject<ProcessorState>({ new BehaviorSubject<ProcessorState>({
supported: true, supported: true,
@@ -38,6 +38,7 @@ import { createConnectionMap$ } from "./ConnectionMap.ts";
import { membershipsAndTransports$ } from "../../SessionBehaviors.ts"; import { membershipsAndTransports$ } from "../../SessionBehaviors.ts";
import { localRtcMember, testJWTToken } from "../../../utils/test-fixtures.ts"; import { localRtcMember, testJWTToken } from "../../../utils/test-fixtures.ts";
import { deepCompare } from "matrix-js-sdk/lib/utils"; import { deepCompare } from "matrix-js-sdk/lib/utils";
import { MatrixRTCMode } from "../../../config/ConfigOptions.ts";
// Test the integration of ConnectionMap and MatrixLivekitMembers // Test the integration of ConnectionMap and MatrixLivekitMembers
@@ -75,6 +76,7 @@ beforeEach(() => {
mockClient, mockClient,
"!roomid:example.org", "!roomid:example.org",
"m.call#ROOM", "m.call#ROOM",
MatrixRTCMode.Matrix_2_0,
mockMediaDevices({}), mockMediaDevices({}),
new BehaviorSubject<ProcessorState>({ new BehaviorSubject<ProcessorState>({
supported: true, supported: true,