环境:vmware虚拟机ubuntu14.04
注意
1.上网模式要桥接哦
2.切换到root模式
sudo -i
1.更换阿里源
修改source.list
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trustymain restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
2.安装必备依赖
各种依赖
apt-get install git unzip lrzsz nodejs npm automake autoconf libtool nodejs-legacy python-webtest golang vim -y
apt-get install openssh-server openssh-client -y
安装jdk1.8
add-apt-repository ppa:openjdk-r/ppa;apt-get update;apt-get install openjdk-8-jdk -y;
3.升级npm,安装grunt
npm最新版本安装方法
1、安装npm
sudo apt-get install npm
2、升级npm为最新版本
sudo npm install npm@latest -g
此时通过npm -v可以发现npm版本号为最新版本3.10.3;
3、安装用于安装nodejs的模块n
sudo npm install -g n
4、然后通过n模块安装指定版本的nodejs,n模块更多介绍请参考官方文档
//安装官方最新版本 sudo n latest //安装官方稳定版本 sudo n stable
更新完成之后可能需要重启terminal或者系统
npm config set registry https://registry.npm.taobao.org
npm info underscore
npm -g install grunt-cli
4.搞apprtc源码
sudo -i
cd /root
git clone https://github.com/webrtc/apprtc.git
备份源码
tar czf apprtc.tar.gz apprtc/
安装依赖
npm install
有时候报权限错误,需要加sudo
编译
grunt build
遇到问题要多看看,复制错误日志谷歌即可
5.修改配置文件
constant.py
修改成如下就可以,注意替换成你自己的ip地址
# Copyright 2015 Google Inc. All Rights Reserved.
"""AppRTC Constants.
This module contains the constants used in AppRTC Python modules.
"""
import os
# Deprecated domains which we should to redirect to REDIRECT_URL.
REDIRECT_DOMAINS = [
'apprtc.appspot.com', 'apprtc.webrtc.org', 'www.appr.tc'
]
# URL which we should redirect to if matching in REDIRECT_DOMAINS.
REDIRECT_URL = 'https://appr.tc'
ROOM_MEMCACHE_EXPIRATION_SEC = 60 * 60 * 24
MEMCACHE_RETRY_LIMIT = 100
LOOPBACK_CLIENT_ID = 'LOOPBACK_CLIENT_ID'
# Turn/Stun server override. This allows AppRTC to connect to turn servers
# directly rather than retrieving them from an ICE server provider.
ICE_SERVER_OVERRIDE = None
# Enable by uncomment below and comment out above, then specify turn and stun
# ICE_SERVER_OVERRIDE = [
# {
# "urls": [
# "turn:hostname/IpToTurnServer:19305?transport=udp",
# "turn:hostname/IpToTurnServer:19305?transport=tcp"
# ],
# "username": "TurnServerUsername",
# "credential": "TurnServerCredentials"
# },
# {
# "urls": [
# "stun:hostname/IpToStunServer:19302"
# ]
# }
# ]
TURN_BASE_URL = 'http://192.168.23.114'
TURN_URL_TEMPLATE = '%s/turn?username=%s&key=%s'
CEOD_KEY = '4080218913'
ICE_SERVER_BASE_URL = 'http://192.168.23.114'
ICE_SERVER_URL_TEMPLATE = '%s/v1alpha/iceconfig?key=%s'
ICE_SERVER_API_KEY = os.environ.get('ICE_SERVER_API_KEY')
# 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: '192.168.23.114:8089',
WSS_INSTANCE_NAME_KEY: 'wsserver-std',
WSS_INSTANCE_ZONE_KEY: 'us-central1-a'
}, {
WSS_INSTANCE_HOST_KEY: '192.168.23.114:8089',
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]
# memcache key for the active collider host.
WSS_HOST_ACTIVE_HOST_KEY = 'wss_host_active_host'
# Dictionary keys in the collider probing result.
WSS_HOST_IS_UP_KEY = 'is_up'
WSS_HOST_STATUS_CODE_KEY = 'status_code'
WSS_HOST_ERROR_MESSAGE_KEY = 'error_message'
RESPONSE_ERROR = 'ERROR'
RESPONSE_ROOM_FULL = 'FULL'
RESPONSE_UNKNOWN_ROOM = 'UNKNOWN_ROOM'
RESPONSE_UNKNOWN_CLIENT = 'UNKNOWN_CLIENT'
RESPONSE_DUPLICATE_CLIENT = 'DUPLICATE_CLIENT'
RESPONSE_SUCCESS = 'SUCCESS'
RESPONSE_INVALID_REQUEST = 'INVALID_REQUEST'
IS_DEV_SERVER = os.environ.get('APPLICATION_ID', '').startswith('dev')
BIGQUERY_URL = 'https://www.googleapis.com/auth/bigquery'
# Dataset used in production.
BIGQUERY_DATASET_PROD = 'prod'
# Dataset used when running locally.
BIGQUERY_DATASET_LOCAL = 'dev'
# BigQuery table within the dataset.
BIGQUERY_TABLE = 'analytics'
apprtc.py
找到get_wss_parameters方法
def get_wss_parameters(request):
wss_host_port_pair = request.get('wshpp')
wss_tls = request.get('wstls')
if not wss_host_port_pair:
# Attempt to get a wss server from the status provided by prober,
# if that fails, use fallback value.
memcache_client = memcache.Client()
wss_active_host = memcache_client.get(constants.WSS_HOST_ACTIVE_HOST_KEY)
if wss_active_host in constants.WSS_HOST_PORT_PAIRS:
wss_host_port_pair = wss_active_host
else:
logging.warning(
'Invalid or no value returned from memcache, using fallback: '
+ json.dumps(wss_active_host))
wss_host_port_pair = constants.WSS_HOST_PORT_PAIRS[0]
if wss_tls and wss_tls == 'false':
wss_url = 'ws://' + wss_host_port_pair + '/ws'
wss_post_url = 'http://' + wss_host_port_pair
else:
wss_url = 'wss://' + wss_host_port_pair + '/ws'
wss_post_url = 'https://' + wss_host_port_pair
return (wss_url, wss_post_url)
修改成
def get_wss_parameters(request):
wss_host_port_pair = request.get('wshpp')
wss_tls = request.get('wstls')
if not wss_host_port_pair:
# Attempt to get a wss server from the status provided by prober,
# if that fails, use fallback value.
memcache_client = memcache.Client()
wss_active_host = memcache_client.get(constants.WSS_HOST_ACTIVE_HOST_KEY)
if wss_active_host in constants.WSS_HOST_PORT_PAIRS:
wss_host_port_pair = wss_active_host
else:
logging.warning(
'Invalid or no value returned from memcache, using fallback: '
+ json.dumps(wss_active_host))
wss_host_port_pair = constants.WSS_HOST_PORT_PAIRS[0]
if wss_tls and wss_tls == 'false':
wss_url = 'ws://' + wss_host_port_pair + '/ws'
wss_post_url = 'http://' + wss_host_port_pair
else:
wss_url = 'ws://' + wss_host_port_pair + '/ws'
wss_post_url = 'http://' + wss_host_port_pair
return (wss_url, wss_post_url)
index_template.html
找到如下代码块,修改并替换ip地址即可
{% if not chromeapp %}
<script type="text/javascript">
var servers=[{
credential:"helloword",
username:"helloword",
urls:[
"turn:192.168.23.114:3478?transport=udp",
"turn:192.168.23.114:3478?transport=tcp"
]
}];
var loadingParams = {
errorMessages: {{ error_messages }},
isLoopback: {{ is_loopback }},
warningMessages: {{ warning_messages }},
{% if room_id %}
roomId: '{{ room_id }}',
roomLink: '{{ room_link }}',
{% endif %}
mediaConstraints: {{ media_constraints | safe }},
offerOptions: {{ offer_options | safe }},
peerConnectionConfig: { "rtcpMuxPolicy":"require","iceServers":servers,"bundlePolicy":"max-bundle"},
//peerConnectionConfig: {{ pc_config | safe }},
peerConnectionConstraints: {{ pc_constraints | safe }},
// iceServerRequestUrl: '{{ ice_server_url }}',
iceServerTransports: '{{ ice_server_transports }}',
wssUrl: '{{ wss_url }}',
wssPostUrl: '{{ wss_post_url }}',
bypassJoinConfirmation: {{ bypass_join_confirmation }},
versionInfo: {{ version_info }},
};
6.启动room server
解压google_appengine_1.9.65.zip到root目录,替换下面的ip并运行即可
root@xyh:~/google_appengine#/root/google_appengine/dev_appserver.py –host 192.168.22.170 /root/apprtc/out/app_engine
这个时候是看不到图像的,安装信令服务器之后才可以看
7.安装信令服务器,signal server
参考:
https://github.com/webrtc/apprtc/blob/master/src/collider/README.md
复制collider到apprtc同级目录即,
cp /root/apprtc/src/collider /root/collider/src -r
修改main.go
vim /root/collider/src/collidermain/main.go
更改为
var roomSrv = flag.String(“room-server”, “http://192.168.110.131:8080”, “The origin of the room server”)
设置环境变量
export GOROOT=/root/go;
export PATH=$PATH:$GOROOT/bin;
export GOPATH=/root/collider/;
如果出问题的话,重新安装go
卸载apt-get install 的go
apt-get remove golang -y;apt-get remove golang* -y;apt-get autoremove;
也可以下载go的tar包,绿色安装
如果出现网络问题
mkdir -p $GOPATH/src/golang.org/x cd $GOPATH/src/golang.org/x git clone https://github.com/golang/net.git
安装依赖
go get collidermain;
go install collidermain;
运行信令服务器
/root/collider/bin/collidermain -port=8089 -tls=false
这个时候可以看到图像
8.安装ice server
安装依赖
apt-get install libssl-dev libsqlite3-dev libevent-dev libpq-dev -y
下载coturn代码
git clone https://github.com/coturn/coturn.git
编译和安装
cd coturn
./configure && make && make install
ip地址换成你自己的
/root/coturn/bin/turnserver –syslog -a -L 192.168.22.170 -X 192.168.22.170 -E 192.168.22.170 -f –min-port=32355 –max-port=65535 –user=helloword:helloword -r helloword –cert=turn_server_cert.pem –pkey=turn_server_pkey.pem –log-file=stdout -v
x外网ip,L和E是内网ip
9.android端需要修改的
下载代码:
https://github.com/njovy/AppRTCDemo
修改代码:
android只需要改这个文件
花圈的是需要注释掉
画横线是需要添加的
里面这个ip需要填写你turn服务器的ip
启动app后需要在app配置里面修改房间服务器地址
这个就是android的修改
10.手机安装后如何使用
安装demo apk
打开设置按钮
设置房间服务器地址:
最后的未解决问题:
1. 日志报错
服务器端:Invalid or no value returned from memcache, using fallback: null
Android端:ice_server_url=http://192.168.23.114/v1alpha/iceconfig?key=none
2. Chrome不支持,https付费,暂时不弄
3. 多对多支持,一对多
所有评论(0)