카테고리 없음

Janus Gateway

dev_jiwon 2023. 2. 6.

Janus Gateway

Janus Gateway는 WebRTC를 사용할 수 있게 구현한 WebRTC Server이다. 기본적인 WebRTC 기능을 포함하며, Meetecho팀이 구현한 여러 종류의 플러그인이 제공된다. 브라우저에서는 제공된  플러그인의 여러 기능(echo tests, conference bridges, media recorders, SIP gateways 등)을 사용할 수 있다. 또한, Janus는 ICE, DTLS, SRTP 모두를 제공한다. 따로 구성할 필요가 없다.

 

Janus는 ICE Server 역할을 포함한다. ICE Sever 역할을 한다는 것은 P2P 연결의 중간자 역할을 한다는 것이다. Janus를 사용하지 않고 WebRTC를 구현할 때, NAT 외부의 사용자와 연결할 경우엔 꼭 STUN이나 TURN에 요청해, 상대방의 SDP 정보를 받은 후에 P2P 연결이 가능하다. Janus를 거치지 않은 경우, TURN 서버가 ICE Server의 역할을 할 수 있다 핮만, 우리는 Janus를 사용한 케이스만 보기로하자. Janus가 ICE Server의 역할을 하며, 브라우저는 ICE Server를 통해 P2P 연결을 구성한다. ICE : Interactive Connectivity Establishment (상호 연결을 돕는 프레임워크) 그리하여 Janus가 P2P 연결의 중간자 역할을 담당한다.

 

Janus Installation

Janus Github repo 페이지를 보면 설치 과정이 자세하게 설명되어있다.

Dependencies
To install it, you'll need to satisfy the following dependecies:

 

Jansson

  • Janus는 C언어로 개발된 서버이다. C언어에서 JSON 타입을 인코딩/디코딩 하기 위해 사용되는 라이브러리이다.

libconfig

  • config 세팅을 위한 라이브러리로, Janus config file 구성을 위해 필수이다.

libnice (at least v0.1.16 suggested, v0.1.18 recommended)

  • ICE(Interactive Connectivity Setup) 표준(RFC 5245 & RFC 8445)을 구현하는 라이브러리이다.

OpenSSL (at least v1.0.1e)

  • TLS 및 SSL 사용을 위한 라이브러리입니다.

libsrtp (at least v2.x suggested)

  • SRTP(Secure Real-time Transport Protocol)를 위한 라이브러리입니다. README.md에도 쓰여 있듯이 2.2.0 버전을 사용하길 바란다. 2.3.0 버전 사용 시, 에러가 발생할 수 있으며, 이는 --enable-openssl 이나 --enable-nss flag를 설정함으로써 해결할 수 있다고 나와 있지만 에러가 발생한 버전이니 추천하지 않는 것 같다. (설치 과정에도 2.2.0 버전을 사용하도록 안내되어 있다.)

usrsctp (only needed if you are interested in Data Channels)

  • 데이터 채널을 사용할 때만 필요하다.

libwebsockets (only needed if you are interested in WebScokets support for the Janus API)

  • Janus는 Websocket 방식과 http를 사용한 long poll 방식으로 사용이 가능하다. libewebsockets는 Websocket 방식을 사용할 때 필요하다.

cmake (only needed if you are interested in WebSockets and/or BoringSSL support, as they make use of it)

  • Websocket 방식을 사용하려면 필요하다.

rabbitmq-c (only needed if you ar interested in RabbitMQ support for the Janus API or events)

  • Messaging에 queue 방식을 사용할 때 필요하다.

paho.mqtt.c (only needed if you are interested in MQTT support for the Janus API or events)

  • C언어 기반의 MQTT 클라이언트이며, IOT를 위한 라이브러리이다.

nanomsg (only needed if you are interested in the TURN REST API support)

  • 몇 가지 일반적인 통신 패턴을 제공하는 소켓 라이브러리이다. 네트워키 계층을 빠르게, 확장 가능하게, 사용하기 쉽게 만드는 것을 목표료한다.

libcurl (only needed if you are interseted in the TURN REST API support)

  • 멀티프로토콜 파일 전송 라이브러리로, 클라이언트 사이드의 URL 전송 라이브러리이다.

이하 라이브러리는 본인이 사용할 플러그인에 따라 설치하면된다.

A couple of plugins depend on a few more libraries:

Sofia-SIP (only needed for the SIP plugin)
libopus (only needed for the AudioBridge plugin)
libogg (needed for the VoiceMail plugin and/or post-processor, and optionally AudioBridge and Streaming plugins)
libcurl (only needed if you are interested in RTSP support in the Streaming plugin or in the sample Event Handler plugin)
Lua (only needed for the Lua plugin)

아래 라이브러리 / 도구는 필요합니다.
Additionally, you'll need the following libraries and tools:

GLib
zlib
pkg-config
gengetopt

 

 

설치과정은 Janus Gateway Github 페이지에 나온 순서대로 진행하면된다. Janus 서버 빌드하는 과정에 많은 dependencies가 요구되어, 로컬 pc의 환경에 설치하는게 부담이 될 수도 있다. 그럴 때는 아래 Dockerfile을 참고하여 Image를 빌드한 후에 사용하면 된다.

Dockerfile

FROM ubuntu:bionic
RUN echo ' \n\
APT::Periodic::Update-Package-Lists "0";\n\
APT::Periodic::Unattended-Upgrade "1";\n'\
> /etc/apt/apt.conf.d/20auto-upgrades
RUN set -x \
    && apt-get update && apt-get install -y build-essential snapd aptitude git wget golang \
    python3 python3-pip python3-setuptools python3-wheel ninja-build \
    libgstreamer1.0-dev libgirepository1.0-dev libunwind-dev apt-utils libsrtp-dev \
    gdb \
    && aptitude install -y libmicrohttpd-dev libjansson-dev libnice-dev \
    libssl-dev libsofia-sip-ua-dev libglib2.0-dev libopus-dev libogg-dev \
    libconfig-dev libavutil-dev libavcodec-dev libavformat-dev libnanomsg-dev \
    libcurl4-openssl-dev liblua5.3-dev pkg-config gengetopt libtool automake curl jq httpie vim screen doxygen graphviz
RUN set -x \
    && wget https://cmake.org/files/v3.16/cmake-3.16.2.tar.gz \
    && tar -xvzf cmake-3.16.2.tar.gz \
    && cd cmake-3.16.2 \
    && ./bootstrap --prefix=/usr/local \
    && make && make install
RUN set -x \
    && python3 -m pip install meson \
    && python3 -m pip install ninja
RUN  set -x \
    && cd  \
    && 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
RUN  set -x \
    && git clone https://boringssl.googlesource.com/boringssl \
    && cd boringssl \
    && sed -i s/" -Werror"//g CMakeLists.txt \
    && mkdir -p build \
    && cd build \
    && cmake -DCMAKE_CXX_FLAGS="-lrt" .. \
    && make \
    && cd .. \
    && mkdir -p /opt/boringssl \
    && cp -R include /opt/boringssl/ \
    && mkdir -p /opt/boringssl/lib \
    && cp build/ssl/libssl.a /opt/boringssl/lib/ \
    && cp build/crypto/libcrypto.a /opt/boringssl/lib/
RUN  set -x \
    && git clone https://github.com/sctplab/usrsctp \
    && cd usrsctp \
    && ./bootstrap \
    && ./configure --prefix=/usr --disable-programs --disable-inet --disable-inet6 \ 
    && make && make install
RUN  set -x \
    && git clone https://github.com/warmcat/libwebsockets.git \
    && cd libwebsockets \
    && mkdir build \
    && cd build \
    && cmake -DLWS_MAX_SMP=1 -DLWS_WITHOUT_EXTENSIONS=0 -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" .. \
    && make && make install
RUN set -x \
    && git clone https://github.com/eclipse/paho.mqtt.c.git \
    && cd paho.mqtt.c \
    && make && make install
RUN set -x \
    && git clone https://github.com/alanxz/rabbitmq-c \
    && cd rabbitmq-c \
    && git submodule init \
    && git submodule update \
    && mkdir build && cd build \
    && cmake -DCMAKE_INSTALL_PREFIX=/usr .. \
    && make && make install
RUN set -x \
    && git clone https://gitlab.freedesktop.org/libnice/libnice \
    && cd libnice \
    && meson --prefix=/usr build && ninja -C build && ninja -C build install
RUN export JANUS_WITH_POSTPROCESSING
RUN  set -x \
    && git clone https://github.com/meetecho/janus-gateway.git \
    && cd janus-gateway \
    && sh autogen.sh \
    && ./configure --prefix=/opt/janus \
    && make \
    && make install \
    && make configs
RUN  set -x \
    && rm -rf /libwebsockets \
    && rm -rf /janus-gateway \
    && rm -rf /boringssl
RUN adduser --disabled-password --gecos '' janus
USER janus
RUN /opt/janus/bin/janus --v
CMD ["/opt/janus/bin/janus"]
위의 순서로 진행하시면 되고, 아래 몇 개의 디렉터리를 제거한 이유는 단순히 image 크기를 줄이기 위함입니다.
맨 위의 update 관련한 내용은 OS 버전 업그레이드를 자동으로 수행하는 걸 방지합니다.
apt 패키지 설치하는 파트에서 시간이 꽤 많이 소요되며, 메모리를 많이 사용하게 됩니다.
빌드할 때 가급적 다른 프로세스를 추가 동작하지 않는 게 좋습니다.
한 번 빌드를 하면 각 스텝 별로 caching되기 떄문에 다시 빌드할 때에 큰 부담이 없습니다.
apt 패키지만 설치하는 image를 만들고 그 image를 사용해서 새로운 Dockerfile을 작성하셔도 됩니다.

 

 

 

참고

https://velog.io/@vamos_eon/Janus-Gateway-1-WebRTC%EB%9E%80-%EB%AC%B4%EC%97%87%EC%9D%B8%EA%B0%80-%EC%84%A4%EC%B9%98%EA%B9%8C%EC%A7%80

 

Janus Gateway (1) :: WebRTC란 무엇인가? & 설치까지

안녕하세요, 주니어 개발자 Eon입니다. 오늘은 WebRTC에 대해 알아보겠습니다. 최근에 코로나 팬데믹으로 재택 근무가 자리 잡고, 학교는 비대면 수업을 진행하게 됐습니다. 그로 인해, 화상회의가

velog.io

 

댓글