From 3691e7120d572082af5560aa5539aa02a5eb6906 Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 8 Oct 2025 17:35:53 -0400 Subject: [PATCH] Restore a hidden 'null' state for the local transport/connection --- src/state/CallViewModel.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/state/CallViewModel.ts b/src/state/CallViewModel.ts index 4d83d997..815cbf17 100644 --- a/src/state/CallViewModel.ts +++ b/src/state/CallViewModel.ts @@ -562,16 +562,22 @@ export class CallViewModel extends ViewModel { /** * The transport over which we should be actively publishing our media. + * null when not joined. */ - private readonly localTransport$: Behavior> = + private readonly localTransport$: Behavior | null> = this.scope.behavior( this.transports$.pipe( map((transports) => transports?.local ?? null), - distinctUntilChanged(deepCompare), + distinctUntilChanged | null>(deepCompare), ), ); - private readonly localConnection$: Behavior> = + /** + * The local connection over which we will publish our media. It could + * possibly also have some remote users' media available on it. + * null when not joined. + */ + private readonly localConnection$: Behavior | null> = this.scope.behavior( this.localTransport$.pipe( map( @@ -807,15 +813,14 @@ export class CallViewModel extends ViewModel { // TODO: Move this logic into Connection/PublishConnection if possible this.localConnection$ .pipe( - switchMap((values) => { - if (values?.state !== "ready") return []; - const localConnection = values.value; + switchMap((localConnection) => { + if (localConnection?.state !== "ready") return []; const memberError = (): never => { throw new Error("No room member for call membership"); }; const localParticipant = { id: "local", - participant: localConnection.livekitRoom.localParticipant, + participant: localConnection.value.livekitRoom.localParticipant, member: this.matrixRoom.getMember(this.userId ?? "") ?? memberError(), }; @@ -823,7 +828,7 @@ export class CallViewModel extends ViewModel { return this.remoteConnections$.pipe( switchMap((remoteConnections) => combineLatest( - [localConnection, ...remoteConnections].map((c) => + [localConnection.value, ...remoteConnections].map((c) => c.publishingParticipants$.pipe( map((ps) => { const participants: { @@ -842,7 +847,7 @@ export class CallViewModel extends ViewModel { this.matrixRoom, )?.member ?? memberError(), })); - if (c === localConnection) + if (c === localConnection.value) participants.push(localParticipant); return { @@ -1974,7 +1979,10 @@ export class CallViewModel extends ViewModel { ); c.stop().catch((err) => { // TODO: better error handling - logger.error("MuteState: handler error", err); + logger.error( + `Fail to stop connection to ${c.localTransport.livekit_service_url}`, + err, + ); }); } for (const c of start) {