Skip to content Skip to sidebar Skip to footer

How To Exchange Streams From Two Peerconnections With Offer/answer

I am trying to setup video chat where two peer connections exchange video. This happens after creating a data channel. So this is the process of events: offerer creates data chann

Solution 1:

I think the problem is in step 3 where you have the offerer initiating when the answerer adds a video. In a real remote call, how would the offerer even know to do that?

As I understand it, when the answerer needs to renegotiate then the roles are effectively reversed, because for the purposes of renegotiation: the renegotiator acts as the offerer, while the non-renegotiator acts as the answerer.

In other words: the response to pc.onnegotiationneeded is always:

  1. createOffer(),
  2. then setLocalDescription(description)
  3. then send pc.localDescription to the other side

regardless of side.

I'm not an authority on SDP, so I don't know for sure that this is the right approach, but the examples in the spec at least suggest to me that the steps above are right, and I got it working this way.

I've tested this out in this Firefox jsfiddle and it seems to work. Instructions for using the fiddle:

  1. There is no server (since it's a fiddle), so press the Offer button and copy the offer.
  2. Paste the offer to the same spot in the same fiddle in another tab or on another machine.
  3. Press ENTER, then copy the answer you get and paste it back in the first fiddle.
  4. You are now connected with two data-channels: one for chat and another for signaling.
  5. Now press addTrack on either end and video should show up on the other end.
  6. Press addTrack in the other direction, and you should have video going both ways.

Can this produce glare? I'm sure, and there may be better ways of handling this, but this seems to work for me.

Post a Comment for "How To Exchange Streams From Two Peerconnections With Offer/answer"