diff --git a/sdk/src/api.ts b/sdk/src/api.ts index 5d035d0c9..7f9d28ba8 100644 --- a/sdk/src/api.ts +++ b/sdk/src/api.ts @@ -110,10 +110,13 @@ export interface RTCParticipationOptions { timings?: Partial; /** Limits on what is published; LiveKit's defaults otherwise. */ mediaQuality?: MediaQuality; - /** Use this transport instead of asking the homeserver. */ - transportUrl?: string; - /** Use this transport when the homeserver advertises none. */ - fallbackTransportUrl?: string; + /** + * Use this transport instead of asking the homeserver. Any shape the + * backend serves: for LiveKit a `url`, a `livekit_service_url` or both. + */ + transport?: Transport; + /** Use this transport when the homeserver advertises none of the backend's type. */ + fallbackTransport?: Transport; /** * What carries the media. LiveKit, configured from the options above, when * left out; see `createLivekitBackend` for building one with other options. @@ -265,9 +268,6 @@ export interface RTCMember { * against `backendIdentities`, not this. */ rtcBackendIdentity: string; - userId: string; - deviceId: string; - /** The membership's own id; what the Matrix 2.0 identity is derived from. */ /** * Every identity this member may publish under on its transport: the * participant identity the SFU sees, and the sender of its data packets. @@ -277,6 +277,9 @@ export interface RTCMember { * Opaque to a host. */ backendIdentities: readonly string[]; + userId: string; + deviceId: string; + /** The membership's own id; what the Matrix 2.0 identity is derived from. */ memberId: string; /** Which transport this member is on; undefined when the membership has none. */ transport$: Behavior; diff --git a/sdk/src/matrixrtc/LocalTransport.ts b/sdk/src/matrixrtc/LocalTransport.ts index 29c5190a1..6815e85e1 100644 --- a/sdk/src/matrixrtc/LocalTransport.ts +++ b/sdk/src/matrixrtc/LocalTransport.ts @@ -16,28 +16,24 @@ import { TransportAutoDiscovery } from "./TransportAutoDiscovery"; /** * The transport the local member advertises: the one the host names, else the * homeserver's first of the type the backend serves, else the host's fallback. - * The two URL options are LiveKit service URLs, and turning one into a - * membership transport is the one piece of LiveKit knowledge outside the - * backend. It stays here, for hosts that configure a URL rather than a - * transport, and goes once the options take a `Transport`. */ export async function discoverLocalTransport( client: Pick, transportType: string, { - transportUrl, - fallbackTransportUrl, - }: Pick, + transport: override, + fallbackTransport, + }: Pick, logger: Logger, ): Promise { - const transport = transportUrl - ? { type: "livekit", livekit_service_url: transportUrl } - : await new TransportAutoDiscovery({ - client, - transportType, - fallbackTransportUrl, - logger, - }).discoverPreferredTransport(); + const transport = + override ?? + (await new TransportAutoDiscovery({ + client, + transportType, + fallbackTransport, + logger, + }).discoverPreferredTransport()); if (transport === null) throw new MatrixRTCTransportMissingError(client.getDomain() ?? ""); return transport; diff --git a/sdk/src/matrixrtc/TransportAutoDiscovery.test.ts b/sdk/src/matrixrtc/TransportAutoDiscovery.test.ts index c774a5706..0f972b82d 100644 --- a/sdk/src/matrixrtc/TransportAutoDiscovery.test.ts +++ b/sdk/src/matrixrtc/TransportAutoDiscovery.test.ts @@ -15,10 +15,7 @@ import { } from "vitest"; import { MatrixError } from "matrix-js-sdk"; import { logger as rootLogger } from "matrix-js-sdk/lib/logger"; -import { - type LivekitTransport, - type Transport, -} from "matrix-js-sdk/lib/matrixrtc"; +import { type Transport } from "matrix-js-sdk/lib/matrixrtc"; import { TransportAutoDiscovery, @@ -27,12 +24,12 @@ import { type DiscoveryClient = TransportAutoDiscoveryProps["client"]; -const backendTransport: LivekitTransport = { +const backendTransport: Transport = { type: "livekit", livekit_service_url: "https://backend.example.org", }; -const configTransport: LivekitTransport = { +const configTransport: Transport = { type: "livekit", livekit_service_url: "https://config.example.org", }; @@ -65,7 +62,7 @@ describe("TransportAutoDiscovery", () => { const discovery = new TransportAutoDiscovery({ client, transportType: "livekit", - fallbackTransportUrl: configTransport.livekit_service_url, + fallbackTransport: configTransport, logger: rootLogger, }); @@ -96,7 +93,7 @@ describe("TransportAutoDiscovery", () => { const discovery = new TransportAutoDiscovery({ client, transportType: "livekit", - fallbackTransportUrl: "https://config.example.org", + fallbackTransport: configTransport, logger: rootLogger, }); @@ -120,7 +117,7 @@ describe("TransportAutoDiscovery", () => { const discovery = new TransportAutoDiscovery({ client, transportType: "livekit", - fallbackTransportUrl: configTransport.livekit_service_url, + fallbackTransport: configTransport, logger: rootLogger, }); @@ -137,7 +134,7 @@ describe("TransportAutoDiscovery", () => { const discovery = new TransportAutoDiscovery({ client, transportType: "livekit", - fallbackTransportUrl: undefined, + fallbackTransport: undefined, logger: rootLogger, }); diff --git a/sdk/src/matrixrtc/TransportAutoDiscovery.ts b/sdk/src/matrixrtc/TransportAutoDiscovery.ts index b278fcfd7..9fa81eac6 100644 --- a/sdk/src/matrixrtc/TransportAutoDiscovery.ts +++ b/sdk/src/matrixrtc/TransportAutoDiscovery.ts @@ -19,26 +19,26 @@ export interface TransportAutoDiscoveryProps { client: TransportDiscoveryClient; /** The transport type the media backend serves. */ transportType: string; - /** A LiveKit service URL to use when the homeserver advertises none. */ - fallbackTransportUrl?: string; + /** A transport to use when the homeserver advertises none of the type. */ + fallbackTransport?: Transport; logger: Logger; } export class TransportAutoDiscovery { private readonly client: TransportDiscoveryClient; private readonly transportType: string; - private readonly fallbackTransportUrl: string | undefined; + private readonly fallbackTransport: Transport | undefined; private readonly logger: Logger; public constructor({ client, transportType, - fallbackTransportUrl, + fallbackTransport, logger, }: TransportAutoDiscoveryProps) { this.client = client; this.transportType = transportType; - this.fallbackTransportUrl = fallbackTransportUrl; + this.fallbackTransport = fallbackTransport; this.logger = logger.getChild("[TransportAutoDiscovery]"); } @@ -46,15 +46,18 @@ export class TransportAutoDiscovery { // 1) backend transports const backendTransport = await this.tryBackendTransports(); if (backendTransport) { - this.logger.info("Found backend transport:", backendTransport); + this.logger.info( + `Found backend transport: ${JSON.stringify(backendTransport)}`, + ); return backendTransport; } - // 2) app config URL - const configTransport = this.tryConfigTransport(); - if (configTransport) { - this.logger.info("Found app config transport:", configTransport); - return configTransport; + // 2) the host's fallback + if (this.fallbackTransport) { + this.logger.info( + `Found fallback transport: ${JSON.stringify(this.fallbackTransport)}`, + ); + return this.fallbackTransport; } return null; @@ -89,15 +92,4 @@ export class TransportAutoDiscovery { } return null; } - - private tryConfigTransport(): Transport | null { - const url = this.fallbackTransportUrl; - if (url) { - return { - type: "livekit", - livekit_service_url: url, - }; - } - return null; - } }