how to restore the negotiation after changing the camera and microphone?

两盒软妹~` 提交于 2019-12-24 12:19:14

问题


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 following link:

Using WebRTC how to choose mic and camera?

After changing the camera and microphone, the previous media flow remains active. So the other people in the conference can not receive the new flow I have in some way.

I would like to know how to renegotiate this new flow, if necessary.

The library that I use for webRTC implementation in the project is "simplewebRTC" currently in disuse.

The code I use to change devices is based entirely on what was achieved in my previous question ...


回答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;
    return Promise.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.



来源:https://stackoverflow.com/questions/55400158/how-to-restore-the-negotiation-after-changing-the-camera-and-microphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!