본문 바로가기
Web/WebRTC

[Kurento] 배포 가이드/네트워크 구성

by 정고정 2022. 2. 28.
반응형

❗ kurento tutorial의 view는 vanila js로 구현되어 있으며, react에서는 세션 이슈가 발생할 수 있습니다.

 

 

N:N 화상이 가능한 Kurento group call 예제를 이용했다.

사실 공식 홈페이지에 웬만한 설명은 다 되어 있지만 배포까지 가려면 조금 신경 써 줄 부분이 있다.

 

Tutorials — Kurento 6.16.0 documentation

» Tutorials Edit on GitHub <!-- "admonition" is the class of Warning messages with the current RTD theme. Obtained by directly checking the HTML sources of an already existing block. --> Warning Kurento is a low-level platform to create WebRTC application

doc-kurento.readthedocs.io

 

 

들어가기 전에

Kurento groupcall tutorial을 이용합니다.
localhost라고 써 놓은 친구는 배포주소로 바꿔서 돌려주세요. 진짜 localhost로 치면 컴퓨터 로컬로 감.

 

배포를 위해 돌려야 할 친구들은 다음과 같다.

  • Kurento Media Server(docker)
  • Kurento groupcall tutorial(Signalling + Client)
  • coturn

KMS(docker ver.)

kurento media server는 도커로 돌리는 게 가장 편하다.

kurento에서 이용하는 TCP 8888 포트와 UDP [5000, 5050] 범위 포트를 연결해서 도커 컨테이너를 돌린다.

docker run --rm \
    -p 8888:8888/tcp \
    -p 5000-5050:5000-5050/udp \
    -e KMS_MIN_PORT=5000 \
    -e KMS_MAX_PORT=5050 \
    kurento/kurento-media-server:latest

sudo docker ps -a 찍어보면 예쁘게 돌고 있는 컨테이너를 확인할 수 있다.

Signalling

배포

먼저 tutorial을 clone 받아 준다.

kurento tutorial은 여러가지 튜토리얼을 모듈로 가지고 있으므로 최상단의 pom.xml과 kurento groupcall tutorial 폴더를 가져다가 컨테이너 안에 넣어 준다.

 

https://github.com/Kurento/kurento-tutorial-java

 

GitHub - Kurento/kurento-tutorial-java

Contribute to Kurento/kurento-tutorial-java development by creating an account on GitHub.

github.com

 

배포 컨테이너 용량이 넉넉하다면 그냥 튜토리얼을 통으로 받아 넣고 원하는 예제만 실행시켜도 된다.

git clone <https://github.com/Kurento/kurento-tutorial-java.git>
cd kurento-tutorial-java/kurento-group-call
git checkout master
mvn -U clean spring-boot:run

❓ 배포 컨테이너에 mvn 깔려 있나요?

mvn-v

 

백그라운드에서 계속 배포되도록 하고 싶다면 nohup mvn -U clean spring-boot:run & 으로 실행한다.

배포 확인

https://localhost:8443

kurento tutorial에는 keystore가 포함되어 있으므로 https로 돌아간다.

배포주소의 https 8443 포트로 접속해 서버가 잘 돌고 있는지 확인해 준다.

groupcall tutorial은 SPA 어플리케이션이므로 뷰와 서버가 같은 포트에서 돈다.

Coturn

설정

  1. 3478, 5349(TLS) 포트 열기

방화벽을 열어 준다. 그런데 만약 CLI에서 수정해야 한다면..?

  1. sudo vi /etc/default/coturn -> TURNSERVER\_ENABLE=1로 바꿔주기
  2. sudo vi /etc/turnserver.conf -> 배포서버의 public ip와 private ip를 적어 준다.
listening-port=3478
tls-listening-port=5349

external-ip=퍼블릭ip/프라이빗ip
listening-ip=프라이빗ip
relay-ip=프라이빗ip

# Lower and upper bounds of the UDP relay endpoints:
# (default values are 49152 and 65535)
min-port=49152
max-port=65535

# Uncomment to run TURN server in 'normal' 'moderate' verbose mode.
# By default the verbose mode is off.
verbose

# Uncomment to use fingerprints in the TURN messages.
# By default the fingerprints are off.
fingerprint

# Uncomment to use long-term credential mechanism.
# By default no credentials mechanism is used (any user allowed).
lt-cred-mech

# Server name used for
# the oAuth authentication purposes
realm=<domain>

# define user and password (usr:pass)
user=<ID>:<PASSWORD>

logfile=/var/log/turn.log
simple-log​

ec2 local ip 확인하기 curl http://169.254.169.254/latest/meta-data/local-ipv4
ec2 public ip 확인하기 curl http://169.254.169.254/latest/meta-data/public-ipv4

  1. sudo service coturn start로 coturn서버 키고 https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/ 에 들어가서 coturn서버 접속

Kurento와 Coturn 연결

groupcall 예제와 KMS 도커를 배포 컨테이너에서 잘 실행시켰다면 어디서나 서비스에 접속할 수 있다.

하지만 다른 네트워크 망에 있는 사용자의 영상을 보려면 coturn 서버를 추가적으로 연결해줘야만 한다.

Kurento Media Server (Docker.ver)

  1. KMS Container image 내부로 접속
sudo docker exec -it 2dd61af58054 bin/bash
  1. /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini에서 turnURL=${사용자이름}:${비밀번호}@${publicIP}:3478?transport=tcp 로 수정

Kurento Signalling Server(Client)

SPA 방식으로, 서버와 클라이언트가 붙어 있다. 클라이언트 단에 coturn 서버를 명시해준다.

kurento-group-call/src/main/resources/static/js/conferenceroom.js

onExistingParticipants(msg), receiveVideo(sender) 함수 안의 var options코드 변경

var options={
    localVideo: video,
    mediaConstraints: constraints,
    configuration: {
        iceServers:[{urls: 'turn:${publicIP}:3478', username: '사용자이름', credential: '비밀번호'}],
        iceTransportPolicy: 'relay'
    },
    onicecandidate: participant.onIceCandidate.bind(participant)
}

저장한 뒤 시그널링 서버가 돌아가는 8443포트를 껐다가 다시 실행해 준다.

sudo kill -15 $(sudo lsof -t -i:8443)
mvn -U clean spring-boot:run

여기까지 하고 클라이언트랑 서버가 같이 돌고 있는 https://localhost:8443에 접속해 보면 같은 방에 접속한 사용자의 캠 화면이 보이는 것을 확인할 수 있다.

WebRTC는 크로미움 오픈소스 기반 브라우저(Chrome, Whale 등)에서 작동하며, 개발자 도구(F12)를 켜 봤을 때 WebSocket Connected가 뜨고 다른 사용자의 iceCandidate를 막 불러오면 성공이다.

 

 

+)

Coturn 서버 시작 및 종료

재시작 sudo service coturn restart
시작 sudo service coturn start
정지 sudo service coturn stop
확인 sudo service coturn status

Coturn 서버 접속

STUN or TURN URI turn:${publicIP}:3478?transport=tcp
TURN username ${본인username}
TURN password ${본인password}

반응형

댓글