diff --git a/src/state/CallViewModel/CallViewModel.ts b/src/state/CallViewModel/CallViewModel.ts index bf3e9521..ab45b07c 100644 --- a/src/state/CallViewModel/CallViewModel.ts +++ b/src/state/CallViewModel/CallViewModel.ts @@ -527,7 +527,10 @@ export function createCallViewModel$( connectOptions$.value, ); }, - createPublisherFactory: (connection: Connection) => { + createPublisherFactory: ( + scope: ObservableScope, + connection: Connection, + ) => { return new Publisher( scope, connection, diff --git a/src/state/CallViewModel/localMember/LocalMember.ts b/src/state/CallViewModel/localMember/LocalMember.ts index 4749e942..6298979f 100644 --- a/src/state/CallViewModel/localMember/LocalMember.ts +++ b/src/state/CallViewModel/localMember/LocalMember.ts @@ -40,7 +40,7 @@ import { type CallMembershipIdentityParts } from "matrix-js-sdk/lib/matrixrtc/En import { type Behavior } from "../../Behavior.ts"; import { type IConnectionManager } from "../remoteMembers/ConnectionManager.ts"; -import { type ObservableScope } from "../../ObservableScope.ts"; +import { ObservableScope } from "../../ObservableScope.ts"; import { type Publisher } from "./Publisher.ts"; import { type MuteStates } from "../../MuteStates.ts"; import { @@ -124,7 +124,10 @@ interface Props { scope: ObservableScope; muteStates: MuteStates; connectionManager: IConnectionManager; - createPublisherFactory: (connection: Connection) => Publisher; + createPublisherFactory: ( + scope: ObservableScope, + connection: Connection, + ) => Publisher; joinMatrixRTC: (transport: LivekitTransport) => void; homeserverConnected: HomeserverConnected; localTransport$: Behavior; @@ -310,13 +313,18 @@ export const createLocalMembership$ = ({ // - destruct all current streams // - overwrite current publisher scope.reconcile(localConnection$, async (connection) => { + logger.info( + "reconcile based on new localConnection:", + connection?.transport.livekit_service_url, + ); if (connection !== null) { - const publisher = createPublisherFactory(connection); + const scope = new ObservableScope(); + const publisher = createPublisherFactory(scope, connection); publisher$.next(publisher); // Clean-up callback + return Promise.resolve(async (): Promise => { - await publisher.stopPublishing(); - await publisher.stopTracks(); + scope.end(); }); } });