Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How looks WebRTC peer negotiation workflow?

Tags:

webrtc

I need to develop a custom WebRTC peer (I need to establish audio or/and data connection between web-browser and non-browser). I however, struggle to find a proper, clear description of the handshake phase.

Answers to questions such as How to create data channel in WebRTC peer connection? are not entirely helpful, as they are not too detailed. Specifically, they say nothing about SDP contents.

Can anyone explain this or recommend any good documentation?

like image 724
mspanc Avatar asked Nov 28 '15 18:11

mspanc


1 Answers

Here is a page with some graphs showing how the signaling process works. Basically, you set some client side stuff first:

  • PeerConnectionFactory; to generate PeerConnections,
  • PeerConnection; one for every connection to another peer you want (usually 1),
  • MediaStream; to hook up the audio and video from your client device.

Then you generate an SDP offer

peerConnection.createOffer();  

on the caller side and send it to the callee. The callee sets this offer

peerConnection.setRemoteDescription(insert-the-offer-here);

and generates an SDP answer

peerConnection.createAnswer();

and sends it back to the caller. The caller receives this answer and sets it.

peerConnection.setRemoteDescription(insert-the-answer-here);

Both the caller and callee get a call to

onAddStream() {...} //needs to be implemented in your code

The callee when the caller's offer is set and the caller when the callee's answer is set. This callback signals the beginning of the connection.
You can also use ICE (STUN/TURN) to avoid firewall and NAT issues, but this is optional. Although in production code, you probably want to implement it anyway.

Note: Webrtc documentation is scarce and subject to change, take everything you read about webrtc (at least anything written as of now) with a grain of salt...

like image 177
Kevin Avatar answered Nov 17 '22 01:11

Kevin