Skip to content Skip to sidebar Skip to footer

How To Restore The Negotiation After Changing The Camera And Microphone?

About a month ago, a Stackoverflow partner helped me with a big question, like changing the camera and the microphone during a conference. That question was answered in the followi

Solution 1:

I don't know about simpleWebRTC, but in plain WebRTC renegotiation is not necessary.

Just use sender.replaceTrack(). It's async, so to switch both camera and mic at the same time:

navigator.mediaDevices.getUserMedia(constraints) 
  .then(stream => {
    video.srcObject = stream;
    returnPromise.all(stream.getTracks().map(track => {
      const sender = pc.getSenders().find((s => s.track.kind == track.kind);
      return sender.replaceTrack(track);
    }));
  })
  .catch(err =>console.log(err));

This should instantly cause the sender to switch to sending media from your new camera and microphone. The other side won't know the difference.

Post a Comment for "How To Restore The Negotiation After Changing The Camera And Microphone?"