WebRTC: How to add stream after offer and answer?

后端 未结 3 1829
眼角桃花
眼角桃花 2020-12-24 14:08

I am working on webRTC video calling. I got datachannel successfully implemented. Now I would like to add video stream to the same peer connection.

I have read that

相关标签:
3条回答
  • 2020-12-24 14:37

    MediaStream should be added to peerconnection first only then exchange of offer, answer ,candidates should be done. If the onAddStream() is called ,that mean you are receiving the remote video.

    0 讨论(0)
  • 2020-12-24 14:44

    To add stream after creating complete signalling, the Peer connection should renegotiate with stream.

    pc1.addstream(stream)
    

    Then once again create offer and send it to other Peer.

    Remote peer will add stream and send answer SDP.

    To stop streams:

    stream.stop();
    pc1.removeStream(stream);
    
    0 讨论(0)
  • 2020-12-24 14:44

    In my experience, what Konga Raju advised didn't work. I couldn't send an "updated offer" and have the video streaming actually happen.

    I found that this sequence of events works for my case, in which I wish to stream video from peer 1 to peer 2.

    1. set up some way for the peers to exchange messages. (The variance in how people accomplish this is what makes different WebRTC code samples so incommensurable, sadly.)
    2. On each side, set up handlers for the important signalling events. (Some folks have reported that you need to create these handlers at special times, but I haven't found that to be the case. ) There are 3 basic events:
      • an ice candidate sent from the other side ==> call addIceCandidate with it
      • an offer message ==> SetRemoteDescription & make an answer & send it
      • an answer message ===> SetRemoteDescription
    3. On each side, create the peerconnection object with the event handlers we care about: onicecandidate, onremovestream, onaddstream, etc.
      • ice candidate pops out of the peerconnection object ===> send it to other side
    4. When both peers are present and all the handlers are in place, peer 1 gets a trigger message of some kind to start video capture (the getUserMedia call)
    5. Once getUserMedia succeeds, we have a stream. Call addStream on the peer connection object.
    6. Then peer 1 makes an offer
    7. Due to the handlers we set up earlier, peer 2 sends an answer
    8. Concurrently with this (and rather opaquely), the peer connection object starts producing ice candidates. They get sent back and forth between the two peers and handled (steps 2 & 3 above)
    9. Streaming starts by itself, opaquely, as a result of 2 conditions:
      • offer/answer exchange
      • ice candidates received, exchanged, and handled

    I haven't found a way to add video after step 9. When I want to change something, I go back to step 3.

    0 讨论(0)
提交回复
热议问题