Skip to content

Commit

Permalink
Only perform mute/unmute actions if necessary (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO authored Feb 27, 2024
1 parent 9f72b5e commit 81bde6d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
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) {
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

0 comments on commit 81bde6d

Please sign in to comment.