What does the WebRTC peer negotiation workflow look like?

I need to develop a custom peer-to-peer WebRTC (I need to establish an audio and / or data connection between a web browser and a non-browser). However, I am trying to find the correct, clear description of the handshake phase.

Answers to questions such as How to create a data channel in a WebRTC peer-to-peer connection? not quite useful, as they are not too detailed. In particular, they do not say anything about the contents of SDP.

Can someone explain this or recommend any good documentation?

+5
source share
1 answer

Here is a page with some graphs showing how the alarm process works . Essentially, first you install some elements of the client side:

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

Then you create an SDP offer

 peerConnection.createOffer(); 

on the calling party side and send it to the called party. The caller sets up this offer

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

and generates SDP answer

 peerConnection.createAnswer(); 

and send it back to the caller. The subscriber receives this answer and installs it.

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

Both the caller and the callee will invoke the call

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

The call when the calling offer set, and the calling when the answer configured. This callback signals the start of a connection.
You can also use ICE ( STUN / TURN ) to avoid problems with firewall and NAT , but this is optional. Although in production code, you probably want to implement it.

Note. The Webrtc documentation is sparse and subject to change, take everything you read about webrtc (at least anything written at the moment) with a grain of salt ...

+8
source

Source: https://habr.com/ru/post/1237013/


All Articles