From 298fc7acc686d981aa8e176feadb297b2f622902 Mon Sep 17 00:00:00 2001 From: Ravi theja Date: Fri, 25 Aug 2023 11:52:59 +0530 Subject: [PATCH] fix: audio issue on role change --- .../managers/TrackManager.ts | 17 ++++++++++++++--- .../managers/onDemandTrackManager.ts | 5 +++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/hms-video-web/src/notification-manager/managers/TrackManager.ts b/packages/hms-video-web/src/notification-manager/managers/TrackManager.ts index 7d42508f11..4043d14fd4 100644 --- a/packages/hms-video-web/src/notification-manager/managers/TrackManager.ts +++ b/packages/hms-video-web/src/notification-manager/managers/TrackManager.ts @@ -85,7 +85,7 @@ export class TrackManager { /** * Sets the track of corresponding peer to null and returns the peer */ - handleTrackRemove(track: HMSRemoteTrack) { + handleTrackRemove(track: HMSRemoteTrack, remove = true) { HMSLogger.d(this.TAG, `ONTRACKREMOVE`, `${track}`); const trackStateEntry = this.store.getTrackState(track.trackId); @@ -100,8 +100,19 @@ export class TrackManager { return; } - // emit this event here as peer will already be removed(if left the room) by the time this event is received - track.type === HMSTrackType.AUDIO && this.eventBus.audioTrackRemoved.publish(track as HMSRemoteAudioTrack); + // remove tracks only when onDemandTracks flag is false + if (remove) { + this.store.removeTrack(track); + const hmsPeer = this.store.getPeerById(trackStateEntry.peerId); + if (!hmsPeer) { + return; + } + this.removePeerTracks(hmsPeer, track); + this.listener?.onTrackUpdate(HMSTrackUpdate.TRACK_REMOVED, track, hmsPeer); + + // emit this event here as peer will already be removed(if left the room) by the time this event is received + track.type === HMSTrackType.AUDIO && this.eventBus.audioTrackRemoved.publish(track as HMSRemoteAudioTrack); + } } handleTrackLayerUpdate = (params: OnTrackLayerUpdateNotification) => { diff --git a/packages/hms-video-web/src/notification-manager/managers/onDemandTrackManager.ts b/packages/hms-video-web/src/notification-manager/managers/onDemandTrackManager.ts index cfcd2c64e3..ce6c423c6a 100644 --- a/packages/hms-video-web/src/notification-manager/managers/onDemandTrackManager.ts +++ b/packages/hms-video-web/src/notification-manager/managers/onDemandTrackManager.ts @@ -27,8 +27,9 @@ export class OnDemandTrackManager extends TrackManager { } handleTrackRemove(track: HMSRemoteTrack) { - super.handleTrackRemove(track); - if (track.type === 'video' && track.source === 'regular') { + const isRegularVideo = track.type === 'video' && track.source === 'regular'; + super.handleTrackRemove(track, !isRegularVideo); + if (isRegularVideo) { this.processTrackInfo( { track_id: track.trackId,