How looks WebRTC peer negotiation workflow?

后端 未结 1 1502
暖寄归人
暖寄归人 2021-01-12 16:30

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 de

相关标签:
1条回答
  • 2021-01-12 17:08

    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...

    0 讨论(0)
提交回复
热议问题