A tentative study of WEBRTC notes

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/fangkm/p/4364553.html

WEBRTC is one of the important features of HTML5 support, it is no longer necessary to use audio and video-related clients, directly through the browser's web page to achieve audio and video chat function. And the WEBRTC project is open source, we can use the WEBRTC source code to quickly build their own audio and video chat function. Whether using the WEBRTC API interface of the front-end JS or building your own chat framework on the WEBRTC source code, you need to follow the following execution processes:

In the above sequence, WEBRTC does not provide stun server and signal server, the server side needs to implement itself. The stun server can be used by Google to implement the stun Protocol test Server (stun:stun.l.google.com:19302), signal server is completely required to implement their own, It requires both SDP and candidate information to be transmitted between Clienta and CLIENTB, and Clienta and CLIENTB Use this information to establish a peer-to connection to deliver audio and video data. Due to the complexity of the network environment, not all clients can establish peer-to connection, in this case, there is a need for a relay server to do audio and video data transfer, this article in line with the analysis of the attitude of the source, this situation is not considered. Here explain, Stun/turn, relay server implementation in WEBRTC source code, there are examples, is really a big treasure trove.

In the above sequence, the annotated scene is Clienta to ClientB to initiate the chat request, the invocation is described as follows:

  • Clienta first creates the Peerconnection object, then turns on the local AV device, encapsulates the audio and video data into MediaStream and adds it to the peerconnection.
  • Clienta calls Peerconnection's Createoffer method to create an SDP object for an offer that holds the relevant parameters for the current audio and video in the SDP object. Clienta saves the SDP object through the Peerconnection Setlocaldescription method and sends it to CLIENTB via the signal server.
  • CLIENTB receives the offer SDP object sent by Clienta, which is saved by Peerconnection's Setremotedescription method, and call Peerconnection's Createanswer method to create an answer to the SDP object, The answer SDP object is saved by Peerconnection's Setlocaldescription method and sent to Clienta through the signal server.
  • Clienta receives the reply SDP object sent by CLIENTB and saves it through the Peerconnection setremotedescription method.
  • In the offer/answer process of SDP information, Clienta and CLIENTB have created appropriate audio channel and video channel based on SDP information and turned on the collection of candidate data. Candidate data can be simply understood as client IP address information (local IP address, public IP address, relay server assigned address).
  • When Clienta collects candidate information, Peerconnection will send a notification to Clienta via the Onicecandidate interface. Clienta will receive the candidate information by signal server sent to CLIENTB,CLIENTB through Peerconnection Addicecandidate method saved up. The same operation ClientB to Clienta again.
  • So Clienta and CLIENTB have established the audio and video transmission of the peer channel, CLIENTB received the Clienta transmitted over the audio and video stream, A MediaStream object that identifies the Clienta-side audio and video stream is returned via the Peerconnection Onaddstream callback interface, which is rendered on the ClientB side. The same operation also adapts to the transmission of CLIENTB to Clienta audio and video streams.

Here the process is only from the use of a description of the level, the specific internal what has been done, how to do, the future of the article will be slowly fine, everything starts difficult, self-encouragement.

A tentative study of WEBRTC notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.