11

I'm starting to learn WebRTC and have a working prototype using copy/paste here: https://github.com/aerik/webrtc (the prototype is meant to be run in two browser windows, unlike many other examples that run both sides in one window)

I understand that WebRTC is peer-to-peer and a I need a connection for every set of peers. However, I'm starting to think about signalling (no code yet) and I'm wondering about the "offer". In my prototype I see that clicking "create offer" multiple times results in the same string. So, if have client A, and connect to client B and C, it looks like I will send the same "offer" to both of them. If that's correct, it makes the first step of signalling easy - client A will always have the same offer, and I just have to gather responses from connected peers.

Is this a correct understanding?

Aerik
  • 2,307
  • 1
  • 27
  • 39

1 Answers1

11

It is not, a peer connection will generate different origin values for different offers (o= in the SDP).

Same peer connection offers will contain same <sess-id> but different <sess-version>.

Different peer connections will produce different <sess-id>

You can check it with the following snippet in Chrome:

var a = new webkitRTCPeerConnection({});
a.createOffer().then(offer => $('#11').text(offer.sdp));
a.createOffer().then(offer => $('#12').text(offer.sdp));
var b = new webkitRTCPeerConnection({});
b.createOffer().then(offer => $('#21').text(offer.sdp));
b.createOffer().then(offer => $('#22').text(offer.sdp));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
First PC, first offer: <span id="11"></span><br/>
First PC, second offer: <span id="12"></span><br/>
Second PC, first offer: <span id="21"></span><br/>
Second PC, second offer: <span id="22"></span><br/>

You can find more info about the SDP in https://datatracker.ietf.org/doc/html/rfc4566#page-11

Javier Conde
  • 2,553
  • 17
  • 25
  • On a side note, you can reuse the offer for the same peerconnection. If the connection somehow doesn't complete, you can use the same peerconnection + offer to try again, just don't mix offers from different peerconnections. – Kevin Dec 10 '15 at 09:59
  • @Javier If I have n users in an array then I have to loop over that array and create offer n times and send to each user? – DragonBorn Jul 19 '18 at 09:40
  • 1
    @DragonBorn exactly, you will have to do independent calls to each user, although you will render all the video streams within the same window so it will feel like if it is a single call. Feel free to take a look at https://github.com/jconde/euphony where I implement a platform for multiuser WebRTC rooms. – Javier Conde Jul 19 '18 at 13:19
  • @JavierConde, is your conferencing solution `euphony` based on P2P mesh topology or SFU? In other words, is every peer sending as many upload streams as the other members? – iammilind Mar 17 '22 at 14:44
  • @iammilind it is mesh topology, every user creates a single p2p connection with each other member of the room – Javier Conde Mar 17 '22 at 22:13