WebRTC - change device / camera in real time

I had a problem trying to change the camera in real time. It works for local video, but the remote person cannot see the new camera and still sees the old one. I tried to stop the thread and restart again, but still did not work. This is just part of my code. I searched everywhere and I cannot find a solution. Can someone help me?

function init() {
        getUserMedia(constraints, connect, fail);
}

$(".webcam-devices").on('change', function() {
    var deviceID = this.value;
    constraints.video = {
        optional: [{
            sourceId: deviceID
        }]
    };
    stream.getTracks().forEach(function (track) { track.stop(); });
    init();
});
+4
source share
1 answer

, PeerConnection. Firefox RTPSender.replaceTrack(new_track); ( ). / RTCPeerConnection , onnegotiationneeded

. @jib : Jib replaceTrack() :

function flip() {
  flipped = 1 - flipped;
  return pc1.getSenders()[0].replaceTrack(streams[flipped].getVideoTracks()[0])
  .then(() => log("Flip! (notice change in dimensions & framerate!)"))
  .catch(failed);
}
+3

Source: https://habr.com/ru/post/1606278/


All Articles