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 insrc
, because apprtc room server will run byout
directory directly, you can also modifysrc
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~
网友评论