WebRTC的RTCPeerConnection()原理探析

时间:2019-08-31 19:04:25   收藏:0   阅读:138

写在前面

WebRTC P2P的现实物理实现

  1. getUserMedia() 把要寄的东西找出来,在WebRTC里面对应的就是获取audio | video,以及对对获取设备的选择、分辨率的设置之类
  2. RTCPeerConnection()signaling,类似于选什么快递公司(communication protocols),要寄的东西要不要处理一下形式、要装箱子寄还是塑料袋就好、收到快递打开使用有没有注意事项(media codecs and formats),填好寄到的地址(IP adress and port information),然后快递就可以寄出了

    Signaling is the process of sending control information between two devices to determine the communication protocols, channels, media codecs and formats, and method of data transfer, as well as any required routing information.

    There are three basic types of information that need to be exchanged during signaling:
    • Control messages used to set up, open, and close the communication channel, and to handle errors.
    • Information needed in order to set up the connection: the IP addressing and port information needed for the peers to be able to talk to one another.
    • Media capability negotiation: what codecs and media data formats can the peers understand? These need to be agreed upon before the WebRTC session can begin.
  3. 通过RTCPeerConnection() 里的一系列API实现上述signaling 过程,这个过程在下一节里面详细分解
  4. 当然寄快递有时候也会出现错误或者碰到异常情况(虽然现实中这种情况我没遇到过),假如是每天都要发一次货物的那种,ICE restart,就是指去找新的发货方式,在找到新的发货渠道之前保持原来的方式,直到找到新的发货方式

signaling的具体实现过程

技术图片

  1. Each peer creates an RTCPeerConnection object representing their end of the WebRTC session.
  2. Each peer establishes a handler for icecandidate events, which handles sending those candidates to the other peer over the signaling channel.
  3. Each peer establishes a handler for track event, which is received when the remote peer adds a track to the stream. This code should connect the tracks to its consumer, such as a <video> element.
  4. The caller creates and shares with the receiving peer a unique identifier or token of some kind so that the call between them can be identified by the code on the signaling server. The exact contents and form of this identifier is up to you.
  5. Each peer connects to an agreed-upon signaling server, such as a WebSocket server they both know how to exchange messages with.
  6. Each peer tells the signaling server that they want to join the same WebRTC session (identified by the token established in step 4).
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!