AppRTC Configuration On Ubuntu 16.04

I tried again and again and again to successfully configure AppRTC on Ubuntu 16.04...These are all my hard steps.

1. Get Google APP Engine

Please download here. Then add export PATH=$PATH:$yourpath/google_appengine to /~.bashrc, and run source ~/.bashrc.

2. Configure AppRTC Room Server

Please download here.
Edit$yourpath/apprtc/out/app_engine/apprtc.py, and change all wss: and https: to ws: and http:. (Maybe something has been changed by me in the download files.)
Edit$yourpath/apprtc/out/app_engine/constants.py and modify the file like this

# WEBRTC_URL is your server ip.
TURN_BASE_URL = 'http://WEBRTC_URL'
TURN_URL_TEMPLATE = '%s/turn?username=%s&key=%s'
CEOD_KEY = '4080218913'

# Dictionary keys in the collider instance info constant.
WSS_INSTANCE_HOST_KEY = 'host_port_pair'
WSS_INSTANCE_NAME_KEY = 'vm_name'
WSS_INSTANCE_ZONE_KEY = 'zone'
WSS_INSTANCES = [{
    WSS_INSTANCE_HOST_KEY: 'WEBRTC_URL:8089',
    WSS_INSTANCE_NAME_KEY: 'wsserver-std',
    WSS_INSTANCE_ZONE_KEY: 'us-central1-a'
}, {
    WSS_INSTANCE_HOST_KEY: 'WEBRTC_URL:8089',
    WSS_INSTANCE_NAME_KEY: 'wsserver-std-2',
    WSS_INSTANCE_ZONE_KEY: 'us-central1-f'
}]

All the files modified are from the out directory, which is different from other suggestions that we should modify files in src, because apprtc room server will run by out directory directly, you can also modify src and rebuild apprtc by nodejs, of course.

3. Use a Independent Collider

Many blogs suggest installing collider server by GO, but it may be a long and tough way to finish, you can download a compiled one here, you need no GO and you don't to have to step over the GFW.

Enter $yourpath/collider/src/collidermain and 'nano main.go', modify corresponding slot to

// WEBRTC_URL is your server ip.
var roomSrv = flag.String("room-server", "http://WEBRTC_URL:8080", "The origin of the room server")\

4. Install Coturn server

Install

Run the followings to install coturn

git clone https://github.com/coturn/coturn
cd coturn
./configure
make
make install

or you can download a conturn server from http://turnserver.open-sys.org/downloads/v4.4.5.3/turnserver-4.4.5.3-debian-wheezy-ubuntu-mint-x86-64bits.tar.gz
and

tar -zxvf turnserver-4.4.5.3-debian-wheezy-ubuntu-mint-x86-64bits.tar.gz
cat INSTALL  # it is a readme file, follow it
sudo apt-get install gdebi-core
sudo gdebi coturn_4.2.2.2-1_i386.deb

Create Config File

Make a file named turnserver.conf adding these

# WEBRTC_URL is your server ip.
listening-device=eth1
listening-ip=WEBRTC_URL
min-port=59000
max-port=65000
relay-device=eth1
relay-ip=WEBRTC_URL
Verbose
fingerprint
lt-cred-mech
use-auth-secret
static-auth-secret=4080218913
stale-nonce
realm=WEBRTC_URL
cert=/etc/turn_server_cert.pem
pkey=/etc/turn_server_pkey.pem
no-loopback-peers
no-multicast-peers
mobility
no-cli

Generate Key

Generate some required keys

sudo openssl req -x509 -newkey  rsa:2048 -keyout /etc/turn_server_pkey.pem -out /etc/turn_server_cert.pem -days 99999 -nodes

Prepare a TURN REST API

Make a file named turn.js adding these

// WEBRTC_URL is your server ip.
var express = require('express');
var crypto = require('crypto');
var app = express();

var hmac = function(key, content){
    var method = crypto.createHmac('sha1', key);
    method.setEncoding('base64');
    method.write(content);
    method.end();
    return method.read();
};

app.get('/turn', function(req, resp) {

var query = req.query;
var key = '4080218913'; 

if (!query['username']) {
    return resp.send({'error':'AppError', 'message':'Must provide username.'});
} else {
    var time_to_live = 600;
    var timestamp = Math.floor(Date.now() / 1000) + time_to_live;
    var turn_username = timestamp + ':' + query['username'];
    var password = hmac(key, turn_username);

    return resp.send({
        username:turn_username,
        password:password,
        ttl:time_to_live,
        "uris": [
            "turn:WEBRTC_URL:3478?transport=udp",
            "turn:WEBRTC_URL:3478?transport=tcp",
            "turn:WEBRTC_URL:3479?transport=udp",
            "turn:WEBRTC_URL.233:3479?transport=tcp"
            ]
    });
}

});

app.listen('3033', function(){
    console.log('server started');
});

5. Nginx

Run apt-get install nginx to install nginx conveniently, and modify the config file default in /etc/nginx/sites-available.

# WEBRTC_URL is your server ip.
server {

        listen       80 default;

        server_name WEBRTC_URL;

        location /turn
        {
                proxy_pass http://WEBRTC_URL:3033;
                proxy_set_header Host $host;
        }

        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'POST,GET';
        add_header 'Access-Control-Allow-Headers' 'x-session-id,user_id,x-requested-with,content-type';

        access_log  /etc/access.log;
}

Run nginx -s reload to check and restart.

6. Start Services

Firstly, you should know you PC inner net ip address, you can get it by ifconfig -a | grep 'inet ' | cut -d ':' -f 2 |cut -d ' ' -f 1 | grep -v '^127', and if you want a internet WebRTC, you need a internet ip address to replace all WEBRTC_URL above. If not (you just want to test WebRTC in your inner net), you can use your PC inner net ip address instead.
You can write a shell like

#!/bin/sh

local_url=$(ifconfig -a | grep 'inet ' | cut -d ':' -f 2 |cut -d ' ' -f 1 | grep -v '^127')
webrtc_url=WEBRTC_URL # Change to your url here

nohup dev_appserver.py --port 8091  --admin_port 8050 --admin_host $local_url --host $local_url --skip_sdk_update_check=yes $yourpath/apprtc/out/app_engine/ 2>stderr1.log &
nohup $yourpath/collider/bin/./collidermain -port=8089 -tls=false -room-server=http://$webrtc_url 2>stderr2.log &
nohup nodejs $yourpath/turn.js >/dev/null 2>stderr3.log &
nohup turnserver -c $yourpath/turnserver.conf -o -v >/dev/null 2>stderr4.log
exit 0

to start all the service.

Open your browser and enter http://WEBRTC_URL:8091(Firefox or 360 explorer (Chrome mode) are required.).

Done, Done, Done! Welcome to communicate with me if you have any problem~

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,619評論 6 539
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,155評論 3 425
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 177,635評論 0 382
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,539評論 1 316
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,255評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,646評論 1 326
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,655評論 3 444
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,838評論 0 289
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,399評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,146評論 3 356
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,338評論 1 372
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,893評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,565評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,983評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,257評論 1 292
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,059評論 3 397
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,296評論 2 376

推薦閱讀更多精彩內容