Skip to content

Commit

Permalink
Only restart track after permission change if not muted (#581)
Browse files Browse the repository at this point in the history
* only restart track after permission change if not muted

* fix implicit restart case

* Create rotten-bottles-work.md

* restart audio track on unmute if readyState is ended
  • Loading branch information
lukasIO authored Feb 16, 2023
1 parent b8fd583 commit 6b35e07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-bottles-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Only restart track after permission change if not muted
10 changes: 7 additions & 3 deletions src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,9 @@ export default class LocalParticipant extends Participant {
// detect granted change after permissions were denied to try and resume then
currentPermissions.onchange = () => {
if (currentPermissions.state !== 'denied') {
track.restartTrack();
if (!track.isMuted) {
track.restartTrack();
}
currentPermissions.onchange = null;
}
};
Expand All @@ -1009,8 +1011,10 @@ export default class LocalParticipant extends Participant {
// permissions query fails for firefox, we continue and try to restart the track
}
}
log.debug('track ended, attempting to use a different device');
await track.restartTrack();
if (!track.isMuted) {
log.debug('track ended, attempting to use a different device');
await track.restartTrack();
}
} catch (e) {
log.warn(`could not restart track, muting instead`);
await track.mute();
Expand Down
6 changes: 5 additions & 1 deletion src/room/track/LocalAudioTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export default class LocalAudioTrack extends LocalTrack {

async unmute(): Promise<LocalAudioTrack> {
await this.muteQueue.run(async () => {
if (this.source === Track.Source.Microphone && this.stopOnMute && !this.isUserProvided) {
if (
this.source === Track.Source.Microphone &&
(this.stopOnMute || this._mediaStreamTrack.readyState === 'ended') &&
!this.isUserProvided
) {
log.debug('reacquiring mic track');
await this.restartTrack();
}
Expand Down

0 comments on commit 6b35e07

Please sign in to comment.