
本文共 9165 字,大约阅读时间需要 30 分钟。
【网络通信 -- WebRTC】项目实战记录 -- Janus 环境搭建
【1】安装准备
【1.1】安装依赖
安装 aptitusudo apt-get install aptitudesudo aptitude install libmicrohttpd-dev libjansson-dev libnice-dev \ libssl1.0.1-dev libsrtp-dev libsofia-sip-ua-dev libglib2.3.4-dev \ libopus-dev libogg-dev libcurl4-openssl-dev pkg-config gengetopt \ libtool automake sudo apt install cmakesudo aptitude install libconfig-devsudo aptitude install libssl-devsudo aptitude install doxygen graphvizsudo aptitude install libavcodec-dev libavformat-dev libswscale-dev libavutil-dev
【2】Janus 插件选择与安装
janus 支持插件式功能安装,根据需求选择安装
安装插件如下
libwebsockets(支持 WebSocket)libsrtp 和 libusrsctp(音视频流传输控制和数据协议支持)libmicrohttpd(支持 http/https)Janusnginx(提供 web 服务)
【2.1】libwebsockets
git clone https://github.com/warmcat/libwebsockets.gitcd libwebsocketsgit checkout v3.2-stable mkdir buildcd buildcmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" ..makemake install
【2.2】libsrtp
wget https://github.com/cisco/libsrtp/archive/v2.2.0.tar.gztar xfv v2.2.0.tar.gzcd libsrtp-2.2.0./configure --prefix=/usr --enable-opensslmake shared_library make install
【2.3】libusrsctp
git clone https://github.com/Kurento/libusrsctp.gitcd libusrsctp./bootstrap./configuremakemake install
【2.4】libmicrohttpd
wget https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.71.tar.gztar zxf libmicrohttpd-0.9.71.tar.gzcd libmicrohttpd-0.9.71/./configuremakemake install
【2.5】Janus
git clone https://github.com/meetecho/janus-gateway.gitgit checkout v0.10.4sh autogen.sh./configure --prefix=/opt/janus --enable-websockets --enable-post-processing --enable-docs --enable-rest --enable-data-channelsmakemake install
【2.6】Nginx
【2.6.0】下载 nginx-rtmp-module
wget https://github.com/arut/nginx-rtmp-module/archive/master.zipunzip master.zip
【2.6.1】安装 Nginx
wget http://nginx.org/download/nginx-1.15.8.tar.gztar xvzf nginx-1.15.8.tar.gzcd nginx-1.15.8/./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module-master --with-http_ssl_modulemakemake install
【2.6.2】生成签名证书
mkdir -p ~/certcd ~/cert# CA私钥openssl genrsa -out key.pem 2048# 自签名证书openssl req -new -x509 -key key.pem -out cert.pem -days 1095
【2.6.3】配置 Nginx
vim /usr/local/nginx/conf/nginx.conf
修改配置文件如下
# 开启 HTTPS 功能server { listen 443 ssl; server_name localhost; ssl_certificate 自己的证书路径/cert.pem; #自己的证书 ssl_certificate_key 自己的证书路径/key.pem; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root /opt/janus/share/janus/demos; #web网页打开时,定位到这里 index index.html index.htm; }}# 开启 RTMP 功能rtmp { server { listen 1900; application myapp { live on; } } }
【2.6.4】Nginx 启停指令
# 启动和关闭nginxsudo /usr/local/nginx/sbin/nginxsudo /usr/local/nginx/sbin/nginx -s stop
【2.6.5】Nginx 测试
【2.7】TurnServer
【2.7.1】安装 TurnServer
sudo apt-get install libssl-devsudo apt-get install libevent-devwget http://coturn.net/turnserver/v4.5.0.7/turnserver-4.5.0.7.tar.gztar xfz turnserver-4.5.0.7.tar.gzcd turnserver-4.5.0.7sudo ./configuresudo makesudo make install
【2.7.2】启动 TurnServer
# 注意此处的用户名与密码需要与 janus.jcfg 中的配置一致sudo nohup turnserver -L 0.0.0.0 --min-port 30000 --max-port 60000 -a -u CopperSun:sungaopeng -v -f -r nort.gov &
【3】运行 Janus 官方 DEMO
备份 Janus 配置文件
cd /opt/janus/etc/janussudo cp janus.jcfg.sample janus.jcfgsudo cp janus.transport.http.jcfg.sample janus.transport.http.jcfgsudo cp janus.transport.websockets.jcfg.sample janus.transport.websockets.jcfgsudo cp janus.plugin.videoroom.jcfg.sample janus.plugin.videoroom.jcfgsudo cp janus.transport.pfunix.jcfg.sample janus.transport.pfunix.jcfgsudo cp janus.plugin.streaming.jcfg.sample janus.plugin.streaming.jcfgsudo cp janus.plugin.recordplay.jcfg.sample janus.plugin.recordplay.jcfgsudo cp janus.plugin.voicemail.jcfg.sample janus.plugin.voicemail.jcfgsudo cp janus.plugin.sip.jcfg.sample janus.plugin.sip.jcfgsudo cp janus.plugin.nosip.jcfg.sample janus.plugin.nosip.jcfg
修改 janus.jcfg 配置 turn server
nat: { stun_server = "172.16.4.78" stun_port = 3478 nice_debug = false #full_trickle = true #ice_lite = true #ice_tcp = true turn_server = "172.16.4.78" turn_port = 3478 turn_type = "udp" turn_user = "CopperSun" turn_pwd = "sungaopeng"}
修改 janus.transport.http.jcfg 以开启 https 和增加证书
general: { #events = true # Whether to notify event handlers about transport events (default=true) json = "indented" # Whether the JSON messages should be indented (default), # plain (no indentation) or compact (no indentation and no spaces) base_path = "/janus" # Base path to bind to in the web server (plain HTTP only) threads = "unlimited" # unlimited=thread per connection, number=thread pool http = true # Whether to enable the plain HTTP interface port = 8088 # Web server HTTP port #interface = "eth0" # Whether we should bind this server to a specific interface only #ip = "192.168.0.1" # Whether we should bind this server to a specific IP address (v4 or v6) only https = true # Whether to enable HTTPS (default=false) secure_port = 8089 # Web server HTTPS port, if enabled #secure_interface = "eth0" # Whether we should bind this server to a specific interface only #secure_ip = "192.168.0.1" # Whether we should bind this server to a specific IP address (v4 or v6) only #acl = "127.,192.168.0." # Only allow requests coming from this comma separated list of addresses}certificates: { cert_pem = "自己的证书路径/cert.pem" cert_key = "自己的证书路径/key.pem" #cert_pwd = "secretpassphrase" #ciphers = "PFS:-VERS-TLS1.0:-VERS-TLS1.1:-3DES-CBC:-ARCFOUR-128"}
修改 janus.transport.websockets.jcfg 以开启 wss 和增加证书
general: { #events = true # Whether to notify event handlers about transport events (default=true) json = "indented" # Whether the JSON messages should be indented (default), # plain (no indentation) or compact (no indentation and no spaces) #pingpong_trigger = 30 # After how many seconds of idle, a PING should be sent #pingpong_timeout = 10 # After how many seconds of not getting a PONG, a timeout should be detected ws = true # Whether to enable the WebSockets API ws_port = 8188 # WebSockets server port #ws_interface = "eth0" # Whether we should bind this server to a specific interface only #ws_ip = "192.168.0.1" # Whether we should bind this server to a specific IP address only wss = true # Whether to enable secure WebSockets wss_port = 8989 # WebSockets server secure port, if enabled #wss_interface = "eth0" # Whether we should bind this server to a specific interface only #wss_ip = "192.168.0.1" # Whether we should bind this server to a specific IP address only #ws_logging = "err,warn" # libwebsockets debugging level as a comma separated list of things # to debug, supported values: err, warn, notice, info, debug, parser, # header, ext, client, latency, user, count (plus 'none' and 'all') #ws_acl = "127.,192.168.0." # Only allow requests coming from this comma separated list of addresses}certificates: { cert_pem = "自己的证书路径/cert.pem" cert_key = "自己的证书路径/key.pem" #cert_pwd = "secretpassphrase"}
修改 Janus demo 增加 wss 支持
vim /opt/janus/share/janus/demos/videoroomtest.jsvar server = null;if(window.location.protocol === 'http:') server = "http://" + window.location.hostname + ":8088/janus";else #server = "https://" + window.location.hostname + ":8089/janus"; server = "wss://" + window.location.hostname + ":8989";
启动 Janus
/opt/janus/bin/janus --debug-level=5 --log-file=$HOME/janus-log
【4】Janus 示例代码
Android 端,
PC Windows 端,
Web 端,
问题与解决方案
问题一
configure: error: Package requirements (libcrypto >= 1.0.1) were not met:
解决方案
安装 openssl,注意添加 shared 标识标识强制生成动态库,否则会出现静态库链接生成动态库的错误
wget https://www.openssl.org/source/openssl-1.0.2l.tar.gztar xf openssl-1.0.2l.tar.gzcd openssl-1.0.2lsudo ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlibmake && make install
设置 PKG_CONFIG_PATH 环境变量
export PKG_CONFIG_PATH=/usr/local/ssl/lib/pkgconfig/:$PKG_CONFIG_PATH
参考致谢
本博客为博主的学习实践总结,并参考了众多博主的博文,在此表示感谢,博主若有不足之处,请批评指正。
【1】
【2】
【3】
发表评论
最新留言
关于作者
