为WebRTC应用程序实现我们自己的STUN/TURN服务器

Sam*_*ast 27 stun webrtc rfc5766turnserver turn

我正在研究webrtc应用程序,必须实现以下TURN服务器.

https://code.google.com/p/rfc5766-turn-server/

我正在学习本教程.

http://www.dialogic.com/den/developer_forums/f/71/t/10238.aspx

它表示在创建RTCPeerConnection的javascript代码中如下引用TURN服务器.

var pc_config = {"iceServers": [{"url": "stun:stun.l.google.com:19302"},
  {"url":"turn:<turn_server_ip_address>", "username":"my_username", "credential":"my_password"}]};

pc_new = new webkitRTCPeerConnection(pc_config);
Run Code Online (Sandbox Code Playgroud)

我有点困惑,为什么我们引用谷歌的公共STUN服务器.我以为RFC5766 TURN服务器里面有STUN.

RFC5766只有TURN服务器吗?而不是STUN服务器?我们不能实现自己的STUN服务器,而不是使用谷歌提供的服务器吗?

抱歉这样天真的问题.我是WebRTC的新手.

谢谢.

mid*_*ido 36

加上伊戈尔的回答,

coturn是一个分支rfc5766-turn-server,核心功能是相同的,具有额外的功能,并添加了新的功能,所以我建议你使用它.

用作者自己的话说:

该项目是从rfc5766-turn-server项目(https://code.google.com/p/rfc5766-turn-server/)发展而来的.有许多新的高级TURN规范远远超出了原始的RFC 5766文档.该项目将rfc5766-turn-server的代码作为入门者,并为其添加了新的高级功能.

至于安装,很容易在linux机器上安装,而不是在其他操作系统中尝试过.

简单方法:

sudo apt-get install coturn
Run Code Online (Sandbox Code Playgroud)

如果您拒绝,我想要最新的前沿,您可以从他们的下载页面下载源代码,自行安装,例如:

sudo -i     # ignore if you already in admin mode
apt-get update && apt-get install libssl-dev libevent-dev libhiredis-dev make -y    # install the dependencies
wget -O turn.tar.gz http://turnserver.open-sys.org/downloads/v4.5.0.6/turnserver-4.5.0.6.tar.gz     # Download the source tar
tar -zxvf turn.tar.gz     # unzip
cd turnserver-*
./configure
make && make install 
Run Code Online (Sandbox Code Playgroud)

为了运行TURN,建议将其作为守护程序运行,您可以使用此Wiki作为参考进行配置.

用于运行TURN服务器的示例命令:

sudo turnserver -a -o -v -n  --no-dtls --no-tls -u test:test -r "someRealm"
Run Code Online (Sandbox Code Playgroud)

命令说明:

  • -a - 使用长期凭证机制
  • -o - 将服务器进程作为守护程序运行
  • -v - '中等'详细模式.
  • -n - 没有配置文件
  • --no-dtls - 不要启动DTLS监听器
  • --no-tls - 不要启动TLS监听器
  • -u - 要使用的用户凭据
  • -r - 要使用的默认域,需要TURN REST API

现在您可以在WebRTC应用程序中使用TURN服务器:

var peerConnectionConfig = {
  iceServers: [{
    urls: YOUR_IP:3478,
    username: 'test',
    password: 'test'
  }]
}
Run Code Online (Sandbox Code Playgroud)

  • "someRealm"代表什么? (8认同)
  • 不得不运行`sudo apt-get update && sudo apt-get install build-essential` (3认同)

Rub*_*con 16

TURN它是STUN的扩展,因此TURN服务器也具有STUN功能.

https://code.google.com/p/rfc5766-turn-server/也可以作为STUN,因此您可以尝试编写如下内容:

var pc_config = {"iceServers": [{"url":"turn:my_username@<turn_server_ip_address>", "credential":"my_password"}]};

pc_new = new webkitRTCPeerConnection(pc_config);
Run Code Online (Sandbox Code Playgroud)