1、概述

想要了解Janus,首先需要知道WebRTC以及Janus和WebRTC之间的关系,本文将会对这些内容做简单的介绍,同时也会介绍一下Janus的架构,Janus可以实现的功能,并展示如何快速搭建一套Janus的后台服务器,最后利用官方的前端demo,实现sip通话。

2、JANUS简介

什么是WebRTC,它有哪些功能?WebRTC (Web Real-Time Communications) 是一个开源项目是一项实时通讯的技术,旨在使得浏览器能为实时通信提供简单的JavaScript接口,让浏览器通过JS实现即时通信接口。这个接口是通过一系列的信令,建立一个浏览器与浏览器之间(peer-to-peer)的信道,这个信道可以发送任何数据,而不需要经过服务器。并且WebRTC通过实现MediaStream,通过浏览器调用设备的摄像头、话筒,使得浏览器之间可以传递音频和视频。

那么什么是Janus呢?janus是一个WebRTC网关,由Meeteco设计和开发,是为Linux系统量身定制的,也可以在MacOS编译和安装。Windows不受支持,但如果需要的话,Janus可以在Windows 10中的“Windows Subsystem for Linux”上工作。

3、JANUS的架构及各文件作用

3.1、janus架构图

3.2、janus部分目录及文件的作用

plugins          # 业务插件目录
docs             # Janus相关文档目录
html             # 前端相关Demo目录
rtcp.c           # RTCP协议的具体实现
rtp.c            # RTP协议的实现,它用于传输音视频数据
sctp.c           # SCTP协议的实现
sdp.c            # SDP协议的实现
sdp-utils.c      # 处理SDP的常用工具
test             # 测试文件所在目录
record.c         # 录制功能的实现
ice.c            # 实现对libnice库的封装
janus.c          # Janus的主框架程序
log.c            # 日志
dtls-bio.c       # DTLS中BIO实现
dtls.c           # DTLS协议实现
。。。

4、JANUS服务端的简单搭建

好了说了这么多废话,下面就开始Janus服务端的搭建,搭建环境为centos7。

4.1、安装依赖包

首先需要安装janus的相关依赖包,以保证Janus服务能正常运行。其中有些依赖包是在github上的,下载的时候可能出现速度比较慢,或者出现会卡顿无法下载等情况,wget多试几次,多等待一会即可。

#step1 安装相关依赖包
yum install -y epel-release && \
yum update -y && \
yum install -y deltarpm && \
yum install -y gnutls-devel&& \
yum install -y openssh-server sudo which file curl zip unzip wget && \
yum install -y libmicrohttpd-devel jansson-devel libnice-devel glib22-devel opus-devel libogg-devel pkgconfig  gengetopt libtool autoconf automake make gcc gcc-c++ git cmake libconfig-devel openssl-devel
#step2 安装libsrtp 1.5.4或安装libsrtp 2.0.0,根据你安装的版本使用即可
wget https://github.com/cisco/libsrtp/archive/v1.5.4.tar.gz
tar xfv v1.5.4.tar.gz
cd libsrtp-1.5.4
./configure --prefix=/usr --enable-openssl
make shared_library && sudo make install
wget https://github.com/cisco/libsrtp/archive/v2.0.0.tar.gz
tar xfv v2.0.0.tar.gz
cd libsrtp-2.0.0
./configure --prefix=/usr --enable-openssl
make shared_library && sudo make install
#step3 安装 sofia-sip,用于Janus的sip-gateway插件
wget https://sourceforge.net/projects/sofia-sip/files/sofia-sip/1.12.11/sofia-sip-1.12.11.tar.gz
tar zxf sofia-sip-1.12.11.tar.gz
cd sofia-sip-1.12.11
./configure --prefix=/usr CFLAGS=-fno-aggressive-loop-optimizations
make && make install
#step4 安装usrsctp,data-channel支持
git clone https://github.com/sctplab/usrsctp
cd usrsctp
./bootstrap
./configure --prefix=/usr
make && make install
#step5 安装libwebsocket
git clone https://github.com/warmcat/libwebsockets
mkdir libwebsockets/build
cd libwebsockets/build
cmake -DMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" ..
make && make install
#step6 安装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 --prefix=/usr
make && sudo make install
#step7 安装libnice,不安装该依赖会“nice_address_ip_version”有报错
yum install -y python3 python3-pip python3-setuptools python3-wheel ninja-build
pip3 install meson ninja
git clone https://gitlab.freedesktop.org/libnice/libnicelibnice-dev
tar zxf libnice-master.tar.gz
cd libnice/
meson --prefix=/usr build && ninja -C build && sudo ninja -C build install

4.2、安装Janus

安装完Janus相关的依赖包以后,便要进入到我们主程序的安装,Janus的安装如下。

#安装Janus
#配置环境变量,否则可能会报错
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig
git clone https://github.com/meetecho/janus-gateway.git
cd janus-gateway
sh autogen.sh
./configure --prefix=/opt/janus --disable-rabbitmq --disable-docs --disable-libsrtp2  &&\
make && make install && make configs

到此,janus的服务器的安装已经完成了。janus安装完成以后,是安装在/opt/janus目录的, 进入目录后可以看到组成结构,其中,Janus的执行文件在bin文件夹中,配置在etc/janus文件夹中。

由于本文旨在快速搭建,并实现sip通话,就不对配置做一一介绍,直接使用默认的配置启动,配置文件默认https是关闭,如需开启,需要进入janus.transport.http.jcfg文件中,将https = false改为true,并且需要将cert_pem和cert_key配置为有效的https证书路径再启动。

4.3、启动Janus

# 启动(后台)
cd /opt/janus/bin
nohup ./janus &
tail -f nohup#启动的部分信息如下,下面是直接控制台启动,看输出
[root@localhost ~]# cd /opt/janus/bin/
[root@localhost bin]# ./janus
Janus version: 1101 (1.1.1)
Janus commit: d659656b49b32046d60b3a9af21b74db790d5880
Compiled on:  Mon Oct 10 17:08:48 CST 2022Logger plugins folder: /opt/janus/lib/janus/loggers
---------------------------------------------------Starting Meetecho Janus (WebRTC Server) v1.1.1
---------------------------------------------------Checking command line arguments...
Debug/log level is 4
Debug/log timestamps are disabled
Debug/log colors are enabled
Using ***.**.**.*8 as local IP...
Token based authentication disabled
Initializing recorder code
Initializing ICE stuff (Full mode, ICE-TCP candidates disabled, half-trickle, IPv6 support disabled)
Crypto: OpenSSL pre-1.1.0
Fingerprint of our certificate: 13:AF:B3:B0:44:73:58:64:A8:6B:24:C6:D8:1C:30:92:99:52:D4:6D:AD:4A:AA:0E:5A:44:17:E8:32:D6:C7:D6
Event handlers support disabled
Plugins folder: /opt/janus/lib/janus/plugins
Sessions watchdog started
Joining Janus requests handler thread
Loading plugin 'libjanus_audiobridge.so'...
JANUS AudioBridge plugin initialized!
Loading plugin 'libjanus_echotest.so'...
JANUS EchoTest plugin initialized!
Loading plugin 'libjanus_recordplay.so'...
JANUS Record&Play plugin initialized!
Loading plugin 'libjanus_sip.so'...
JANUS SIP plugin initialized!
Loading plugin 'libjanus_nosip.so'...
JANUS NoSIP plugin initialized!
Loading plugin 'libjanus_streaming.so'...
[WARN] libcurl not available, Streaming plugin will not have RTSP support
JANUS Streaming plugin initialized!
Loading plugin 'libjanus_videocall.so'...
JANUS VideoCall plugin initialized!
Loading plugin 'libjanus_videoroom.so'...
JANUS VideoRoom plugin initialized!
Loading plugin 'libjanus_voicemail.so'...
JANUS VoiceMail plugin initialized!
Loading plugin 'libjanus_textroom.so'...
JANUS TextRoom plugin initialized!
Transport plugins folder: /opt/janus/lib/janus/transports
Loading transport plugin 'libjanus_http.so'...
HTTP transport timer started
HTTP webserver started (port 8088, /janus path listener)...
JANUS REST (HTTP/HTTPS) transport plugin initialized!
Loading transport plugin 'libjanus_websockets.so'...
Websockets server started (port 8188)...
JANUS WebSockets transport plugin initialized!
Loading transport plugin 'libjanus_pfunix.so'...
WebSockets thread started

查看进程:ps -ef|grep janus

查看相关端口:netstat -apn|grep janus

停止进程:直接kill即可:kill -9 xxx

到此,可以看到http端口和ws端口已经提示启动成功了,这也表示Janus的后端服务已经启动成功了。个人认为对于Janus的服务端,不一定非要通过janus的配置开启https,可以通过nginx做一层转发即可。

4.4、前端项目

上面图中能看到Janus的目录中有一个share目录,/opt/janus/share/janus/demos这个目录下,即使demo环境了。将demos目录拷贝本地nginx的www目录中,www目录为nginx的安装目录,然后访问即可。由于本文主要是搭建简单的sip,所以只需要关注janus.js, settings.js,siptest.html,siptest.js,在启动窗口可以看到后端为http请求的服务端口为8088,将settings.js中的server改为本机的8088端口即可,如果需要集成到自己的项目中,也只需要对这几个文件进行修改。部署完成以后,浏览器访问http://localhost:8088/demos即可访问。页面如下,点击demos,选择Sip Gateway, 点击start,填入真实的sip话机信息,即可实现从浏览器打电话。

4.5、项目部署遇到的坑

4.5.1、版本问题

前端代码的版本和服务端使用同一版本,在开发过程中,如果使用老版本的前端的js文件修改后调用高版本的服务端,由于一下协议的不同,可能会导致电话打通后秒挂,所以要注意使用同一版本的前后端。

4.5.2、nice_address_ip_version

检查一下依赖环境,参考4.1安装依赖包有关于libnice这段安装。

4.5.3、提示找不到libsrtp

export PKG_CONFIG_PATH=/usr/lib/libsrtp/lib/pkgconfig

4.5.4、提示找不到 libnice

export PKG_CONFIG_PATH=/path/to/libnice/lib/pkgconfig`(libnice的安装路径)

4.5.5、要使用libsrtp1.5.4

在configure janus 时加上 --disable-libsrtp2。

4.5.6、libwebsockets.so.12报错

错误提示:libwebsockets.so.12: cannot open shared object file: No such file or directory。

# 修改/etc/ld.so.conf文件,加入libwebsockets的so路径
vi /etc/ld.so.conf
#include ld.so.conf.d/*.conf
#/usr/local/src/libwebsockets-2.4.1/build/lib
ldconfig
mosquitto -c /etc/mosquitto/mosquitto.conf -d

一文学会快速搭建Janus服务端相关推荐

  1. 快速搭建Kerberos服务端及入门使用

    快速搭建Kerberos服务端及入门使用 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. Kerberos是一种网络身份验证协议.它旨在通过使用秘密密钥加密为客户端/服务器应用程序提 ...

  2. 大疆无人机基于自搭建RTMP服务端推流直播

    思路 大疆在手机端提供了软件DJI GO 4控制飞行参数等,其中包含自定义RTMP接口来向第三方推流进行直播业务,而我们可以利用这种直播的思路来完成画面传输. 环境 精灵Phantom 4 Pro V ...

  3. Azure 中快速搭建 FTPS 服务

    FTP,FTPS 与 SFTP 的区别 FTP (File Transfer Protocol)是一种常用的文件传输协议,在日常工作中被广泛应用.不过,FTP 协议使用明文传输.如果文件传输发生在公网 ...

  4. 阿里云ESC搭建SVN服务端

    CentOS7)下yum命令快速安装svn服务端,学习在思考中独孤中度过,在孤独中进取! 01.SVN服务的安装(subversion) 02.ESC安全组策略 1.在线安装svn服务 $ sudo ...

  5. 如何在 MacOS 环境下搭建 SVN 服务端环境

    文章目录 在服务端创建资源仓库 资源仓库访问权限配置 给资源仓库添加用户 配置用户组及用户的权限 启动 SVN 服务器 停止 SVN 服务器 SVN 是一个使用十分广泛的开放源代码的版本控制系统.在 ...

  6. vue.js+koa2项目实战(四)搭建koa2服务端

    搭建koa2服务端 安装两个版本的koa 一.版本安装 1.安装 koa1 npm install koa -g 注:必须安装到全局 2.安装 koa2 npm install koa@2 -g 二. ...

  7. HTML+JS+websocket 实现联机“游戏王”对战(十)- 搭建游戏服务端

    目录: 游戏王联机卡牌对战 1 - 前言 游戏王联机卡牌对战 2 - 联机模式 游戏王联机卡牌对战 3 - 界面布局 游戏王联机卡牌对战 4 - 卡组系统 游戏王联机卡牌对战 5 - 卡片选中系统 游 ...

  8. Android搭建WebSocket服务端

    WebSocket简介 WebSocket协议是基于TCP的一种新的网络协议.它实现了浏览器与服务器全双工(full-duplex)通信--允许服务器主动发送信息给客户端.全双工就是指客户端和服务端可 ...

  9. 使用Eclipse和Tomcat搭建Android服务端

    作为一名Android开发者,不懂一点服务端的知识有时候真的不行.比如你做好了用户登录请求的功能,想找服务端验证一下是否正确.服务端同事告诉你他很忙,等他把接口写完了再验证.这时候呢,我们完全可以自己 ...

最新文章

  1. 隆重介绍恩智浦MCU机器学习教育套件——OpenART
  2. MySQL数据库Innodb储存引擎----储存页的结构
  3. Facebook 号称击败谷歌,推出最强聊天机器人
  4. 课程第一天内容《基础交换 一 》
  5. WireShark抓包,may be caused by ip checksum offload的解决办法
  6. 使用 WebSphere Portlet Factory 构建基于 Web2.0 的灵活 SOA 前端
  7. php 有request,php实现httpRequest的方法
  8. 王庆的边缘计算(第一章)
  9. dell无线网卡驱动安装
  10. AF 服务器安全防护实验
  11. 黑群晖二合一已损毁_黑群晖二合一ghost安装教程(蜜獾超存可用)
  12. QT 之QTreeWidget实现好友列表
  13. 随机预言模型和标准模型 -2014-03-24 15:35
  14. OTL电路与OCL功放电路的区别
  15. 数据库初级入门sqlite3版本
  16. 数据结构 ADT例子
  17. 使用mars3d时第二次进行hls视频融合报错
  18. C++面向对象学习之路(一)类与对象
  19. 《演讲的本质》:如何做好一次公开演讲?
  20. 如何实现JAVA游戏存档_保存游戏数据 – Java

热门文章

  1. 这些Web API真的有用吗? 别问,问就是有用
  2. x210移植wifi(三):WIFI网卡的配置过程(wpa_supplicant)
  3. PE系统解决忘记开机密码
  4. 关于POS系统可靠性开发的一些考虑:
  5. Android对方向感应器的封装调用
  6. c shell 命令提示符大全
  7. 【神器】神经网络画图,这些模板也太美了吧!
  8. python怎么读取csv的一部分数据_python批量读取csv文件 如何用python将csv文件中的数据读取成数组...
  9. 惠普笔记本触摸板双指、多指操作失效问题的解决
  10. android应用添加字体,android应用 修改字体