├── .gitignore ├── webrtc-build ├── shadowsocks.json ├── polipo.config ├── run.sh ├── Dockerfile └── build.sh ├── apprtc-server ├── turnserver.conf ├── run.sh ├── ice.js ├── apprtc_supervisord.conf ├── Dockerfile └── constants.py ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /.vscode/ -------------------------------------------------------------------------------- /webrtc-build/shadowsocks.json: -------------------------------------------------------------------------------- 1 | { 2 | "server":"server-ip", 3 | "server_port":server-port, 4 | "local_address": "127.0.0.1", 5 | "local_port":1080, 6 | "password":"your-password", 7 | "timeout":600, 8 | "method":"enc-method" 9 | } 10 | -------------------------------------------------------------------------------- /apprtc-server/turnserver.conf: -------------------------------------------------------------------------------- 1 | listening-port=3478 2 | min-port=59000 3 | max-port=65000 4 | fingerprint 5 | lt-cred-mech 6 | use-auth-secret 7 | static-auth-secret=4080218913 8 | realm=apprtc 9 | stale-nonce 10 | no-loopback-peers 11 | no-multicast-peers 12 | mobility 13 | no-cli 14 | no-tlsv1 15 | no-tlsv1_1 16 | -------------------------------------------------------------------------------- /apprtc-server/run.sh: -------------------------------------------------------------------------------- 1 | sed -i "s/SERVER_PUBLIC_IP/${PUBLIC_IP}/g" /ice.js 2 | sed -i 's/wss:\/\//ws:\/\//g' /apprtc/out/app_engine/apprtc.py 3 | sed -i 's/https:\/\//http:\/\//g' /apprtc/out/app_engine/apprtc.py 4 | 5 | sed -i "s/SERVER_PUBLIC_IP/${PUBLIC_IP}/g" /apprtc/out/app_engine/constants.py 6 | 7 | supervisord -c /apprtc_supervisord.conf 8 | -------------------------------------------------------------------------------- /webrtc-build/polipo.config: -------------------------------------------------------------------------------- 1 | # This file only needs to list configuration variables that deviate 2 | # from the default values. See /usr/share/doc/polipo/examples/config.sample 3 | # and "polipo -v" for variables you can tweak and further information. 4 | 5 | logSyslog = true 6 | logFile = /var/log/polipo/polipo.log 7 | 8 | socksParentProxy = "localhost:1080" 9 | socksProxyType = socks5 10 | -------------------------------------------------------------------------------- /webrtc-build/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ "$ENABLE_SHADOW_SOCKS" == "true" ]] 4 | then 5 | sed -i "s/server-ip/$SHADOW_SOCKS_SERVER_ADDR/g" /etc/shadowsocks.json 6 | sed -i "s/server-port/$SHADOW_SOCKS_SERVER_PORT/g" /etc/shadowsocks.json 7 | sed -i "s/enc-method/$SHADOW_SOCKS_ENC_METHOD/g" /etc/shadowsocks.json 8 | sed -i "s/your-password/$SHADOW_SOCKS_ENC_PASS/g" /etc/shadowsocks.json 9 | 10 | sslocal -c /etc/shadowsocks.json -d start -v 11 | export http_proxy=http://localhost:8123 12 | export https_proxy=http://localhost:8123 13 | service polipo stop 14 | service polipo start 15 | bash 16 | else 17 | bash 18 | fi 19 | -------------------------------------------------------------------------------- /apprtc-server/ice.js: -------------------------------------------------------------------------------- 1 | var express = require('express') 2 | var crypto = require('crypto') 3 | var app = express() 4 | 5 | var hmac = function (key, content) { 6 | var method = crypto.createHmac('sha1', key) 7 | method.setEncoding('base64') 8 | method.write(content) 9 | method.end() 10 | return method.read() 11 | } 12 | 13 | function handleIceRequest(req, resp) { 14 | var query = req.query 15 | var key = '4080218913' 16 | var time_to_live = 600 17 | var timestamp = Math.floor(Date.now() / 1000) + time_to_live 18 | var turn_username = timestamp + ':ninefingers' 19 | var password = hmac(key, turn_username) 20 | 21 | return resp.send({ 22 | iceServers: [ 23 | { 24 | urls: [ 25 | 'stun:SERVER_PUBLIC_IP:3478', 26 | 'turn:SERVER_PUBLIC_IP:3478' 27 | ], 28 | username: turn_username, 29 | credential: password 30 | } 31 | ] 32 | }) 33 | } 34 | 35 | app.get('/iceconfig', handleIceRequest) 36 | app.post('/iceconfig', handleIceRequest) 37 | 38 | app.listen('3033', function () { 39 | console.log('server started') 40 | }) 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Piasy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebRTC-Docker 2 | 3 | Out-of-the-box docker images for AppRTC dev/test purpose. 4 | 5 | ## AppRTC-Server 6 | 7 | macOS host: 8 | 9 | ``` bash 10 | docker run --rm \ 11 | -p 8080:8080 -p 8089:8089 -p 3478:3478 -p 3478:3478/udp -p 3033:3033 \ 12 | -p 59000-65000:59000-65000/udp \ 13 | -e PUBLIC_IP= \ 14 | -it piasy/apprtc-server 15 | ``` 16 | 17 | Linux host: 18 | 19 | ``` bash 20 | docker run --rm --net=host \ 21 | -e PUBLIC_IP= \ 22 | -it piasy/apprtc-server 23 | ``` 24 | 25 | About port publish: 26 | 27 | + TCP `8080` is used for room server; 28 | + TCP `8089` is used for signal server; 29 | + TCP `3033` is used for ICE server; 30 | + TCP `3478`, UDP `3478` and UDP `59000-65000` is used for TURN/STUN server; 31 | 32 | So make sure your firewall has opened those ports. 33 | 34 | ## WebRTC-Build 35 | 36 | Only Android/Linux is supported. 37 | 38 | ``` bash 39 | docker run --rm \ 40 | -e ENABLE_SHADOW_SOCKS=true \ 41 | -e SHADOW_SOCKS_SERVER_ADDR= \ 42 | -e SHADOW_SOCKS_SERVER_PORT= \ 43 | -e SHADOW_SOCKS_ENC_METHOD= \ 44 | -e SHADOW_SOCKS_ENC_PASS= \ 45 | -v :/webrtc \ 46 | -it piasy/webrtc-build 47 | ``` 48 | 49 | Note: if your encrypt password contains special characters, remember to escape it with `\`, e.g. `&bDmc!` to `\&bDmc\!`. 50 | 51 | If you don't need run shadowsocks proxy, you can run: 52 | 53 | ``` bash 54 | docker run --rm \ 55 | -v :/webrtc \ 56 | -it piasy/webrtc-build 57 | ``` 58 | 59 | After the docker image started, you can run `fetch`, `gclient`, `gn`, and `ninja` commands to download and build webrtc code. 60 | -------------------------------------------------------------------------------- /webrtc-build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | LABEL maintainer="Piasy Xu (xz4215@gmail.com)" 3 | 4 | WORKDIR / 5 | 6 | ENV ENABLE_SHADOW_SOCKS false 7 | ENV SHADOW_SOCKS_SERVER_ADDR 127.0.0.1 8 | ENV SHADOW_SOCKS_SERVER_PORT 8000 9 | ENV SHADOW_SOCKS_ENC_METHOD encmethod 10 | ENV SHADOW_SOCKS_ENC_PASS encpass 11 | 12 | RUN apt-get update -y 13 | 14 | # Deps 15 | RUN apt-get install -y vim python-pip polipo wget git gnupg flex bison gperf build-essential zip curl subversion pkg-config libglib2.0-dev libgtk2.0-dev libxtst-dev libxss-dev libpci-dev libdbus-1-dev libgconf2-dev libgnome-keyring-dev libnss3-dev lsb-release sudo locales libssl-dev openssl cmake lbzip2 libavcodec-dev libavdevice-dev libavfilter-dev libavformat-dev libswresample-dev libpostproc-dev 16 | RUN pip install shadowsocks 17 | 18 | # libsodium 19 | RUN wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.16.tar.gz 20 | RUN tar zxf libsodium-1.0.16.tar.gz 21 | WORKDIR /libsodium-1.0.16 22 | RUN ./configure && make && make install 23 | RUN echo /usr/local/lib > /etc/ld.so.conf.d/usr_local_lib.conf && ldconfig 24 | 25 | WORKDIR / 26 | COPY shadowsocks.json /etc/shadowsocks.json 27 | COPY polipo.config /etc/polipo/config 28 | 29 | # install webrtc deps 30 | RUN curl https://chromium.googlesource.com/chromium/src/+/master/build/install-build-deps-android.sh?format=TEXT | base64 -d > install-build-deps-android.sh 31 | RUN curl https://chromium.googlesource.com/chromium/src/+/master/build/install-build-deps.sh?format=TEXT | base64 -d > install-build-deps.sh 32 | RUN chmod +x ./install-build-deps.sh 33 | RUN chmod +x ./install-build-deps-android.sh 34 | RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections 35 | RUN ./install-build-deps-android.sh 36 | 37 | # depot tools 38 | WORKDIR / 39 | RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git 40 | 41 | RUN echo 'export PATH=$PATH:/depot_tools' >> /root/.bashrc 42 | COPY run.sh / 43 | RUN chmod +x /run.sh 44 | 45 | CMD /run.sh 46 | -------------------------------------------------------------------------------- /apprtc-server/apprtc_supervisord.conf: -------------------------------------------------------------------------------- 1 | [unix_http_server] 2 | file=/webrtc_avconf/supervisor.sock 3 | 4 | [supervisord] 5 | logfile = /webrtc_avconf/supervisord.log 6 | logfile_maxbytes = 20MB 7 | logfile_backups=500 8 | loglevel = info 9 | pidfile = /webrtc_avconf/supervisord.pid 10 | nodaemon=true 11 | minfds=1024 12 | minprocs=200 13 | 14 | [rpcinterface:supervisor] 15 | supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface 16 | 17 | [supervisorctl] 18 | serverurl=unix:///webrtc_avconf/supervisor.sock 19 | 20 | [eventlistener:dependentstartup] 21 | command=/usr/local/bin/supervisord-dependent-startup -c /apprtc_supervisord.conf 22 | stderr_logfile=/webrtc_avconf/supervisor-%(program_name)s-err.log 23 | autostart=true 24 | events=PROCESS_STATE 25 | 26 | [program:ice_server] 27 | command = nodejs /ice.js 28 | stdout_logfile = /webrtc_avconf/ice_server.log 29 | stdout_logfile_maxbytes = 20MB 30 | stdout_logfile_backups = 500 31 | stderr_logfile = /webrtc_avconf/ice_server.err.log 32 | stderr_logfile_maxbytes = 20MB 33 | stderr_logfile_backups = 500 34 | startsecs=3 35 | autostart=false 36 | dependent_startup=true 37 | 38 | [program:collider] 39 | command = /goWorkspace/bin/collidermain -port=8089 -tls=false --room-server=0.0.0.0 40 | stdout_logfile = /webrtc_avconf/collider.log 41 | stdout_logfile_maxbytes = 20MB 42 | stdout_logfile_backups = 500 43 | stderr_logfile = /webrtc_avconf/collider.err.log 44 | stderr_logfile_maxbytes = 20MB 45 | stderr_logfile_backups = 500 46 | startsecs=3 47 | autostart=false 48 | dependent_startup=true 49 | 50 | [program:apprtc_rs] 51 | command = dev_appserver.py /apprtc/out/app_engine --skip_sdk_update_check --enable_host_checking=False --host=0.0.0.0 52 | stdout_logfile = /webrtc_avconf/apprtc_rs.log 53 | stdout_logfile_maxbytes = 20MB 54 | stdout_logfile_backups = 500 55 | stderr_logfile = /webrtc_avconf/apprtc_rs.err.log 56 | stderr_logfile_maxbytes = 20MB 57 | stderr_logfile_backups = 500 58 | startsecs=3 59 | autostart=false 60 | dependent_startup=true 61 | 62 | [program:turnserver] 63 | command = turnserver -v -L 0.0.0.0 -a -f -r apprtc -c /etc/turnserver.conf --no-tls --no-dtls 64 | stdout_logfile = /webrtc_avconf/turnserver.log 65 | stdout_logfile_maxbytes = 20MB 66 | stdout_logfile_backups = 500 67 | stderr_logfile = /webrtc_avconf/turnserver.err.log 68 | stderr_logfile_maxbytes = 20MB 69 | stderr_logfile_backups = 500 70 | startsecs=3 71 | autostart=false 72 | dependent_startup=true 73 | -------------------------------------------------------------------------------- /apprtc-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | LABEL maintainer="Piasy Xu (xz4215@gmail.com)" 3 | 4 | EXPOSE 8080 8089 3478 3033 59000-65000 5 | 6 | WORKDIR / 7 | 8 | ENV GAE_VER 1.9.74 9 | ENV GOLANG_VER 1.8.3 10 | ENV LIBEVENT_VER 2.1.8 11 | ENV COTURN_VER 4.5.0.7 12 | 13 | ENV PUBLIC_IP 127.0.0.1 14 | 15 | RUN apt-get update -y 16 | 17 | # Deps 18 | RUN apt-get install -y build-essential vim git curl wget unzip python2.7 python-pil python-webtest python-pip libssl-dev openjdk-8-jdk && \ 19 | rm -rf /usr/lib/python2.7/dist-packages/supervisor* && \ 20 | pip install supervisor requests && \ 21 | pip install git+https://github.com/bendikro/supervisord-dependent-startup 22 | 23 | # NodeJS 24 | RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - 25 | RUN apt-get install -y nodejs 26 | 27 | # Golang 28 | ENV GOLANG_TAR go$GOLANG_VER.linux-amd64.tar.gz 29 | RUN wget https://storage.googleapis.com/golang/$GOLANG_TAR 30 | RUN tar -C /usr/local -xzf $GOLANG_TAR 31 | ENV PATH $PATH:/usr/local/go/bin 32 | ENV GOPATH /goWorkspace 33 | RUN mkdir -p $GOPATH/src 34 | 35 | # Google App Engine 36 | ENV GAE_ZIP google_appengine_$GAE_VER.zip 37 | RUN wget https://storage.googleapis.com/appengine-sdks/featured/$GAE_ZIP 38 | RUN unzip $GAE_ZIP -d /usr/local 39 | ENV PATH $PATH:/usr/local/google_appengine 40 | 41 | # Coturn server 42 | RUN wget https://github.com/libevent/libevent/releases/download/release-$LIBEVENT_VER-stable/libevent-$LIBEVENT_VER-stable.tar.gz 43 | RUN tar xvfz libevent-$LIBEVENT_VER-stable.tar.gz 44 | WORKDIR libevent-$LIBEVENT_VER-stable 45 | RUN ./configure && make && make install 46 | WORKDIR / 47 | RUN wget http://turnserver.open-sys.org/downloads/v$COTURN_VER/turnserver-$COTURN_VER.tar.gz 48 | RUN tar xvfz turnserver-$COTURN_VER.tar.gz 49 | WORKDIR turnserver-$COTURN_VER 50 | RUN ./configure && make && make install 51 | RUN turnadmin -a -u ninefingers -r apprtc -p youhavetoberealistic 52 | COPY turnserver.conf /etc/turnserver.conf 53 | 54 | # AppRTC 55 | WORKDIR / 56 | RUN git clone https://github.com/webrtc/apprtc.git 57 | 58 | WORKDIR apprtc 59 | 60 | RUN ln -s /apprtc/src/collider/collider $GOPATH/src 61 | RUN ln -s /apprtc/src/collider/collidermain $GOPATH/src 62 | RUN ln -s /apprtc/src/collider/collidertest $GOPATH/src 63 | RUN go get collidermain 64 | RUN go install collidermain 65 | 66 | RUN npm install -g npm 67 | RUN npm install -g grunt-cli 68 | 69 | RUN npm install 70 | RUN grunt build 71 | 72 | WORKDIR / 73 | 74 | RUN npm install express 75 | COPY ice.js / 76 | COPY constants.py /apprtc/out/app_engine/constants.py 77 | 78 | # Clean up APT when done. 79 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 80 | 81 | COPY apprtc_supervisord.conf / 82 | 83 | COPY run.sh / 84 | RUN chmod +x /run.sh 85 | CMD /run.sh 86 | -------------------------------------------------------------------------------- /apprtc-server/constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc. All Rights Reserved. 2 | 3 | """AppRTC Constants. 4 | This module contains the constants used in AppRTC Python modules. 5 | """ 6 | import os 7 | 8 | # Deprecated domains which we should to redirect to REDIRECT_URL. 9 | REDIRECT_DOMAINS = [ 10 | 'apprtc.appspot.com', 'apprtc.webrtc.org', 'www.appr.tc' 11 | ] 12 | # URL which we should redirect to if matching in REDIRECT_DOMAINS. 13 | REDIRECT_URL = 'https://appr.tc' 14 | 15 | ROOM_MEMCACHE_EXPIRATION_SEC = 60 * 60 * 24 16 | MEMCACHE_RETRY_LIMIT = 100 17 | 18 | LOOPBACK_CLIENT_ID = 'LOOPBACK_CLIENT_ID' 19 | 20 | # Turn/Stun server override. This allows AppRTC to connect to turn servers 21 | # directly rather than retrieving them from an ICE server provider. 22 | ICE_SERVER_OVERRIDE = None 23 | # Enable by uncomment below and comment out above, then specify turn and stun 24 | # ICE_SERVER_OVERRIDE = [ 25 | # { 26 | # "urls": [ 27 | # "turn:hostname/IpToTurnServer:19305?transport=udp", 28 | # "turn:hostname/IpToTurnServer:19305?transport=tcp" 29 | # ], 30 | # "username": "TurnServerUsername", 31 | # "credential": "TurnServerCredentials" 32 | # }, 33 | # { 34 | # "urls": [ 35 | # "stun:hostname/IpToStunServer:19302" 36 | # ] 37 | # } 38 | # ] 39 | 40 | ICE_SERVER_BASE_URL = 'http://SERVER_PUBLIC_IP:3033' 41 | ICE_SERVER_URL_TEMPLATE = '%s/iceconfig?key=%s' 42 | ICE_SERVER_API_KEY = os.environ.get('ICE_SERVER_API_KEY') 43 | 44 | # Dictionary keys in the collider instance info constant. 45 | WSS_INSTANCE_HOST_KEY = 'host_port_pair' 46 | WSS_INSTANCE_NAME_KEY = 'vm_name' 47 | WSS_INSTANCE_ZONE_KEY = 'zone' 48 | WSS_INSTANCES = [{ 49 | WSS_INSTANCE_HOST_KEY: 'SERVER_PUBLIC_IP:8089', 50 | WSS_INSTANCE_NAME_KEY: 'wsserver-std', 51 | WSS_INSTANCE_ZONE_KEY: 'us-central1-a' 52 | }] 53 | 54 | WSS_HOST_PORT_PAIRS = [ins[WSS_INSTANCE_HOST_KEY] for ins in WSS_INSTANCES] 55 | 56 | # memcache key for the active collider host. 57 | WSS_HOST_ACTIVE_HOST_KEY = 'wss_host_active_host' 58 | 59 | # Dictionary keys in the collider probing result. 60 | WSS_HOST_IS_UP_KEY = 'is_up' 61 | WSS_HOST_STATUS_CODE_KEY = 'status_code' 62 | WSS_HOST_ERROR_MESSAGE_KEY = 'error_message' 63 | 64 | RESPONSE_ERROR = 'ERROR' 65 | RESPONSE_ROOM_FULL = 'FULL' 66 | RESPONSE_UNKNOWN_ROOM = 'UNKNOWN_ROOM' 67 | RESPONSE_UNKNOWN_CLIENT = 'UNKNOWN_CLIENT' 68 | RESPONSE_DUPLICATE_CLIENT = 'DUPLICATE_CLIENT' 69 | RESPONSE_SUCCESS = 'SUCCESS' 70 | RESPONSE_INVALID_REQUEST = 'INVALID_REQUEST' 71 | 72 | IS_DEV_SERVER = os.environ.get('APPLICATION_ID', '').startswith('dev') 73 | 74 | BIGQUERY_URL = 'https://www.googleapis.com/auth/bigquery' 75 | 76 | # Dataset used in production. 77 | BIGQUERY_DATASET_PROD = 'prod' 78 | 79 | # Dataset used when running locally. 80 | BIGQUERY_DATASET_LOCAL = 'dev' 81 | 82 | # BigQuery table within the dataset. 83 | BIGQUERY_TABLE = 'analytics' 84 | -------------------------------------------------------------------------------- /webrtc-build/build.sh: -------------------------------------------------------------------------------- 1 | # !/bin/bash 2 | # Copyright Pristine Inc 3 | # Author: Rahul Behera 4 | # Author: Aaron Alaniz 5 | # Author: Arik Yaacob 6 | # 7 | # Builds the android peer connection library 8 | 9 | # Get location of the script itself .. thanks SO ! http://stackoverflow.com/a/246128 10 | SOURCE="${BASH_SOURCE[0]}" 11 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink 12 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 13 | SOURCE="$(readlink "$SOURCE")" 14 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located 15 | done 16 | PROJECT_ROOT="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 17 | 18 | # Utility method for creating a directory 19 | create_directory_if_not_found() { 20 | # if we cannot find the directory 21 | if [ ! -d "$1" ]; 22 | then 23 | echo "$1 directory not found, creating..." 24 | mkdir -p "$1" 25 | echo "directory created at $1" 26 | fi 27 | } 28 | 29 | DEFAULT_WEBRTC_URL="https://webrtc.googlesource.com/src.git" 30 | WEBRTC_ROOT="$PROJECT_ROOT/webrtc" 31 | DEPOT_TOOLS="$WEBRTC_ROOT/depot_tools" 32 | create_directory_if_not_found "$WEBRTC_ROOT" 33 | BUILD="$WEBRTC_ROOT/libjingle_peerconnection_builds" 34 | WEBRTC_TARGET="AppRTCMobile" 35 | 36 | ANDROID_TOOLCHAINS="$WEBRTC_ROOT/src/third_party/android_tools/ndk/toolchains" 37 | 38 | exec_ninja() { 39 | echo "Running ninja" 40 | ninja -C $1 $WEBRTC_TARGET 41 | } 42 | 43 | # Installs the required dependencies on the machine 44 | install_dependencies() { 45 | sudo apt-get -y install wget git gnupg flex bison gperf build-essential zip curl subversion pkg-config libglib2.0-dev libgtk2.0-dev libxtst-dev libxss-dev libpci-dev libdbus-1-dev libgconf2-dev libgnome-keyring-dev libnss3-dev 46 | #Download the latest script to install the android dependencies for ubuntu 47 | curl https://chromium.googlesource.com/chromium/src/+/master/build/install-build-deps-android.sh?format=TEXT | base64 -d > install-build-deps-android.sh 48 | curl https://chromium.googlesource.com/chromium/src/+/master/build/install-build-deps.sh?format=TEXT | base64 -d > install-build-deps.sh 49 | chmod u+x ./install-build-deps.sh 50 | #use bash (not dash which is default) to run the script 51 | sudo /bin/bash ./install-build-deps-android.sh 52 | #delete the file we just downloaded... not needed anymore 53 | #rm install-build-deps-android.sh 54 | } 55 | 56 | # Update/Get/Ensure the Gclient Depot Tools 57 | # Also will add to your environment 58 | pull_depot_tools() { 59 | WORKING_DIR=`pwd` 60 | 61 | # Either clone or get latest depot tools 62 | if [ ! -d "$DEPOT_TOOLS" ] 63 | then 64 | echo Make directory for gclient called Depot Tools 65 | mkdir -p "$DEPOT_TOOLS" 66 | 67 | echo Pull the depo tools project from chromium source into the depot tools directory 68 | git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $DEPOT_TOOLS 69 | 70 | else 71 | echo Change directory into the depot tools 72 | cd "$DEPOT_TOOLS" 73 | 74 | echo Pull the depot tools down to the latest 75 | git pull 76 | fi 77 | PATH="$PATH:$DEPOT_TOOLS" 78 | 79 | # Navigate back 80 | cd "$WORKING_DIR" 81 | } 82 | 83 | # Update/Get the webrtc code base 84 | pull_webrtc() { 85 | WORKING_DIR=`pwd` 86 | 87 | # If no directory where webrtc root should be... 88 | create_directory_if_not_found "$WEBRTC_ROOT" 89 | cd "$WEBRTC_ROOT" 90 | 91 | # Setup gclient config 92 | echo Configuring gclient for Android build 93 | if [ -z $USER_WEBRTC_URL ] 94 | then 95 | echo "User has not specified a different webrtc url. Using default" 96 | gclient config --name=src "$DEFAULT_WEBRTC_URL" 97 | else 98 | echo "User has specified their own webrtc url $USER_WEBRTC_URL" 99 | gclient config --name=src "$USER_WEBRTC_URL" 100 | fi 101 | 102 | # Ensure our target os is correct building android 103 | echo 'target_os = ["ios", "mac", "linux", "android", "unix"]' >> .gclient 104 | gclient runhooks 105 | 106 | # Get latest webrtc source 107 | echo Pull down the latest from the webrtc repo 108 | echo this can take a while 109 | if [ -z $1 ] 110 | then 111 | echo "gclient sync with newest" 112 | gclient sync 113 | else 114 | echo "gclient sync with $1" 115 | gclient sync -r $1 116 | fi 117 | 118 | # Navigate back 119 | cd "$WORKING_DIR" 120 | } 121 | 122 | # Prepare our build 123 | function wrbase() { 124 | export GYP_DEFINES="host_os=linux libjingle_java=1 build_with_libjingle=1 build_with_chromium=0 enable_tracing=1 enable_android_opensl=0 use_sysroot=0 include_tests=0" 125 | if [ "$WEBRTC_DEBUG" != "true" ] ; 126 | then 127 | export GYP_DEFINES="$GYP_DEFINES fastbuild=2" 128 | fi 129 | export GYP_GENERATORS="ninja" 130 | } 131 | 132 | # Arm V7 with Neon 133 | function wrarmv7() { 134 | wrbase 135 | export GYP_DEFINES="$GYP_DEFINES OS=android" 136 | export GYP_GENERATOR_FLAGS="$GYP_GENERATOR_FLAGS output_dir=out/android_armeabi-v7a" 137 | export GYP_CROSSCOMPILE=1 138 | echo "ARMv7 with Neon Build" 139 | } 140 | 141 | # Arm 64 142 | function wrarmv8() { 143 | wrbase 144 | export GYP_DEFINES="$GYP_DEFINES OS=android target_arch=arm64 target_subarch=arm64" 145 | export GYP_GENERATOR_FLAGS="output_dir=out/android_arm64-v8a" 146 | export GYP_CROSSCOMPILE=1 147 | echo "ARMv8 with Neon Build" 148 | } 149 | 150 | # x86 151 | function wrX86() { 152 | wrbase 153 | export GYP_DEFINES="$GYP_DEFINES OS=android target_arch=ia32" 154 | export GYP_GENERATOR_FLAGS="output_dir=out/android_x86" 155 | echo "x86 Build" 156 | } 157 | 158 | # x86_64 159 | function wrX86_64() { 160 | wrbase 161 | export GYP_DEFINES="$GYP_DEFINES OS=android target_arch=x64" 162 | export GYP_GENERATOR_FLAGS="output_dir=out/android_x86_64" 163 | echo "x86_64 Build" 164 | } 165 | 166 | 167 | # Setup our defines for the build 168 | prepare_gyp_defines() { 169 | # Configure environment for Android 170 | echo Setting up build environment for Android 171 | source "$WEBRTC_ROOT/src/build/android/envsetup.sh" 172 | 173 | # Check to see if the user wants to set their own gyp defines 174 | echo Export the base settings of GYP_DEFINES so we can define how we want to build 175 | if [ -z $USER_GYP_DEFINES ] 176 | then 177 | echo "User has not specified any gyp defines so we proceed with default" 178 | if [ "$WEBRTC_ARCH" = "x86" ] ; 179 | then 180 | wrX86 181 | elif [ "$WEBRTC_ARCH" = "x86_64" ] ; 182 | then 183 | wrX86_64 184 | elif [ "$WEBRTC_ARCH" = "armv7" ] ; 185 | then 186 | wrarmv7 187 | elif [ "$WEBRTC_ARCH" = "armv8" ] ; 188 | then 189 | wrarmv8 190 | fi 191 | else 192 | echo "User has specified their own gyp defines" 193 | export GYP_DEFINES="$USER_GYP_DEFINES" 194 | fi 195 | 196 | echo "GYP_DEFINES=$GYP_DEFINES" 197 | } 198 | 199 | # Builds the apprtc demo 200 | execute_build() { 201 | WORKING_DIR=`pwd` 202 | cd "$WEBRTC_ROOT/src" 203 | 204 | if [ "$WEBRTC_ARCH" = "x86" ] ; 205 | then 206 | ARCH="x86" 207 | STRIP="$ANDROID_TOOLCHAINS/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-strip" 208 | elif [ "$WEBRTC_ARCH" = "x86_64" ] ; 209 | then 210 | ARCH="x64" 211 | STRIP="$ANDROID_TOOLCHAINS/x86_64-4.9/prebuilt/linux-x86_64/bin/x86_64-linux-android-strip" 212 | elif [ "$WEBRTC_ARCH" = "armv7" ] ; 213 | then 214 | ARCH="arm" 215 | STRIP="$ANDROID_TOOLCHAINS/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip" 216 | elif [ "$WEBRTC_ARCH" = "armv8" ] ; 217 | then 218 | ARCH="arm64" 219 | STRIP="$ANDROID_TOOLCHAINS/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip" 220 | fi 221 | 222 | if [ "$WEBRTC_DEBUG" = "true" ] ; 223 | then 224 | BUILD_TYPE="Debug" 225 | DEBUG_ARG='is_debug=true' 226 | else 227 | BUILD_TYPE="Release" 228 | DEBUG_ARG='is_debug=false dcheck_always_on=true' 229 | fi 230 | 231 | ARCH_OUT="out/android_${ARCH}" 232 | 233 | echo Generate projects using GN 234 | gn gen "$ARCH_OUT/$BUILD_TYPE" --args="$DEBUG_ARG symbol_level=1 target_os=\"android\" target_cpu=\"${ARCH}\"" 235 | #gclient runhooks 236 | 237 | REVISION_NUM=`get_webrtc_revision` 238 | echo "Build ${WEBRTC_TARGET} in $BUILD_TYPE (arch: ${WEBRTC_ARCH})" 239 | exec_ninja "$ARCH_OUT/$BUILD_TYPE" 240 | 241 | # Verify the build actually worked 242 | if [ $? -eq 0 ]; then 243 | SOURCE_DIR="$WEBRTC_ROOT/src/$ARCH_OUT/$BUILD_TYPE" 244 | TARGET_DIR="$BUILD/$BUILD_TYPE" 245 | create_directory_if_not_found "$TARGET_DIR" 246 | 247 | echo "Copy JAR File" 248 | create_directory_if_not_found "$TARGET_DIR/libs/" 249 | create_directory_if_not_found "$TARGET_DIR/jni/" 250 | 251 | if [ "$WEBRTC_ARCH" = "x86" ] ; 252 | then 253 | ARCH_JNI="$TARGET_DIR/jni/x86" 254 | elif [ "$WEBRTC_ARCH" = "x86_64" ] ; 255 | then 256 | ARCH_JNI="$TARGET_DIR/jni/x86_64" 257 | elif [ "$WEBRTC_ARCH" = "armv7" ] ; 258 | then 259 | ARCH_JNI="$TARGET_DIR/jni/armeabi-v7a" 260 | elif [ "$WEBRTC_ARCH" = "armv8" ] ; 261 | then 262 | ARCH_JNI="$TARGET_DIR/jni/arm64-v8a" 263 | fi 264 | create_directory_if_not_found "$ARCH_JNI" 265 | 266 | # Copy the jars 267 | cp -p "$SOURCE_DIR/lib.java/sdk/android/libjingle_peerconnection_java.jar" "$TARGET_DIR/libs/libjingle_peerconnection.jar" 268 | cp -p "$SOURCE_DIR/lib.java/rtc_base/base_java.jar" "$TARGET_DIR/libs/base_java.jar" 269 | cp -p "$SOURCE_DIR/lib.java/modules/audio_device/audio_device_java.jar" "$TARGET_DIR/libs/audio_device_java.jar" 270 | 271 | # Strip the build only if its release 272 | if [ "$WEBRTC_DEBUG" = "true" ] ; 273 | then 274 | cp -p "$WEBRTC_ROOT/src/$ARCH_OUT/$BUILD_TYPE/libjingle_peerconnection_so.so" "$ARCH_JNI/libjingle_peerconnection_so.so" 275 | else 276 | "$STRIP" -o "$ARCH_JNI/libjingle_peerconnection_so.so" "$WEBRTC_ROOT/src/$ARCH_OUT/$BUILD_TYPE/libjingle_peerconnection_so.so" -s 277 | fi 278 | 279 | cd "$TARGET_DIR" 280 | mkdir -p aidl 281 | mkdir -p assets 282 | mkdir -p res 283 | 284 | cd "$WORKING_DIR" 285 | echo "$BUILD_TYPE build for apprtc complete for revision $REVISION_NUM" 286 | else 287 | 288 | echo "$BUILD_TYPE build for apprtc failed for revision $REVISION_NUM" 289 | #exit 1 290 | fi 291 | } 292 | 293 | # Gets the webrtc revision 294 | get_webrtc_revision() { 295 | DIR=`pwd` 296 | cd "$WEBRTC_ROOT/src" 297 | REVISION_NUMBER=`git log -1 | grep 'Cr-Commit-Position: refs/heads/master@{#' | egrep -o "[0-9]+}" | tr -d '}'` 298 | 299 | if [ -z "$REVISION_NUMBER" ] 300 | then 301 | REVISION_NUMBER=`git describe --tags | sed 's/\([0-9]*\)-.*/\1/'` 302 | fi 303 | 304 | if [ -z "$REVISION_NUMBER" ] 305 | then 306 | echo "Error grabbing revision number" 307 | exit 1 308 | fi 309 | 310 | echo $REVISION_NUMBER 311 | cd "$DIR" 312 | } 313 | 314 | get_webrtc() { 315 | pull_depot_tools && 316 | pull_webrtc $1 317 | } 318 | 319 | # Updates webrtc and builds apprtc 320 | build_apprtc() { 321 | export WEBRTC_ARCH=armv7 322 | prepare_gyp_defines && 323 | execute_build 324 | 325 | export WEBRTC_ARCH=armv8 326 | prepare_gyp_defines && 327 | execute_build 328 | 329 | export WEBRTC_ARCH=x86 330 | prepare_gyp_defines && 331 | execute_build 332 | 333 | export WEBRTC_ARCH=x86_64 334 | prepare_gyp_defines && 335 | execute_build 336 | } 337 | --------------------------------------------------------------------------------