@@ -232,6 +232,7 @@ export default abstract class LocalTrack<
232232 ) {
233233 return true ;
234234 }
235+
235236 this . _constraints . deviceId = deviceId ;
236237
237238 // when track is muted, underlying media stream track is stopped and
@@ -313,6 +314,7 @@ export default abstract class LocalTrack<
313314 if ( ! constraints ) {
314315 constraints = this . _constraints ;
315316 }
317+ const { deviceId, ...otherConstraints } = this . _constraints ;
316318 this . log . debug ( 'restarting track with constraints' , { ...this . logContext , constraints } ) ;
317319
318320 const streamConstraints : MediaStreamConstraints = {
@@ -321,9 +323,9 @@ export default abstract class LocalTrack<
321323 } ;
322324
323325 if ( this . kind === Track . Kind . Video ) {
324- streamConstraints . video = constraints ;
326+ streamConstraints . video = deviceId ? { deviceId } : true ;
325327 } else {
326- streamConstraints . audio = constraints ;
328+ streamConstraints . audio = deviceId ? { deviceId } : true ;
327329 }
328330
329331 // these steps are duplicated from setMediaStreamTrack because we must stop
@@ -340,6 +342,7 @@ export default abstract class LocalTrack<
340342 // create new track and attach
341343 const mediaStream = await navigator . mediaDevices . getUserMedia ( streamConstraints ) ;
342344 const newTrack = mediaStream . getTracks ( ) [ 0 ] ;
345+ await newTrack . applyConstraints ( otherConstraints ) ;
343346 newTrack . addEventListener ( 'ended' , this . handleEnded ) ;
344347 this . log . debug ( 're-acquired MediaStreamTrack' , this . logContext ) ;
345348
0 commit comments