【网络通信 -- WebRTC】项目实战记录 -- Janus 环境搭建

2024-01-08 16:30

本文主要是介绍【网络通信 -- WebRTC】项目实战记录 -- Janus 环境搭建,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

【网络通信 -- WebRTC】项目实战记录 -- Janus 环境搭建

【1】安装准备

【1.1】安装依赖

安装 aptitu
sudo 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 automakesudo apt install cmake
sudo aptitude install libconfig-dev
sudo aptitude install libssl-dev
sudo aptitude install doxygen graphviz
sudo aptitude install libavcodec-dev libavformat-dev libswscale-dev libavutil-dev

【2】Janus 插件选择与安装

janus 支持插件式功能安装,根据需求选择安装

安装插件如下

libwebsockets(支持 WebSocket)
libsrtp 和 libusrsctp(音视频流传输控制和数据协议支持)
libmicrohttpd(支持 http/https)
Janus
nginx(提供 web 服务)

【2.1】libwebsockets

git clone https://github.com/warmcat/libwebsockets.git
cd libwebsockets
git checkout v3.2-stable 
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" ..
make
make install

【2.2】libsrtp

wget https://github.com/cisco/libsrtp/archive/v2.2.0.tar.gz
tar xfv v2.2.0.tar.gz
cd libsrtp-2.2.0
./configure --prefix=/usr --enable-openssl
make shared_library 
make install

【2.3】libusrsctp

git clone https://github.com/Kurento/libusrsctp.git
cd libusrsctp
./bootstrap
./configure
make
make install

【2.4】libmicrohttpd

wget https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.71.tar.gz
tar zxf libmicrohttpd-0.9.71.tar.gz
cd libmicrohttpd-0.9.71/
./configure
make
make install

【2.5】Janus

git clone https://github.com/meetecho/janus-gateway.git
git  checkout v0.10.4
sh autogen.sh
./configure --prefix=/opt/janus --enable-websockets --enable-post-processing --enable-docs --enable-rest --enable-data-channels
make
make install

【2.6】Nginx

【2.6.0】下载 nginx-rtmp-module

wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
unzip master.zip

【2.6.1】安装 Nginx

wget http://nginx.org/download/nginx-1.15.8.tar.gz
tar xvzf nginx-1.15.8.tar.gz
cd nginx-1.15.8/
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module-master --with-http_ssl_module
make
make install

【2.6.2】生成签名证书

mkdir -p ~/cert
cd ~/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 启停指令

# 启动和关闭nginx
sudo /usr/local/nginx/sbin/nginx
sudo /usr/local/nginx/sbin/nginx -s  stop

【2.6.5】Nginx 测试

【2.7】TurnServer

【2.7.1】安装 TurnServer

sudo apt-get install libssl-dev
sudo apt-get install libevent-devwget http://coturn.net/turnserver/v4.5.0.7/turnserver-4.5.0.7.tar.gz
tar xfz turnserver-4.5.0.7.tar.gz
cd turnserver-4.5.0.7
sudo ./configure
sudo make
sudo 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/janus
sudo cp janus.jcfg.sample janus.jcfg
sudo cp janus.transport.http.jcfg.sample janus.transport.http.jcfg
sudo cp janus.transport.websockets.jcfg.sample janus.transport.websockets.jcfg
sudo cp janus.plugin.videoroom.jcfg.sample janus.plugin.videoroom.jcfg
sudo cp janus.transport.pfunix.jcfg.sample janus.transport.pfunix.jcfg
sudo cp janus.plugin.streaming.jcfg.sample janus.plugin.streaming.jcfg
sudo cp janus.plugin.recordplay.jcfg.sample janus.plugin.recordplay.jcfg
sudo cp janus.plugin.voicemail.jcfg.sample janus.plugin.voicemail.jcfg
sudo cp janus.plugin.sip.jcfg.sample janus.plugin.sip.jcfg
sudo cp janus.plugin.nosip.jcfg.sample janus.plugin.nosip.jcfg

修改 janus.jcfg 配置 turn server

nat: {stun_server = "172.16.4.78"stun_port = 3478nice_debug = false#full_trickle = true#ice_lite = true#ice_tcp = trueturn_server = "172.16.4.78"turn_port = 3478turn_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 poolhttp = true                                             # Whether to enable the plain HTTP interfaceport = 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) onlyhttps = 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 detectedws = true                                               # Whether to enable the WebSockets APIws_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 onlywss = true                                              # Whether to enable secure WebSocketswss_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 端,https://github.com/pcgpcgpcg/janus-gateway-android

PC Windows 端,https://github.com/pcgpcgpcg/janus_gateway_win

Web 端,https://github.com/pcgpcgpcg/rtc_web_demo

附录

【1】云服务器上相关配置 -- 使能相关端口

【2】Android 端代码修改

修改配置 Janus 服务器 IP 地址

修改 build.gradle

maven{ url'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://developer.huawei.com/repo/' }
jcenter { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }

问题与解决方案

  • 问题一

configure: error: Package requirements (libcrypto >= 1.0.1) were not met:

  • 解决方案

安装 openssl,注意添加 shared 标识标识强制生成动态库,否则会出现静态库链接生成动态库的错误

wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
tar xf openssl-1.0.2l.tar.gz
cd openssl-1.0.2l
sudo ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
make && make install

设置 PKG_CONFIG_PATH 环境变量

export PKG_CONFIG_PATH=/usr/local/ssl/lib/pkgconfig/:$PKG_CONFIG_PATH
  • 问题二

  • 解决方案
安装 doxygensudo apt-get install flex
sudo apt-get install bisongit clone https://github.com/doxygen/doxygen.git
cd doxygen
mkdir build
cd build
cmake -G "Unix Makefiles" ..
make
sudo make install
doxygen --version

参考致谢

本博客为博主的学习实践总结,并参考了众多博主的博文,在此表示感谢,博主若有不足之处,请批评指正。

【1】Ubuntu16.04 中 搭建Janus Server

【2】ubuntu安装python3.7,并更新python默认指向为python3.7

【3】ubuntu18.04 安装新版本openssl

【4】doxygen安装(doxygen的编译依靠cmake)

这篇关于【网络通信 -- WebRTC】项目实战记录 -- Janus 环境搭建的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/584085

相关文章

从原理到实战深入理解Java 断言assert

《从原理到实战深入理解Java断言assert》本文深入解析Java断言机制,涵盖语法、工作原理、启用方式及与异常的区别,推荐用于开发阶段的条件检查与状态验证,并强调生产环境应使用参数验证工具类替代... 目录深入理解 Java 断言(assert):从原理到实战引言:为什么需要断言?一、断言基础1.1 语

深度解析Java项目中包和包之间的联系

《深度解析Java项目中包和包之间的联系》文章浏览阅读850次,点赞13次,收藏8次。本文详细介绍了Java分层架构中的几个关键包:DTO、Controller、Service和Mapper。_jav... 目录前言一、各大包1.DTO1.1、DTO的核心用途1.2. DTO与实体类(Entity)的区别1

Java MQTT实战应用

《JavaMQTT实战应用》本文详解MQTT协议,涵盖其发布/订阅机制、低功耗高效特性、三种服务质量等级(QoS0/1/2),以及客户端、代理、主题的核心概念,最后提供Linux部署教程、Sprin... 目录一、MQTT协议二、MQTT优点三、三种服务质量等级四、客户端、代理、主题1. 客户端(Clien

在Spring Boot中集成RabbitMQ的实战记录

《在SpringBoot中集成RabbitMQ的实战记录》本文介绍SpringBoot集成RabbitMQ的步骤,涵盖配置连接、消息发送与接收,并对比两种定义Exchange与队列的方式:手动声明(... 目录前言准备工作1. 安装 RabbitMQ2. 消息发送者(Producer)配置1. 创建 Spr

SQLite3 在嵌入式C环境中存储音频/视频文件的最优方案

《SQLite3在嵌入式C环境中存储音频/视频文件的最优方案》本文探讨了SQLite3在嵌入式C环境中存储音视频文件的优化方案,推荐采用文件路径存储结合元数据管理,兼顾效率与资源限制,小文件可使用B... 目录SQLite3 在嵌入式C环境中存储音频/视频文件的专业方案一、存储策略选择1. 直接存储 vs

深度解析Spring Boot拦截器Interceptor与过滤器Filter的区别与实战指南

《深度解析SpringBoot拦截器Interceptor与过滤器Filter的区别与实战指南》本文深度解析SpringBoot中拦截器与过滤器的区别,涵盖执行顺序、依赖关系、异常处理等核心差异,并... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)深度解析:区别、实现

如何在Spring Boot项目中集成MQTT协议

《如何在SpringBoot项目中集成MQTT协议》本文介绍在SpringBoot中集成MQTT的步骤,包括安装Broker、添加EclipsePaho依赖、配置连接参数、实现消息发布订阅、测试接口... 目录1. 准备工作2. 引入依赖3. 配置MQTT连接4. 创建MQTT配置类5. 实现消息发布与订阅

springboot项目打jar制作成镜像并指定配置文件位置方式

《springboot项目打jar制作成镜像并指定配置文件位置方式》:本文主要介绍springboot项目打jar制作成镜像并指定配置文件位置方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录一、上传jar到服务器二、编写dockerfile三、新建对应配置文件所存放的数据卷目录四、将配置文

深度解析Spring AOP @Aspect 原理、实战与最佳实践教程

《深度解析SpringAOP@Aspect原理、实战与最佳实践教程》文章系统讲解了SpringAOP核心概念、实现方式及原理,涵盖横切关注点分离、代理机制(JDK/CGLIB)、切入点类型、性能... 目录1. @ASPect 核心概念1.1 AOP 编程范式1.2 @Aspect 关键特性2. 完整代码实

MySQL中的索引结构和分类实战案例详解

《MySQL中的索引结构和分类实战案例详解》本文详解MySQL索引结构与分类,涵盖B树、B+树、哈希及全文索引,分析其原理与优劣势,并结合实战案例探讨创建、管理及优化技巧,助力提升查询性能,感兴趣的朋... 目录一、索引概述1.1 索引的定义与作用1.2 索引的基本原理二、索引结构详解2.1 B树索引2.2