WEBRTC 学习过程

1、webrtc可以无需插件基于web直接完成视频,目前主流的浏览器firefox/chrome/微软Edge均已经支持了

2、其部署依赖两个东西

2.1、一个是消息服务,负责对端连接信息(sdp)的交换

这里使用golang-collider 基础websocket进行通信

golang的进程这里通过supervisor进行管理

使用yum进行安装:

yum install python-setuptools

easy_install supervisor

echo_supervisord_conf > /etc/supervisord.conf 生成基础配置

[program:xxxx]

command=xxxxx

user=xxxx

autostart=true

autorestart=true

stderr_logfile=/tmp/xxx_err.log

stdout_logfile=/tmp/xxx.log

更多配置说明请参考:http://supervisord.org/configuration.html


2.2、一个是ICE服务,负责NAT穿透和打洞穿透

载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 = { "1.2.3.4" }

修改 ## 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

2,认证用户文件

cp extra/turnusers.txt.template /etc/turnusers.txt

vi /etc/turnusers.txt

添加一行或多行认证信息格式为    用户名:密码:domain:authorized

例如下面的行:

700:700pass:domain.org:authorized

添加完成后,就可以在webrtc 里面使用stun 和tun server 了。

var configuration = {

  'iceServers': [{

    { 'url' : 'stun:1.2.3.4'} ,

    { 'url' : 'turn:1.2.3.4', username:'700', credential:'700pass'}

  }]

};


如果是做国外的市场可以直接使用google提供的ice服务器

var configuration = {"iceServers": [{"urls":"stun:stun.l.google.com:19302"}]};


3、webrtc-前端代码demo

具体自行下载


你可能感兴趣的:(WEBRTC 学习过程)