diff --git a/packages/client/src/rtc/Publisher.ts b/packages/client/src/rtc/Publisher.ts index ce79f7e964..735ed7c6ac 100644 --- a/packages/client/src/rtc/Publisher.ts +++ b/packages/client/src/rtc/Publisher.ts @@ -218,12 +218,7 @@ export class Publisher { 'info', `Track ${TrackType[trackType]} has ended, notifying the SFU`, ); - await this.notifyTrackMuteStateChanged( - mediaStream, - track, - trackType, - true, - ); + await this.notifyTrackMuteStateChanged(mediaStream, trackType, true); // clean-up, this event listener needs to run only once. track.removeEventListener('ended', handleTrackEnded); }; @@ -295,12 +290,7 @@ export class Publisher { await transceiver.sender.replaceTrack(track); } - await this.notifyTrackMuteStateChanged( - mediaStream, - track, - trackType, - false, - ); + await this.notifyTrackMuteStateChanged(mediaStream, trackType, false); }; /** @@ -325,12 +315,7 @@ export class Publisher { : (transceiver.sender.track.enabled = false); // We don't need to notify SFU if unpublishing in response to remote soft mute if (this.state.localParticipant?.publishedTracks.includes(trackType)) { - await this.notifyTrackMuteStateChanged( - undefined, - transceiver.sender.track, - trackType, - true, - ); + await this.notifyTrackMuteStateChanged(undefined, trackType, true); } } }; @@ -369,7 +354,6 @@ export class Publisher { private notifyTrackMuteStateChanged = async ( mediaStream: MediaStream | undefined, - track: MediaStreamTrack, trackType: TrackType, isMuted: boolean, ) => { diff --git a/packages/client/src/store/stateStore.ts b/packages/client/src/store/stateStore.ts index 290e286905..0af577ac33 100644 --- a/packages/client/src/store/stateStore.ts +++ b/packages/client/src/store/stateStore.ts @@ -2,7 +2,8 @@ import { BehaviorSubject, Observable } from 'rxjs'; import type { Patch } from './rxUtils'; import * as RxUtils from './rxUtils'; import { Call } from '../Call'; -import type { OwnUserResponse } from '../coordinator/connection/types'; +import { CallingState } from './CallState'; +import type { OwnUserResponse } from '../gen/coordinator'; import { getLogger } from '../logger'; export class StreamVideoWriteableStateStore { @@ -22,12 +23,14 @@ export class StreamVideoWriteableStateStore { this.connectedUserSubject.subscribe(async (user) => { // leave all calls when the user disconnects. if (!user) { + const logger = getLogger(['client-state']); for (const call of this.calls) { - getLogger(['client-state'])( - 'info', - `User disconnected, leaving call: ${call.cid}`, - ); - await call.leave(); + if (call.state.callingState === CallingState.LEFT) continue; + + logger('info', `User disconnected, leaving call: ${call.cid}`); + await call.leave().catch((err) => { + logger('error', `Error leaving call: ${call.cid}`, err); + }); } } });