webrtc起步 - apprtc服務器搭建


簡介
     apprtc 是什么,webrtc.org官方指定體驗app
 
 
原料:
ubuntu14.04,其他linux版本不限,官方並沒特殊說明
chrome M51+
 
 
 
步驟:
 
設置代理
由於國內網絡的特殊性,這步非常關鍵,如果沒有靠譜的代理,很可能以失敗告終。
設置shell環境的代理
添加如下內容到 ~/.bashrc
export http_proxy= http://10.xx.xx.xx:100
export https_proxy= http://10.xx.xx.xx:100
     
設置git的代理
添加如下內容到  ~/.gitconfig
[http]
         proxy = http://10.xx.xx.xx:100
         sslverify = false
[https]
          proxy = http://10.xx.xx.xx:100
 
 
下載,解壓.
建議存放在和apprtc同級目錄
 
├── code
│   ├── google_appengine
│   ├── apprtc
 
 
安裝apprtc
下載apprtc源碼
建議存放在和google_appengine同級目錄
 
├── code
│   ├── google_appengine
│   ├── apprtc
 
 
 
安裝npm
下面摘錄自[1],如果設置好代理之后,這些步驟可很順利的完成
 
Install grunt by first installing  npm. npm is distributed as part of nodejs.
sudo apt-get install nodejs
sudo npm install -g npm
 
On Ubuntu 14.04 the default packages installs  /usr/bin/nodejs but the  /usr/bin/node executable is required for grunt. This is installed on some Ubuntu package sets; if it is missing, you can add this by installing the  nodejs-legacypackage,
sudo apt-get install nodejs-legacy
 
It is easiest to install a shared version of  grunt-cli from  npm using the  -g flag. This will allow you access the  gruntcommand from  /usr/local/bin. More information can be found on  gruntjs Getting Started.
sudo npm -g install grunt-cli

Omitting the -g flag will install grunt-cli to the current directory under the node_modules directory.

 
Finally, you will want to install grunt and required grunt dependencies.  This can be done from any directory under your checkout of the webrtc/apprtc repository.
npm install

On Ubuntu, you will also need to install the webtest package:

sudo apt-get install python-webtest
 
編譯apprtc
sudo grunt build --force
每次更新修改代碼都應該重新編譯,編譯生成的文件存放在out目錄中
 
 
運行apprtc
sudo ../google_appengine//dev_appserver.py ./out/app_engine --host 0.0.0.0
 
 
安裝 rfc5766-turn-server 
sudo app-get install rfc5766-turn-server
配置
編輯 /etc/trunserver.conf
確保打開了以下行的注釋,並且賦予正確的值,port,ip的值當然要按照實際情況填寫,static-auth-secret=4080218913最好也不要修改成其他值,因為apprtc硬編碼了這個值,除非你也去修改apprtc里對應的地方。realm=cn.cn 這個沒有要求,填寫自己的域名即可。Verbose 不是必須的,打開它只是為了可以看到更多輸出而已。
 
18:listening-port=9000
52:listening-ip=10.58.60.236
97:relay-ip=10.58.60.236
154:Verbose
203:use-auth-secret
211:static-auth-secret=4080218913
289:realm=cn.cn
446:
 
 
制作證書
➜  apprtc git:(restapi) ✗ openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 99999 -nodes
Generating a 2048 bit RSA private key
..............+++
....................................................+++
writing new private key to 'key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:cn
State or Province Name (full name) [Some-State]:cn
Locality Name (eg, city) []:cn
Organization Name (eg, company) [Internet Widgits Pty Ltd]:cn
Organizational Unit Name (eg, section) []:cn
Common Name (e.g. server FQDN or YOUR name) []:cn
Email Address []:cn
 
生成過程中多次提示輸入一些信息,可以馬馬虎虎填寫一下。
 
將生成的 cert.pem 和 key.pem 安裝到/cert/目錄下,為什么要放在這個目錄呢,因為collidermain中硬編碼讀取下面兩個文件。不放在這里就意味着要去修改collidermain中的代碼,為了省事,暫且順着它的方式來。
"/cert/cert.pem"
"/cert/key.pem"
 
 
 
安裝 stunnle
sudo app-get install stunnle
配置
編輯 /usr/local/etc/stunnel/stunnel.conf
 
添加以下內容
[apprtc_main]
accept  = 443
connect = 8080
cert = /cert/cert.pem
 
[apprtc_auth]
accept  = 4431
connect = 8081
cert = /cert/cert.pem
 
 
安裝golang
sudo app-get install golang
 
 
編譯信令
在apprtc目錄中
export GOPATH=$(shell pwd)
go build -o collidermain src/collider/collidermain/main.go
 
編譯rfc5766-turn-server授權服務:apprtc_turn_auth
授權服務筆者沒有找到源碼,所以需要自己寫,這里共享出筆者寫golang版的代碼。
編譯方式如下
export GOPATH=$(shell pwd)
go build -o auth auth.go
 
 
 
 
修改apprtc中的代碼
對apprtc/src做如下修改,但是IP地址要根據實際情況填寫。修改之后必不可少的步驟是重新編譯,千萬別忘了。
 
diff --git a/src/app_engine/apprtc.py b/src/app_engine/apprtc.py
index dbe9d84..2acc179 100755
--- a/src/app_engine/apprtc.py
+++ b/src/app_engine/apprtc.py
@@ -292,6 +292,7 @@ def get_room_parameters(request, room_id, client_id, is_initiator):
 
   if room_id is not None:
     room_link = request.host_url + '/r/' + room_id
+    room_link = room_link.replace("http", "https")
     room_link = append_url_arguments(request, room_link)
     params['room_id'] = room_id
     params['room_link'] = room_link
diff --git a/src/app_engine/constants.py b/src/app_engine/constants.py
index 430a7a2..7d4dd73 100644
--- a/src/app_engine/constants.py
+++ b/src/app_engine/constants.py
@@ -16,8 +16,8 @@ TURN_BASE_URL = 'https://computeengineondemand.appspot.com'
 TURN_URL_TEMPLATE = '%s/turn?username=%s&key=%s'
 CEOD_KEY = '4080218913'
 
-ICE_SERVER_BASE_URL = 'https://networktraversal.googleapis.com'
-ICE_SERVER_URL_TEMPLATE = '%s/v1alpha/iceconfig?key=%s'
+ICE_SERVER_BASE_URL = 'https://10.58.60.236:4431'    # 'https://networktraversal.googleapis.com'
+ICE_SERVER_URL_TEMPLATE = '%s/turn?key=%s'             # '%s/v1alpha/iceconfig?key=%s'
 ICE_SERVER_API_KEY = os.environ.get('ICE_SERVER_API_KEY')
 
 # Dictionary keys in the collider instance info constant.
@@ -25,13 +25,13 @@ WSS_INSTANCE_HOST_KEY = 'host_port_pair'
 WSS_INSTANCE_NAME_KEY = 'vm_name'
 WSS_INSTANCE_ZONE_KEY = 'zone'
 WSS_INSTANCES = [{
-    WSS_INSTANCE_HOST_KEY: 'apprtc-ws.webrtc.org:443',
+    WSS_INSTANCE_HOST_KEY: '10.58.60.236:4432',   # 'apprtc-ws.webrtc.org:443',
     WSS_INSTANCE_NAME_KEY: 'wsserver-std',
     WSS_INSTANCE_ZONE_KEY: 'us-central1-a'
-}, {
-    WSS_INSTANCE_HOST_KEY: 'apprtc-ws-2.webrtc.org:443',
-    WSS_INSTANCE_NAME_KEY: 'wsserver-std-2',
-    WSS_INSTANCE_ZONE_KEY: 'us-central1-f'
+# }, {
+#     WSS_INSTANCE_HOST_KEY: 'apprtc-ws-2.webrtc.org:443',
+#     WSS_INSTANCE_NAME_KEY: 'wsserver-std-2',
+#     WSS_INSTANCE_ZONE_KEY: 'us-central1-f'
 }]
 
 WSS_HOST_PORT_PAIRS = [ins[WSS_INSTANCE_HOST_KEY] for ins in WSS_INSTANCES]
diff --git a/src/collider/collidermain/main.go b/src/collider/collidermain/main.go
index a499ada..5e164dd 100644
--- a/src/collider/collidermain/main.go
+++ b/src/collider/collidermain/main.go
@@ -6,7 +6,7 @@
 package main
 
 import (
-    "collider"
+    "collider/collider"
     "flag"
     "log"
 )
➜  apprtc git:(restapi) ✗
 
 
 
 
最后
由於整個過程過於繁瑣,筆者在實驗過程中寫了Makefile,現也共享傳來。這個Makefile在調試運行過程中缺失帶來了很多便利,不用每次噼里啪啦的敲一堆命令。幾乎包含了上述所有編譯,運行的操作,有了此文件只需make  xxx 就行
 
➜  apprtc git:(restapi) ✗ cat Makefile
all: apprtc auth collidermain
 
apprtc:
  sudo grunt build --force
 
auth: auth.go env
    go build -o auth auth.go
 
collidermain: src/collider/collidermain/main.go env
    go build -o collidermain src/collider/collidermain/main.go
 
clean:
    rm auth
 
env:
    export GOPATH=$(shell pwd)
 
test_auth:
    curl http://localhost:8081/turn
    curl http://localhost:8081/v2/turn
 
 
run_apprtc:
    sudo ../google_appengine//dev_appserver.py ./out/app_engine --host 0.0.0.0    2>&1 | tee app.log
 
run_auth:
    sudo ./auth -port 8081
 
run_collidermain:
    sudo ./collidermain -port 4432 -room-server http://localhost:8080 2>&1 | tee collider.log
 
run_stunnel:
    sudo stunnel
 
run_turnserver:
    sudo turnserver
 
 
.PHONY: all test clean apprtc env
 
 
 
 
體驗
 
參考文章
 
 
未完……


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM