使用WebRTC构建iOS Native App [英] Building iOS Native App using WebRTC

查看:418
本文介绍了使用WebRTC构建iOS Native App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找4天,但无法得到它。我构建了所有库并将其集成到我的自定义项目中,但我不知道应该采取哪些步骤来使其工作。我在代码example \explanation中找到的唯一一件事就是tech.appear.in/2015/05/25/Getting-started-with-WebRTC-on-iOS,但它对我来说很糟糕且不清楚,AppRTCDemo源代码也是如此。我读过有关浏览器的WebRTC但仍然无法在iOS上重现它。
任何人都可以解释或提供关于如何使用WebRTC API完全构建iOS本机应用程序的解释链接,例如p2p ios chat?

I'm searching for 4 days, but can't get it. I built all libraries and integrated it in my custom project, but I don't know what steps should I do to make it work. The only thing that i found with code example\explanation is tech.appear.in/2015/05/25/Getting-started-with-WebRTC-on-iOS , but it is poor and unclear for me, AppRTCDemo source code too. I read about WebRTC for browsers but still can't reproduce it on iOS. Can anybody explain or provide links to explanation on how to completely build iOS native app using WebRTC API for example p2p ios chat?

除了我不理解演示中提供的代码逻辑这一事实外,我无法理解:

Besides the fact that I do not understand code logic provided in demo, I can't understand:

1)我的iOS应用程序的ICE服务器是什么?我应该照顾它吗?它是服务器端的东西吗?我应该自己编码和运行它,还是我可以使用现有的Parse背景?

1) What is ICE servers for my iOS app? Should I take care of it? Is it something server side? Should I code and run it myself, or I can use existing Parse background?

2)iOS应用程序中的信令机制是什么?它只是客户端,还是必须在服务器端实现?

2) What is signaling mechanism in iOS app? Is it client side only, or it must be implemented on server side too?

3)也许有人可以解释一步一步的指南,也许有一些代码,如何使用WebRTC实现简单的iOS p2p聊天?例如:

3) And maybe someone can explain step-by-step guide, maybe with some code, how to implement simple iOS p2p chat using WebRTC? For example:

你必须:


  1. 创建ICE解析核心上的/ STUN / TURN服务器使用this = source =和本教程=教程=。

  1. Create ICE/STUN/TURN server on parse core using this =source= and this tutorial =tutorial=.

使用创建的ICEServer创建RTCPeerConnection:
RTCPeerConnectionFactory * pcFactory = [[RTCPeerConnectionFactory alloc] init];
RTCPeerConnection * peerConnection = [pcFactory peerConnectionWithICEServers:kICEServerURL constraints:nil delegate:self];

Create RTCPeerConnection using created ICEServer: RTCPeerConnectionFactory *pcFactory = [[RTCPeerConnectionFactory alloc] init]; RTCPeerConnection *peerConnection = [pcFactory peerConnectionWithICEServers:kICEServerURL constraints:nil delegate:self];

使用创建DataChannel ...

发送信号使用 ... 在此解释= link =

Send signal using ... explained here =link=

设置本地和远程描述 ...

发送数据 ... 使用 ...

...或类似的东西。

... " or something similar.

我很抱歉这个问题,但是我想失去理智。谢谢!

I'm sorry for asking this, but I'm losing my mind trying to figure it out. Thank you!

推荐答案

我不是webrtc的专家,但我会尝试解释你的一些问题。

I am not an expert in webrtc but i will try to explain some of your questions.

1.ICE服务器 - NAT和防火墙在设置IP端点时存在严重问题。因此开发了IETF标准STUN,TURN和ICE来解决NAT遍历问题。
STUN帮助连接IP端点:

1.ICE servers-- NATs and firewalls impose significant problem in setting up IP endpoints. so IETF standards STUN, TURN and ICE were developed to address the NAT traversal problem. STUN helps connect IP end-points:


  • 发现它们是否在NAT /防火墙后面,如果是,
  • discover whether they are behind a NAT/firewall, and if so,
  • to determine the public IP address and type of the firewall. STUN then uses this information to assist in establishing peer-to-peer IP connectivity.

TURN,代表Traversal Using Relay NAT,提供了一种回退NAT遍历技术,使用媒体中继服务器来促进端点之间的媒体传输。

TURN, which stands for Traversal Using Relay NAT, provides a fallback NAT traversal technique using a media relay server to facilitate media transport between end-points.

ICE是一个利用STUN和TURN提供可靠IP集的框架-up和媒体传输,通过SIP提供/应答模型为端点交换多个候选IP地址和端口(如私有地址和TURN服务器地址)。

ICE is a framework that leverages both STUN and TURN to provide reliable IP set-up and media transport, through a SIP offer/answer model for end-points to exchange multiple candidate IP addresses and ports (such as private addresses and TURN server addresses).

2.信号是协调沟通的过程。这个信号部分需要你根据自己的需要实现(例如,如果你有sip结构,那么你将不得不实现sip信令)。为了使WebRTC应用程序设置呼叫,其客户端需要交换信息:

2.Signaling is the process of coordinating communication. This signalling part needs to be implemented by you according to your needs(for ex. if you have sip structure in place then you will have to implement sip signalling). In order for a WebRTC application to set up a 'call', its clients need to exchange information:


  • 用于打开的会话控制消息或密切沟通。

  • 错误消息。

  • 媒体元数据,如编解码器和编解码器设置,带宽和媒体类型。

  • 用于建立安全连接的密钥数据。

  • 网络数据,例如外部世界看到的主机IP地址和端口。

  • Session control messages used to open or close communication.
  • Error messages.
  • Media metadata such as codecs and codec settings, bandwidth and media types.
  • Key data, used to establish secure connections.
  • Network data, such as a host's IP address and port as seen by the outside world.


  1. 步骤

for beferer:

for offerer:

首先创建对等连接并将冰候选者传递给
作为参数。

first create the peer connection and pass the ice candidates into it as parameters.

为三个事件设置事件处理程序:

set event handlers for three events:


  • onicecandidate-- onicecandidate返回本地生成的ICE候选者,以便您可以通过其他对等体传递它们( s)即STUN / TURN服务器返回的冰候选者列表;这些冰候选者包含你的公共ipv4 / ipv6地址以及UDP随机地址

  • onaddstream - onaddstream返回远程流(你朋友的麦克风和相机!)。


    • addStream`将您的本地麦克风和相机附加到其他同行。

    现在通过调用setLocalDescription函数创建SDP提供,并通过调用setRemoteDescription设置远程SDP。

    Now create SDP offer by calling setLocalDescription function and set remote SDP by calling setRemoteDescription.

    对于回答者:


    • setRemoteDescription

    • createAnswer

    • setLocalDescription

    • oniceCandidate - 获取本地生成的ICE

    • addiceCandidate - 获取其他对等方发送的ICE

    • onaddstream - 用于添加远程流

    • setRemoteDescription
    • createAnswer
    • setLocalDescription
    • oniceCandidate--On getting locally generated ICE
    • addiceCandidate--On getting ICE sent by other peer
    • onaddstream--for remote stream to add

    我希望这会让你的一些疑惑变得清晰。

    I hope this will make some of your doubts clear.

    这篇关于使用WebRTC构建iOS Native App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆