部署WebRTC 或 SIP p2p 方案时经常会遇到p2p 无法穿透的环境, 这时就是TunServer 的用武之地了。 这里我们使用turnserver-0.7.3 下载confuse依赖库 wget http://savannah.nongnu.org/download/confuse/confuse-2.7.tar.gz tar zxvf confuse-2.7.tar.gz cd confuse* ./configure make && make install 下载 wget http://downloads.sourceforge.net/project/turnserver/turnserver-0.7.3.tar.bz2 tar jxvf turnserver-0.7.3.tar.bz2 cd turnserver* ./configure make && make install 编辑配置文件 将extra 中的配置文件模版拷贝到/etc目录下,假设您的ip 是 1.2.3.4 1,配置文件 cp extra/turnserver.conf.template /etc/turnserver.conf vi /etc/tunserver.conf 修改 listen_address = { "你的IP地址外网" } 修改 ## Daemon mode. daemon = true # 修改为后台服务方式 修改带宽限制 ## Allocation bandwidth limitation (in KBytes/s). ## 0 value means bandwidth quota disabled. bandwidth_per_allocation = 1024 ## Restricted user bandwidth (in KBytes/s). ## 0 value means bandwidth limitation disabled. restricted_bandwidth = 0 ## Account file (if account_method = file). 指定认证文件路径 account_file = "/etc/turnusers.txt" 2,认证用户文件 cp extra/turnusers.txt.template /etc/turnusers.txt vi /etc/turnusers.txt 添加一行或多行认证信息格式为 用户名:密码:domain:authorized 例如下面的行: jiege:php2:www.php2.cc:authorized 如果需要开启iptables,需要添加防火墙规则: -A INPUT -p udp --dport 3478 -j ACCEPT -A INPUT -p udp --dport 5347 -j ACCEPT 启动 TurnServer, 运行命令 turnserver 添加完成后,就可以在webrtc 里面使用stun 和tun server 了。 config = { peerConnectionConfig: { iceServers: [ { "url": "stun:www.php2.cc" } ] }, peerConnectionConstraints: { optional: [ {"DtlsSrtpKeyAgreement": true} ] } } 测试turnserver服务是否可用:https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/ 本服务器已配好,可测试: stun:www.php2.cc
PHP技术交流QQ群:422137578 除非注明,文章均为 PHP二次开发 原创,转载请注明本文地址:http://www.php2.cc/article-2676-1.html |