AppRTC

AppRTC

安裝紀錄
安裝環境
# make working folder
mkdir -p /home/webrtc
cd /home/webrtc

# java SDK
yum -y install java-1.8.0-openjdk nginx

# nodejs
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum -y install nodejs

# apprtc related tools
npm -g install grunt-cli

# python
yum -y install epel-release
yum -y install python python-webtest python-pip
pip install --upgrade pip

# google appengine
wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.40.zip
unzip google_appengine_1.9.40.zip

cd /home/webrtc
echo "export google_appengine_path=/root/webrtc/google_appengine" >> /etc/profile
echo "export PATH=$PATH:$google_appengine_path" >> /etc/profile

source /etc/profile

# go lang
yum -y install golang


# working space
mkdir -p /home/webrtc/goWorkspace/src
echo "export GOPATH=/home/webrtc/goWorkspace" >> /etc/profile
source /etc/profile

cd /home/webrtc
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar xvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure
make install
安裝 AppRTC
cd /home/webrtc
git clone https://github.com/webrtc/apprtc.git

mkdir -p /root/go/src
export GOPATH=/root/go
ln -s /home/webrtc/apprtc/src/collider/collider /root/go/src
ln -s /home/webrtc/apprtc/src/collider/collidermain /root/go/src
ln -s /home/webrtc/apprtc/src/collider/collidertest /root/go/src
 

# 修改房間服務器為我們前面的房間服務器:
vi $GOPATH/src/collidermain/main.go

var roomSrv = flag.String(“room-server”, “https://49.235.159.44:8080”, “The origin of the room server”)
 
vi $GOPATH/src/collider/collider.go
# 修改放入自己私有證書
e = server.ListenAndServeTLS(“/home/ssl/server.pem”,   “/home/ssl/server.key”)
 
cd /home/webrtc

go get collidermain
go install collidermain
安裝 coturn
cd /home/webrtc/

yum -y install openssl-devel

wget http://coturn.net/turnserver/v4.5.0.7/turnserver-4.5.0.7.tar.gz
tar xvfz turnserver-4.5.0.7.tar.gz
cd turnserver-4.5.0.7

./configure --prefix=./bin
make install
 
設定 turnserver
#內網:172.17.0.11 :DevYk:用戶 12345 密碼 & ctr+c 不會停止
nohup turnserver -L 172.17.0.11 -a -u DevYK:12345 -v -f -r nort.gov &


#netstat -ntulp 查看 5766,3478 端口是否啟動
 
安裝 collider 信令服務器
nohup $GOPATH/bin/collidermain -port=8089 -tls=true -room-server="https://49.235.159.44:8080" > /root/webrtc/collidermain.log 2>&1 &
編譯 AppRTC
cd /home/webrtc/apprtc/
npm install
grunt build
配置 ICE Service
mkdir /home/webrtc/iceService
vi ice.js
var http = require('http');
var crypto = require('crypto')
var hmac = function(key, content) {
  var method = crypto.createHmac('sha1', key)
  method.setEncoding('base64')
  method.write(content)
  method.end()
  return method.read()
}
http.createServer(function(request, response) {
  //賬戶
  var timestamp = Math.floor(Date.now() / 1000)
  var turn_username = timestamp + ':DevYK'
  //密碼
  var key = '12345'
  var password = hmac(key, turn_username)
  // 發送 HTTP 頭部 
  // HTTP 狀態值: 200 : OK
  // 內容類型: text/plain
  response.writeHead(200, {'Content-Type': 'text/plain'});
  console.log(turn_username);
  console.log(password);
  // 發送響應數據 "ice服務器"
  response.end('{"iceServers":[{"username":"'+turn_username+'","credential":"'+password+'","urls":["stun:49.235.159.44:3478","turn:49.235.159.44:3478"]}]}\n');
  }).listen(8088);
  // 終端打印如下信息
  console.log('ICE Server running');
配置 nginx
 
vi /etc/nginx/nginx.conf
配置 nginx

vi /etc/nginx/nginx.conf
events {
        worker_connections 1024;
  }
  http{
   #apprtc 服務
        upstream roomserver {
        server example.com:8080;
        }
        server {
                listen 80;
                server_name example.com;
                return  301 https://$server_name$request_uri;
        }
        server {
                root /root/webrtc/nginx-1.17.8/html;
                index index.php index.html index.htm;
                listen      443 ssl;
                ssl_certificate /cert/cert.pem;
                ssl_certificate_key /cert/key.pem;
                server_name example.com;
                location / {
                        proxy_pass http://roomserver$request_uri;
                        proxy_set_header Host $host;
                }
                location ~ .php$ {
                        fastcgi_pass unix:/var/run/php5-fpm.sock;
                        fastcgi_index index.php;
                        include fastcgi_params;
                }
        }
}
啟動
 
cd /home/webrtc/turnserver-4.5.0.7/bin
nohup turnserver -L * -a -u anbotalk:12345 -v -f -r apprtc.anbotalk.net &


nohup $GOPATH/bin/collidermain -port=8089 -tls=true -room-server="https://apprtc.anbotalk.net:8080" > /home/webrtc/collidermain.log 2>&1 &

cd /home/webrtc/google_appengine
nohup ./dev_appserver.py --host=* --port 8080 /home/webrtc/apprtc/out/app_engine --skip_sdk_update_check > /home/webrtc/apprtc.log 2>&1 &


cd /home/webrtc/iceService
nohup node ice.js &