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阅读 214,444评论 6 496
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,421评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,036评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,363评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,460评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,502评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,511评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,280评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,736评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,014评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,190评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,848评论 5 338
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,531评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,159评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,411评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,067评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,078评论 2 352

推荐阅读更多精彩内容