文章标题

来源:互联网 发布:阿里云邮箱中病毒 编辑:程序博客网 时间:2024/06/06 14:11

WebRtc 初见
一、 服务端
源码地址https://github.com/muaz-khan/RTCMultiConnection
文档说明http://www.rtcmulticonnection.org/docs/
1.1 RTCMultiConnection是基于WebRTC进行实时连接的开源多人音视频通讯服务器,最新版本为V3.4.2.
1.2服务器部署(部署环境为ubuntu-14.04-desktop-amd64):
1.2.1安装npm
sudo apt-get update

sudo apt-get install npm

sudo npm install -g npm

1.2.2安装nodejs(直接使用sudo apt-get install nodejs安装会因版本过低导致无法运行) 我们可以采用手动安装。
1获取源码:wget https://nodejs.org/dist/v6.9.1/node-v6.9.1.tar.gz(如网络不稳定易获取失败,可通过浏览器打开此链接下载)

2解压:tar zxvf node-v6.9.1.tar.gz

3使用gcc编译并安装:
cd node-v6.9.1
./configure

            编译:make(编译时间较长,耐心等待)            安装:make install

4查看是否安装成功:node –v

1.2.3克隆RTCMultiConnection源码到指定目录:
sudo apt-get install git

    git clone https://github.com/muaz-khan/RTCMultiConnection.git ./RTCMultiConnection

1.2.4安装服务器:
cd RTCMultiConnection
sudo npm install –save-dev

1.2.5 开启服务器:
node server.js

(后台运行可使用node server.js &)
1.3 开启守护进程:
Forever可以守护Node.js应用,命令终端断开的情况下,应用也能正常工作。
安装Forever(需要加-g参数,因为forever要求安装到全局环境下):
sudo npm install forever –g

运行守护进程:

附Forever使用方法:
forever使用:

启动

forever start ./bin/www #最简单的启动方式
forever start -l forever.log ./bin/www #指定forever日志输出文件,默认路径~/.forever
forever start -l forever.log -a ./bin/www #需要注意,如果第一次启动带日志输出文件,以后启动都需要加上 -a 参数,forever默认不覆盖原文件
forever start -o out.log -e err.log ./bin/www #指定node.js应用的控制台输出文件和错误信息输出文件
forever start -w ./bin/www #监听当前目录下文件改动,如有改动,立刻重启应用,不推荐的做法!如有日志文件,日志文件是频繁更改的

重启

forever restart ./bin/www #重启单个应用
forever restart [pid] #根据pid重启单个应用
forever restartall #重启所有应用

停止(和重启很类似)

forever stop ./bin/www #停止单个应用
forever stop [pid] #根据pid停止单个应用
forever stopall #停止所有应用

查看forever守护的应用列表

    forever list

1.4 测试是否部署成功(默认端口号为9001)
打开地址:http://localhost:9001/(出现如下页面即为部署成功)

1.5 配置穿透服务器
https://www.webrtc-experiment.com/docs/TURN-server-installation-guide.html#coturn
CoTURN installation on Ubuntu
Make sure that you’re using latest up-to-dated Ubuntu (TLS 14+)
1.5.1 Find a useful FTP link for your region。
https://packages.debian.org/jessie/amd64/coturn/download
Simply copy the link. Don’t try any command yet.
1.5.2 Modify sources.list file:
/etc/apt/sources.list
And add above FTP_domain in the sources-list. E.g.
# at the bottom of the sources.list file
# assuming that you found this domain:
# http://ftp.hk.debian.org/debian
deb http://ftp.hk.debian.org/debian jessie main
1.5.3 Make sure you have installed “Aptitude”:
https://wiki.debian.org/Aptitude
# update-to-latest version
aptitude update
1.5.4 Now install “coturn” package using “aptitude”:
# below command may require [sudo] privileges
aptitude install coturn
1.5.5 If “aptitude install coturn” fails:
# replace “8B48AD6246925553” and “7638D0442B90D010” with the error_key displayed on your OWN-screen
# GPG error: http://ftp.hk.debian.org jessie Release:
# The following signatures could not be verified because the public key is
# not available: NO_PUBKEY 8B48AD6246925553 NO_PUBKEY 7638D0442B90D010 NO_PUBKEY CBF8D6FD518E17E1
# execute below commands
gpg –keyserver pgpkeys.mit.edu –recv-key 8B48AD6246925553
gpg -a –export 8B48AD6246925553 | apt-key add -
gpg –keyserver pgpkeys.mit.edu –recv-key 7638D0442B90D010
gpg -a –export 7638D0442B90D010 | apt-key add -
1.5.6 Modify following file after “coturn” installation:
/etc/turnserver.conf
Remove all text from the file, and replace with this:
# you can listen ports 3478 and 5349 instead of 80/443
listening-port=80
tls-listening-port=443
listening-ip=your-ip-address
relay-ip=your-ip-address
external-ip=your-ip-address
realm=yourdomain.com
server-name=yourdomain.com
lt-cred-mech
userdb=/etc/turnuserdb.conf
# use real-valid certificate/privatekey files
cert=/etc/ssl/certificate.pem
pkey=/etc/ssl/private.key
no-stdout-log
1.5.7 Modify following file after modifying above “turnserver.conf”:
/etc/turnuserdb.conf
Remove all text from the file, and replace with this:
yourName:yourPassword
Now type following command:
turnserver
Try following if above “turnserver” command fails:
# you can listen ports 3478 and 5349 instead of 80/443
lsof -n -i4TCP:80 | grep LISTEN
lsof -n -i4TCP:443 | grep LISTEN
Kill “existing” processes using this command:
kill processId
Now type following command again and it should work:
turnserver
Make sure that ports 80/443 (or 3478/5349) are opened in the firewall:
# you can listen ports 3478 and 5349 instead of 80/443
iptables -A INPUT -p udp –dport 80 -j ACCEPT
iptables -A INPUT -p udp –dport 443 -j ACCEPT
Run following command:
nohup turnserver > /dev/null 2>&1 &
# or simply
nohup turnserver &
Now check all UDP+TCP ports:
# recommended
netstat -tulpn
# or
netstat -nat | grep LISTEN
You will see that port 80/443 is listened by turnserver (both for UDP/TCP).
二、 客户端
2.1在Android Studio Gradle dependencies中引入
compile ‘org.xwalk:xwalk_core_library:22.52.561.4@aar’ 最新版本的crosswalk。
2.2 布局配置

0 0
原创粉丝点击