Skip to content

Commit

Permalink
fix: consider prior track publishing state before applying soft mutes (
Browse files Browse the repository at this point in the history
…#1070)

related: #988
  • Loading branch information
oliverlaz authored Sep 11, 2023
1 parent ade3d1e commit f542409
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 31 deletions.
64 changes: 34 additions & 30 deletions packages/client/src/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,36 +278,40 @@ export class Call {
this.camera = new CameraManager(this);
this.microphone = new MicrophoneManager(this);

this.state.localParticipant$.subscribe(async (p) => {
// Mute via device manager
// If integrator doesn't use device manager, we mute using stopPublish
if (
!p?.publishedTracks.includes(TrackType.VIDEO) &&
this.publisher?.isPublishing(TrackType.VIDEO)
) {
this.logger(
'info',
`Local participant's video track is muted remotely`,
);
await this.camera.disable();
if (this.publisher.isPublishing(TrackType.VIDEO)) {
this.stopPublish(TrackType.VIDEO);
}
}
if (
!p?.publishedTracks.includes(TrackType.AUDIO) &&
this.publisher?.isPublishing(TrackType.AUDIO)
) {
this.logger(
'info',
`Local participant's audio track is muted remotely`,
);
await this.microphone.disable();
if (this.publisher.isPublishing(TrackType.AUDIO)) {
this.stopPublish(TrackType.AUDIO);
}
}
});
// FIXME OL: disable soft-mutes as they are not working properly
// this.state.localParticipant$.subscribe(async (p) => {
// if (!this.publisher) return;
// // Mute via device manager
// // If integrator doesn't use device manager, we mute using stopPublish
// if (
// this.publisher.hasEverPublished(TrackType.VIDEO) &&
// this.publisher.isPublishing(TrackType.VIDEO) &&
// !p?.publishedTracks.includes(TrackType.VIDEO)
// ) {
// this.logger(
// 'info',
// `Local participant's video track is muted remotely`,
// );
// await this.camera.disable();
// if (this.publisher.isPublishing(TrackType.VIDEO)) {
// await this.stopPublish(TrackType.VIDEO);
// }
// }
// if (
// this.publisher.hasEverPublished(TrackType.AUDIO) &&
// this.publisher.isPublishing(TrackType.AUDIO) &&
// !p?.publishedTracks.includes(TrackType.AUDIO)
// ) {
// this.logger(
// 'info',
// `Local participant's audio track is muted remotely`,
// );
// await this.microphone.disable();
// if (this.publisher.isPublishing(TrackType.AUDIO)) {
// await this.stopPublish(TrackType.AUDIO);
// }
// }
// });
this.speaker = new SpeakerManager();
}

Expand Down
21 changes: 21 additions & 0 deletions packages/client/src/rtc/Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ export class Publisher {
[TrackType.UNSPECIFIED]: undefined,
};

/**
* A map keeping track of track types that were published to the SFU.
* This map shouldn't be cleared when unpublishing a track, as it is used
* to determine whether a track was published before.
*
* @private
*/
private readonly trackTypePublishHistory = new Map<TrackType, boolean>();

private readonly isDtxEnabled: boolean;
private readonly isRedEnabled: boolean;
private readonly preferredVideoCodec?: string;
Expand Down Expand Up @@ -269,6 +278,7 @@ export class Publisher {
logger('debug', `Added ${TrackType[trackType]} transceiver`);
this.transceiverInitOrder.push(trackType);
this.transceiverRegistry[trackType] = transceiver;
this.trackTypePublishHistory.set(trackType, true);

if ('setCodecPreferences' in transceiver && codecPreferences) {
logger(
Expand Down Expand Up @@ -352,6 +362,17 @@ export class Publisher {
return false;
};

/**
* Returns true if the given track type was ever published to the SFU.
* Contrary to `isPublishing`, this method returns true if a certain
* track type was published before, even if it is currently unpublished.
*
* @param trackType the track type to check.
*/
hasEverPublished = (trackType: TrackType): boolean => {
return this.trackTypePublishHistory.get(trackType) ?? false;
};

/**
* Returns true if the given track type is currently live
*
Expand Down
2 changes: 1 addition & 1 deletion sample-apps/react/react-video-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const Init = () => {
token,
tokenProvider,
options: {
logLevel: log_level || 'warn',
logLevel: log_level || 'info',
},
});
setClient(_client);
Expand Down

0 comments on commit f542409

Please sign in to comment.