Stick to the term 'transport' rather than 'focus'

This commit is contained in:
Robin
2025-10-14 14:38:37 -04:00
parent ea17ed7253
commit 2dc6134606
2 changed files with 29 additions and 28 deletions

View File

@@ -397,7 +397,7 @@ export class CallViewModel extends ViewModel {
switchMap((c) => switchMap((c) =>
c?.state === "ready" c?.state === "ready"
? // TODO mapping to ConnectionState for compatibility, but we should use the full state? ? // TODO mapping to ConnectionState for compatibility, but we should use the full state?
c.value.focusConnectionState$.pipe( c.value.transportState$.pipe(
map((s) => { map((s) => {
if (s.state === "ConnectedToLkRoom") return s.connectionState; if (s.state === "ConnectedToLkRoom") return s.connectionState;
return ConnectionState.Disconnected; return ConnectionState.Disconnected;

View File

@@ -37,13 +37,13 @@ import {
} from "../utils/errors.ts"; } from "../utils/errors.ts";
export interface ConnectionOpts { export interface ConnectionOpts {
/** The focus server to connect to. */ /** The media transport to connect to. */
transport: LivekitTransport; transport: LivekitTransport;
/** The Matrix client to use for OpenID and SFU config requests. */ /** The Matrix client to use for OpenID and SFU config requests. */
client: OpenIDClientParts; client: OpenIDClientParts;
/** The observable scope to use for this connection. */ /** The observable scope to use for this connection. */
scope: ObservableScope; scope: ObservableScope;
/** An observable of the current RTC call memberships and their associated focus. */ /** An observable of the current RTC call memberships and their associated transports. */
remoteTransports$: Behavior< remoteTransports$: Behavior<
{ membership: CallMembership; transport: LivekitTransport }[] { membership: CallMembership; transport: LivekitTransport }[]
>; >;
@@ -52,18 +52,18 @@ export interface ConnectionOpts {
livekitRoomFactory?: (options?: RoomOptions) => LivekitRoom; livekitRoomFactory?: (options?: RoomOptions) => LivekitRoom;
} }
export type FocusConnectionState = export type TransportState =
| { state: "Initialized" } | { state: "Initialized" }
| { state: "FetchingConfig"; focus: LivekitTransport } | { state: "FetchingConfig"; transport: LivekitTransport }
| { state: "ConnectingToLkRoom"; focus: LivekitTransport } | { state: "ConnectingToLkRoom"; transport: LivekitTransport }
| { state: "PublishingTracks"; focus: LivekitTransport } | { state: "PublishingTracks"; transport: LivekitTransport }
| { state: "FailedToStart"; error: Error; focus: LivekitTransport } | { state: "FailedToStart"; error: Error; transport: LivekitTransport }
| { | {
state: "ConnectedToLkRoom"; state: "ConnectedToLkRoom";
connectionState: ConnectionState; connectionState: ConnectionState;
focus: LivekitTransport; transport: LivekitTransport;
} }
| { state: "Stopped"; focus: LivekitTransport }; | { state: "Stopped"; transport: LivekitTransport };
/** /**
* Represents participant publishing or expected to publish on the connection. * Represents participant publishing or expected to publish on the connection.
@@ -87,14 +87,15 @@ export type PublishingParticipant = {
*/ */
export class Connection { export class Connection {
// Private Behavior // Private Behavior
private readonly _focusConnectionState$ = private readonly _transportState$ = new BehaviorSubject<TransportState>({
new BehaviorSubject<FocusConnectionState>({ state: "Initialized" }); state: "Initialized",
});
/** /**
* The current state of the connection to the focus server. * The current state of the connection to the media transport.
*/ */
public readonly focusConnectionState$: Behavior<FocusConnectionState> = public readonly transportState$: Behavior<TransportState> =
this._focusConnectionState$; this._transportState$;
/** /**
* Whether the connection has been stopped. * Whether the connection has been stopped.
@@ -116,17 +117,17 @@ export class Connection {
public async start(): Promise<void> { public async start(): Promise<void> {
this.stopped = false; this.stopped = false;
try { try {
this._focusConnectionState$.next({ this._transportState$.next({
state: "FetchingConfig", state: "FetchingConfig",
focus: this.transport, transport: this.transport,
}); });
const { url, jwt } = await this.getSFUConfigWithOpenID(); const { url, jwt } = await this.getSFUConfigWithOpenID();
// If we were stopped while fetching the config, don't proceed to connect // If we were stopped while fetching the config, don't proceed to connect
if (this.stopped) return; if (this.stopped) return;
this._focusConnectionState$.next({ this._transportState$.next({
state: "ConnectingToLkRoom", state: "ConnectingToLkRoom",
focus: this.transport, transport: this.transport,
}); });
try { try {
await this.livekitRoom.connect(url, jwt); await this.livekitRoom.connect(url, jwt);
@@ -155,16 +156,16 @@ export class Connection {
// If we were stopped while connecting, don't proceed to update state. // If we were stopped while connecting, don't proceed to update state.
if (this.stopped) return; if (this.stopped) return;
this._focusConnectionState$.next({ this._transportState$.next({
state: "ConnectedToLkRoom", state: "ConnectedToLkRoom",
focus: this.transport, transport: this.transport,
connectionState: this.livekitRoom.state, connectionState: this.livekitRoom.state,
}); });
} catch (error) { } catch (error) {
this._focusConnectionState$.next({ this._transportState$.next({
state: "FailedToStart", state: "FailedToStart",
error: error instanceof Error ? error : new Error(`${error}`), error: error instanceof Error ? error : new Error(`${error}`),
focus: this.transport, transport: this.transport,
}); });
throw error; throw error;
} }
@@ -186,9 +187,9 @@ export class Connection {
public async stop(): Promise<void> { public async stop(): Promise<void> {
if (this.stopped) return; if (this.stopped) return;
await this.livekitRoom.disconnect(); await this.livekitRoom.disconnect();
this._focusConnectionState$.next({ this._transportState$.next({
state: "Stopped", state: "Stopped",
focus: this.transport, transport: this.transport,
}); });
this.stopped = true; this.stopped = true;
} }
@@ -252,13 +253,13 @@ export class Connection {
scope scope
.behavior<ConnectionState>(connectionStateObserver(this.livekitRoom)) .behavior<ConnectionState>(connectionStateObserver(this.livekitRoom))
.subscribe((connectionState) => { .subscribe((connectionState) => {
const current = this._focusConnectionState$.value; const current = this._transportState$.value;
// Only update the state if we are already connected to the LiveKit room. // Only update the state if we are already connected to the LiveKit room.
if (current.state === "ConnectedToLkRoom") { if (current.state === "ConnectedToLkRoom") {
this._focusConnectionState$.next({ this._transportState$.next({
state: "ConnectedToLkRoom", state: "ConnectedToLkRoom",
connectionState, connectionState,
focus: current.focus, transport: current.transport,
}); });
} }
}); });