File tree Expand file tree Collapse file tree 3 files changed +13
-7
lines changed
Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " livekit-client " : patch
3+ ---
4+
5+ Fix unnecessary track restarts on unmute when using ideal device constraints
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { TrackEvent } from '../events';
33import { computeBitrate , monitorFrequency } from '../stats' ;
44import type { AudioSenderStats } from '../stats' ;
55import type { LoggerOptions } from '../types' ;
6- import { isReactNative , isWeb , unwrapConstraint } from '../utils' ;
6+ import { isReactNative , isWeb } from '../utils' ;
77import LocalTrack from './LocalTrack' ;
88import { Track } from './Track' ;
99import type { AudioCaptureOptions } from './options' ;
@@ -74,14 +74,11 @@ export default class LocalAudioTrack extends LocalTrack<Track.Kind.Audio> {
7474 return this ;
7575 }
7676
77- const deviceHasChanged =
78- this . _constraints . deviceId &&
79- this . _mediaStreamTrack . getSettings ( ) . deviceId !==
80- unwrapConstraint ( this . _constraints . deviceId ) ;
81-
8277 if (
8378 this . source === Track . Source . Microphone &&
84- ( this . stopOnMute || this . _mediaStreamTrack . readyState === 'ended' || deviceHasChanged ) &&
79+ ( this . stopOnMute ||
80+ this . _mediaStreamTrack . readyState === 'ended' ||
81+ this . pendingDeviceChange ) &&
8582 ! this . isUserProvided
8683 ) {
8784 this . log . debug ( 'reacquiring mic track' , this . logContext ) ;
Original file line number Diff line number Diff line change @@ -65,6 +65,8 @@ export default abstract class LocalTrack<
6565
6666 protected trackChangeLock : Mutex ;
6767
68+ protected pendingDeviceChange : boolean = false ;
69+
6870 /**
6971 *
7072 * @param mediaTrack
@@ -246,6 +248,7 @@ export default abstract class LocalTrack<
246248 // when track is muted, underlying media stream track is stopped and
247249 // will be restarted later
248250 if ( this . isMuted ) {
251+ this . pendingDeviceChange = true ;
249252 return true ;
250253 }
251254
@@ -365,6 +368,7 @@ export default abstract class LocalTrack<
365368
366369 await this . setMediaStreamTrack ( newTrack ) ;
367370 this . _constraints = constraints ;
371+ this . pendingDeviceChange = false ;
368372 this . emit ( TrackEvent . Restarted , this ) ;
369373 if ( this . manuallyStopped ) {
370374 this . log . warn (
You can’t perform that action at this time.
0 commit comments