Replace track to switch camera causes audio input to stop working or echo

This is the full code to switch camera, if i don’t replace the audio track it just goes dead with no mic input, but with it i get the echo, it doesn’t make sense.

this.OV.getDevices().then((devices)=> {

        let videoDevices = devices.filter(device => device.kind === 'videoinput' && device.label !== 'Snap Camera');
        let audioDevices = devices.filter(device => device.kind === 'audioinput');

        let frontDeviceId = videoDevices[0].deviceId;
        let backDeviceId = videoDevices[1].deviceId;


        this.OV.getUserMedia(<any>{
          videoSource: this.OVCurrentCamera === 'front' ? backDeviceId : frontDeviceId,
          audioSource: typeof audioDevices[0] !== 'undefined' ? audioDevices[0].deviceId : true
        }).then((mediaStream) =>  {

          let videoTrack = mediaStream.getVideoTracks()[0];
          let audioTrack = mediaStream.getAudioTracks()[0];

          this.OVPublisher.replaceTrack(videoTrack).then(() => {
            this.OVCurrentCamera = this.OVCurrentCamera === 'front' ? 'back' : 'front';
          }).catch(() => {
            this.toast.error('There was a problem switching cameras.');
          })

          this.OVPublisher.replaceTrack(audioTrack).then(() => {
            this.OVPublisher.videoReference.setAttribute('muted',true);
            this.OVPublisher.videoReference.muted = true;

          }).catch(()=>{
            this.toast.error('There was a problem activating your microphone.');
          })
        }).catch(() => {
          this.toast.error('Could not access devices');
        })

      })