Skip to content

Commit

Permalink
Don't reacquire muted tracks (#385)
Browse files Browse the repository at this point in the history
* always apply mute state to streamtrack

* changeset

* set isMuted after

* Don't reacquire muted tracks

* update changeset
  • Loading branch information
lukasIO authored Aug 9, 2022
1 parent 961fcc4 commit c11d99d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-timers-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Don't reacquire muted tracks when app visibility changes
15 changes: 3 additions & 12 deletions src/room/track/LocalTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export default class LocalTrack extends Track {

protected constraints: MediaTrackConstraints;

protected wasMuted: boolean;

protected reacquireTrack: boolean;

protected providedByUser: boolean;
Expand All @@ -34,7 +32,6 @@ export default class LocalTrack extends Track {
this._mediaStreamTrack.addEventListener('ended', this.handleEnded);
this.constraints = constraints ?? mediaTrack.getConstraints();
this.reacquireTrack = false;
this.wasMuted = false;
this.providedByUser = userProvidedTrack;
this.muteQueue = new Queue();
}
Expand Down Expand Up @@ -181,7 +178,8 @@ export default class LocalTrack extends Track {

protected setTrackMuted(muted: boolean) {
log.debug(`setting ${this.kind} track ${muted ? 'muted' : 'unmuted'}`);
if (this.isMuted === muted) {

if (this.isMuted === muted && this._mediaStreamTrack.enabled !== muted) {
return;
}

Expand All @@ -204,17 +202,10 @@ export default class LocalTrack extends Track {
if (!isMobile()) return;
log.debug(`visibility changed, is in Background: ${this.isInBackground}`);

if (!this.isInBackground && this.needsReAcquisition && !this.isUserProvided) {
if (!this.isInBackground && this.needsReAcquisition && !this.isUserProvided && !this.isMuted) {
log.debug(`track needs to be reaquired, restarting ${this.source}`);
await this.restart();
this.reacquireTrack = false;
// Restore muted state if had to be restarted
this.setTrackMuted(this.wasMuted);
}

// store muted state each time app goes to background
if (this.isInBackground) {
this.wasMuted = this.isMuted;
}
}

Expand Down

0 comments on commit c11d99d

Please sign in to comment.