Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only perform mute/unmute actions if necessary #1048

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/unlucky-planets-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Only perform mute/unmute actions if necessary
10 changes: 10 additions & 0 deletions src/room/track/LocalAudioTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export default class LocalAudioTrack extends LocalTrack<Track.Kind.Audio> {
async mute(): Promise<typeof this> {
const unlock = await this.muteLock.lock();
try {
if (this.isMuted) {
this.log.debug('Track already muted', this.logContext);
return this;
}

// disabled special handling as it will cause BT headsets to switch communication modes
if (this.source === Track.Source.Microphone && this.stopOnMute && !this.isUserProvided) {
this.log.debug('stopping mic track', this.logContext);
Expand All @@ -67,6 +72,11 @@ export default class LocalAudioTrack extends LocalTrack<Track.Kind.Audio> {
async unmute(): Promise<typeof this> {
const unlock = await this.muteLock.lock();
try {
if (!this.isMuted) {
this.log.debug('Track already unmuted', this.logContext);
return this;
}

const deviceHasChanged =
this._constraints.deviceId &&
this._mediaStreamTrack.getSettings().deviceId !==
Expand Down
10 changes: 10 additions & 0 deletions src/room/track/LocalVideoTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export default class LocalVideoTrack extends LocalTrack<Track.Kind.Video> {
async mute(): Promise<typeof this> {
const unlock = await this.muteLock.lock();
try {
if (this.isMuted) {
this.log.debug('Track already muted', this.logContext);
return this;
}

if (this.source === Track.Source.Camera && !this.isUserProvided) {
this.log.debug('stopping camera track', this.logContext);
// also stop the track, so that camera indicator is turned off
Expand All @@ -133,6 +138,11 @@ export default class LocalVideoTrack extends LocalTrack<Track.Kind.Video> {
async unmute(): Promise<typeof this> {
const unlock = await this.muteLock.lock();
try {
if (!this.isMuted) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could add a check here for mediaStreamTrack.readyState === 'live' just to make sure?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine to leave it out. If it not live, it is ended and the following action is probably not user perceptible any way. Want to avoid checks which probably increases the surface area of browser weirdness affecting functionality in unexpected ways.

this.log.debug('Track already unmuted', this.logContext);
return this;
}

if (this.source === Track.Source.Camera && !this.isUserProvided) {
this.log.debug('reacquiring camera track', this.logContext);
await this.restartTrack();
Expand Down
Loading