Skip to content

Commit

Permalink
fix: audio issue on role change
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 authored Aug 25, 2023
1 parent a545bf0 commit 298fc7a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 298fc7a

Please sign in to comment.