1. pre-conditions
-
First you need to have a linux server, windows can also be, please get yourself
-
You need to install nodejs environment, note the version can not be too low,
nodejs official website: https://nodejs.org/en/download/
In case of questions, please find: https://github.com/nodejs/help/wiki/Installation
-
openssl, this thing should not have said
-
This also goes without saying git
-
Should not the other
2. coturn traversal server to build
-
Compile and install coturn
git clone https://github.com/coturn/coturn cd coturn ./configure make sudo make install
-
Check whether the installation
which turnserver
-
Configuration
Profile path as follows
/usr/local/etc/turnserver.conf (also possible in other positions), with one caveat min-port to port max-port needs to open, or forwarded so bad
#我配置如下: verbose fingerprint min-port=59000 max-port=65000 lt-cred-mech realm=demo user=dds:0x2bc31c994d676961b59b9aa1c92f74d3 user=dds:123456 stale-nonce no-loopback-peers no-multicast-peers mobility no-cli #只需要修改user字段和realm字段 #0x2bc31c994d676961b59b9aa1c92f74d3 是为了安全访问,也可不填
The above generation command string follows, dds and replaced their 123456
turnadmin -k -u dds -r north.gov -p 123456
See more detailed configuration
https://github.com/ddssingsong/webrtc_server/blob/master/coturn/turnserver.conf
Or under this configuration, only the configuration stun (stun-only)
listening-ip=本地ip listening-port=3478 #relay-ip=0.0.0.0 external-ip=外网ip Verbose fingerprint no-stdout-log syslog cert=pem/turn_server_cert.pem #这两个玩意请自行生成 pkey=pem/turn_server_pkey.pem # user=demo:demo no-tcp no-tls no-tcp-relay stun-only #secure-stun
-
start up
如果按照上面的配置直接运行 turnserver 如果没有配置上述配置文件,可采用其他运行方法 /usr/local/bin/turnserver --syslog -a -f --min-port=32355 --max-port=65535 --user=dds:123456 -r dds --cert=turn_server_cert.pem --pkey=turn_server_pkey.pem --log-file=stdout -v --syslog 使用系统日志 -a 长期验证机制 -f 使用指纹 --min-port 起始用的最小端口 --max-port 最大端口号 --user=dds:123456 turn用户名和密码 -r realm组别 --cert PEM格式的证书 --pkey PEM格式的私钥文件 -l, --log-file,<filename> 指定日志文件 -v verbose 请根据需要选择
-
Address test, test stun and turn respectively
https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
3. The signaling service is set up (based Skyrtc)
Still download it from github
github to mark it, support it slightly
git clone https://github.com/ddssingsong/webrtc_server.git
cd webrtc_server
运行
node server.js
#如果要测试浏览器,请修改下面两个文件
Modify /public/dist/js/SkyRTC-client.js, mainly for testing browser
var iceServer = {
"iceServers": [
{
"url": "stun:stun.l.google.com:19302"
},
{
"url": "stun:外网ip:3478"
},
{
"url": "turn:外网ip:3478",
"username":"用户名",
"credential":"密码"
}
]
};
Mainly used for modifying /public/dist/js/conn.js
#最后一行
#如果没有配wss代理
rtc.connect("ws:" + window.location.href.substring(window.location.protocol.length).split('#')[0], window.location.hash.slice(1));
如果配了wss代理
rtc.connect("wss:" + window.location.href.substring(window.location.protocol.length).split('#')[0]+"/wss", window.location.hash.slice(1));
# 后面的那个“/wss”是根据自己配的代理路径
4. Configure proxy nignx
Install the required dependencies
yum install -y gcc gcc-c++ autoconf automake make zlib zlib-devel openssl openssl-devel pcre pcre-devel
Compile and install nginx
wget -C http://nginx.org/download/nginx-1.12.0.tar.gz
tar xvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
Modify the configuration file
cd /usr/local/nginx/conf/
vi vim nginx.conf
Configuring reverse proxy as follows
#代理https
upstream web {
server 0.0.0.0:3000;
}
#代理websocket
upstream websocket {
server 0.0.0.0:3000;
}
server {
listen 443;
server_name localhost;
ssl on;
ssl_certificate /cert/cert.crt;#配置证书
ssl_certificate_key /cert/cert.key;#配置密钥
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 50m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv2 SSLv3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
#charset koi8-r;
#access_log logs/host.access.log main;
#wss 反向代理
location /wss {
proxy_pass http://websocket/; # 代理到上面的地址去
proxy_read_timeout 100s;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-for $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'Upgrade';
}
#https 反向代理
location / {
proxy_pass http://web/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
5. Test your browser
访问
https://serverIp#roomName
查看效果,其中roomName为进入的房间名,不同房间的用户无法互相通话
For details, see: https://github.com/ddssingsong/webrtc_server
6. Test Client
将这个项目下下来使用 android studio 编译并安装
https://github.com/ddssingsong/webrtc_android
将 WebrtcUtil.java中的地址替换成自己地址 就可测试
Project Address: https://github.com/ddssingsong/webrtc_android
As the above process have questions please ask your question on github, I will take the time to reply