API_PEER_CONNECTION_INTERFACE_H_通信过程描述

 简单翻译一下,仅供自己学习,如有错误,欢迎指出!

// The PeerConnectionFactory class provides factory methods to create
// PeerConnection, MediaStream and MediaStreamTrack objects.
//
// The following steps are needed to setup a typical call using WebRTC:
//
// 1. Create a PeerConnectionFactoryInterface. Check constructors for more
// information about input parameters.
//
// 2. Create a PeerConnection object. Provide a configuration struct which
// points to STUN and/or TURN servers used to generate ICE candidates, and
// provide an object that implements the PeerConnectionObserver interface,
// which is used to receive callbacks from the PeerConnection.
//
// 3. Create local MediaStreamTracks using the PeerConnectionFactory and add
// them to PeerConnection by calling AddTrack (or legacy method, AddStream).
//
// 4. Create an offer, call SetLocalDescription with it, serialize it, and send
// it to the remote peer
//
// 5. Once an ICE candidate has been gathered, the PeerConnection will call the
// observer function OnIceCandidate. The candidates must also be serialized and
// sent to the remote peer.
//
// 6. Once an answer is received from the remote peer, call
// SetRemoteDescription with the remote answer.
//
// 7. Once a remote candidate is received from the remote peer, provide it to
// the PeerConnection by calling AddIceCandidate.
//

PeerConnectionFactory(客户端连接工厂)类提供了 用于创建PeerConnection,MediaStream和MediaStreamTrack对象 的工厂方法。

使用WebRTC设置典型呼叫需要执行以下步骤:

  1. 创建一个PeerConnectionFactoryInterface。 检查构造函数以获取有关输入参数的更多信息。
  2. 创建一个PeerConnection对象。 提供一个指向用于生成 ICE 候选者的 STUN和/或TURN服务器的 配置结构,并提供一个实现PeerConnectionObserver接口的对象,该接口用于接收来自PeerConnection的回调。
  3. 使用PeerConnectionFactory(工厂方法)创建本地MediaStreamTracks,然后通过调用AddTrack(或旧方法,AddStream)将它们添加到PeerConnection 中。
  4. 创建一个offer(邀约),使用offer调用SetLocalDescription,对offer进行序列化,然后将offer发送给remote peer(远程对等方)。
  5. 一旦收集了ICE候选者,PeerConnection将调用观察者函数OnIceCandidate。 candidate还必须序列化并发送到remote peer(远程对等方)。
  6. 一旦从remote peer(远程对等方)收到(answer)回应后,用远端应答(remote answer)调用SetRemoteDescription。
  7. 一旦从remote peer(远程对等方)接收到远程候选者,则通过调用AddIceCandidate将其(remote candidate)提供给PeerConnection。

 

// The receiver of a call (assuming the application is "call"-based) can decide
// to accept or reject the call; this decision will be taken by the application,
// not the PeerConnection.
//
// If the application decides to accept the call, it should:
//
// 1. Create PeerConnectionFactoryInterface if it doesn't exist.
//
// 2. Create a new PeerConnection.
//
// 3. Provide the remote offer to the new PeerConnection object by calling
// SetRemoteDescription.
//
// 4. Generate an answer to the remote offer by calling CreateAnswer and send it
// back to the remote peer.
//
// 5. Provide the local answer to the new PeerConnection by calling
// SetLocalDescription with the answer.
//
// 6. Provide the remote ICE candidates by calling AddIceCandidate.
//
// 7. Once a candidate has been gathered, the PeerConnection will call the
// observer function OnIceCandidate. Send these candidates to the remote peer.

呼叫的接收者(假设应用程序是基于“呼叫”的)可以决定接受还是拒绝该呼叫。 该决定将由应用程序而不是PeerConnection决定。

如果应用程序决定接受呼叫,则应:

  1. 如果不存在,则创建PeerConnectionFactoryInterface。
  2. 创建一个新的PeerConnection。
  3. 通过调用SetRemoteDescription,将remote offer 提供给新的PeerConnection对象。
  4. 通过调用CreateAnswer生成 对 remote offer 的answer(答复),并将其发送回remote peer(远程对等方)。
  5. 通过调用带有answer的SetLocalDescription,为新的PeerConnection提供local answer。
  6. 通过调用AddIceCandidate提供remote ICE候选者。
  7. 收集candidate后,PeerConnection将调用观察者函数OnIceCandidate, 将这些candidate(候选者)发送到remote peer(远程对等方)。

WebRTC P2P建立过程

上图来自连接:https://blog.csdn.net/ice_ly000/article/details/103162838

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值