Switch camera & renegotiate

< HelloWorld / >

I have been trying for a few days to understand how to renegotiate the video to be able to switch the camera. I understood that the lastest methods (eg. getSenders) are not yet implemented in the library.

How can this be done?

< Thanks />

As document points out:

MediaStreamTrack.prototype._switchCamera()
This function allows to switch the front / back cameras in a video track on the fly, without the need for adding / removing tracks or renegotiating.

BTW if you want to add/change the streams you are sending you could see at this example. Basically you need to create a new offer with the content you want to send.

function upgrade() {
  upgradeButton.disabled = true;
  navigator.mediaDevices
      .getUserMedia({video: true})
      .then(stream => {
        const videoTracks = stream.getVideoTracks();
        if (videoTracks.length > 0) {
          console.log(`Using video device: ${videoTracks[0].label}`);
        }
        localStream.addTrack(videoTracks[0]);
        localVideo.srcObject = null;
        localVideo.srcObject = localStream;
        pc1.addTrack(videoTracks[0], localStream);
        return pc1.createOffer();
      })
      .then(offer => pc1.setLocalDescription(offer))
      .then(() => pc2.setRemoteDescription(pc1.localDescription))
      .then(() => pc2.createAnswer())
      .then(answer => pc2.setLocalDescription(answer))
      .then(() => pc1.setRemoteDescription(pc2.localDescription));
}