h5的直播时代到来,搭建webrtc

环境

ubuntu18.04 git

安装janus

apt-get install aptitude
apt install meson
apt list meson*
pip3 install --user meson
apt install python3-pip
sudo aptitude install libmicrohttpd-dev libjansson-dev libssl-dev libsrtp-dev libsofia-sip-ua-dev libglib2.0-dev libopus-dev libogg-dev libcurl4-openssl-dev liblua5.3-dev libconfig-dev pkg-config gengetopt libtool automake
新建进入janus
mkdir janus
cd janus/
安装libnice
git clone https://gitlab.freedesktop.org/libnice/libnice
cd libnice/
meson --prefix=/usr build && ninja -C build && sudo ninja -C build install
./configure && make && sudo make install
安装libwebsocket
git clone https://libwebsockets.org/repo/libwebsockets
cd libwebsockets
mkdir build
cd build
cmake -DLWS_MAX_SMP=1 -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic"
make && sudo make install
源码安装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 && sudo make install
安装usrsctp
git clone https://github.com/sctplab/usrsctp
cd usrsctp
./bootstrap
./configure --prefix=/usr --disable-programs --disable-inet --disable-inet6
make && sudo make install```
生成证书
cd ~
mkdir ssl
cd ssl
openssl req -new -newkey rsa:4096 -nodes -keyout key.pem -out cert.csr
openssl x509 -req -sha256 -days 365 -in cert.csr -signkey key.pem -out cert.pem
chmod 600 cert.csr
chmod 600 cert.pem
chmod 600 key.pem

1.3 编译Janus

好了,依赖都准备好了,可以编译janus了。

git clone https://github.com/meetecho/janus-gateway.git
sh autogen.sh
./configure --prefix=/opt/janus --enable-websockets
make
sudo make install

打开/opt/janus/etc/janus/janus.jcfg,certificates修改key路径

certificates: {
        cert_pem = "/home/chenxiaofeng/ssl/cert.pem"
        cert_key = "/home/chenxiaofeng/ssl/key.pem"
        cert_pwd = "123456"
        #dtls_accept_selfsigned = false
        #dtls_ciphers = "your-desired-openssl-ciphers"
        #rsa_private_key = false
}
nat: {
	stun_server = "192.168.1.6"
	stun_port = 3478
	nice_debug = false
	#full_trickle = true
	#ice_lite = true
	#ice_tcp = true
	
	turn_server = "192.168.1.6"
	turn_port = 3478
	turn_type = "udp"
	turn_user = "zhs"
	turn_pwd = "123456"
}


/opt/janus/etc/janus/janus.transport.http.jcfg, 修改generals和certificates,启用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)
        http = true                                             # Whether to enable the plain HTTP interface
        port = 8088                                             # Web server HTTP port
      
        https = true                                    # Whether to enable HTTPS (default=false)
        secure_port = 8089                              # Web server HTTPS port, if enabled

}


certificates: {
        cert_pem = "/home/chenxiaofeng/ssl/cert.pem"
        cert_key = "/home/chenxiaofeng/ssl/key.pem"
        cert_pwd = "123456"
        #ciphers = "PFS:-VERS-TLS1.0:-VERS-TLS1.1:-3DES-CBC:-ARCFOUR-128"
}
/opt/janus/etc/janus/janus.transport.websockets.jcfg, 修改generals和certificates,启用wss。

general: {

        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
}

certificates: {
        cert_pem = "/home/chenxiaofeng/ssl/cert.pem"
        cert_key = "/home/chenxiaofeng/ssl/key.pem"
        cert_pwd = "123456"
        #ciphers = "PFS:-VERS-TLS1.0:-VERS-TLS1.1:-3DES-CBC:-ARCFOUR-128"
}
安装coturn
git clone https://github.com/coturn/coturn
cd coturn
./configure 
make 
sudo make install

运行
/opt/janus/bin/janus --debug-level=7
检查运行端口![在这里插入图片描述](https://img-blog.csdnimg.cn/20210204203336611.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L216dWVy,size_16,color_FFFFFF,t_70#pic_center)![在这里插入图片描述](https://img-blog.csdnimg.cn/20210204203336611.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L216dWVy,size_16,color_FFFFFF,t_70
安装nginx并配置
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210204203527912.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L216dWVy,size_16,color_FFFFFF,t_70)/opt/janus/share/janus/demos/videoroomtest.js加上这一行
![在这里插入图片描述](https://img-blog.csdnimg.cn/2021020420364777.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L216dWVy,size_16,color_FFFFFF,t_70)浏览器中访问192.168.1.6
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210204203912295.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L216dWVy,size_16,color_FFFFFF,t_70)![效果图](https://img-blog.csdnimg.cn/20210204203926830.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L21	6dWVy,size_16,color_FFFFFF,t_70)
安卓端
安卓环境自己搭建
sudo git clone https://github.com/pcgpcgpcg/janus-gateway-android.git

![在这里插入图片描述](https://img-blog.csdnimg.cn/20210204204118591.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L216dWVy,size_16,color_FFFFFF,t_70)
![改成自己的地址](https://img-blog.csdnimg.cn/20210204204306471.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L216dWVy,size_16,color_FFFFFF,t_70)


![在这里插入图片描述](https://img-blog.csdnimg.cn/20210204204334634.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L216dWVy,size_16,color_FFFFFF,t_70)

![在这里插入图片描述](https://img-blog.csdnimg.cn/20210204204349301.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L216dWVy,size_16,color_FFFFFF,t_70)到此完成

你可能感兴趣的:(html5,javascript,java,android,web,app)