webrtcp2ppeer

How to add additional peers to the WebRTC session with already two existing peers


I have used WebRTC to make p2p audio and video connection. With only two peers I get the order of invocation.

Peer1-caller sends SDP offer and ICE candidates. Peer2-callee receives SDP offer and ICE candidates generates SDP answer and it's ICE candidates send it back to the caller which adds them.

Now let's say I want Peer3 to join the session with two existing peers. What would be the process?

    • Peer3 sends SDP offer and ICE candidates to both previous peers and both Peer1-caller and Peer2-callee send back SDP answers, I suppose I would have to have ICE candidates from previous peers stored somewhere?
    • Peer3 has to wait for SDP offers from Peer1-caller and Peer2-callee and send back SDP answer to both of them?
    • Initiator Peer1-caller sends SDP offer to Peer3 which responds with SDP answer and after ICE candidates are exchanged between all three peers they can all see each other?
    • Something else?

Basically I am confused how to add third peer, which method to use peerConnection.createOffer() than wait for SDP answers from all other peers including the initiator or wait for SDP offer(s) and use peerConnection.createAnswer()?

Any help would be appreciated.
Thanks.


Solution

  • RTCPeerConnection is just that, a connection talking to a single endpoint. If you want to more than one, you'll need a separate peerconnection for each, complete with its own independent offer-answer exchange.

    https://webrtc.github.io/samples/src/content/peerconnection/multiple/ is a minimal demo.