0

我正在关注官方的coturn 文档并尝试设置一个coturn服务器来处理STUNTURN请求。我正在使用这个小 JS 脚本测试我的服务器是否正常运行:

function checkTURNServer(turnConfig, timeout){ 

  return new Promise(function(resolve, reject){

    setTimeout(function(){
        if(promiseResolved) return;
        resolve(false);
        promiseResolved = true;
    }, timeout || 5000);

    var promiseResolved = false
      , myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection   //compatibility for firefox and chrome
      , pc = new myPeerConnection({iceServers:[turnConfig]})
      , noop = function(){};
    pc.createDataChannel("");    //create a bogus data channel
    pc.createOffer(function(sdp){
      if(sdp.sdp.indexOf('typ relay') > -1){ // sometimes sdp contains the ice candidates...
        promiseResolved = true;
        resolve(true);
      }
      pc.setLocalDescription(sdp, noop, noop);
    }, noop);    // create offer and set local description
    pc.onicecandidate = function(ice){  //listen for candidate events
      if(promiseResolved || !ice || !ice.candidate || !ice.candidate.candidate || !(ice.candidate.candidate.indexOf('typ relay')>-1))  return;
      promiseResolved = true;
      resolve(true);
    };
  });   
}

并使用我的凭据运行它:

checkTURNServer({"url":"turn:IP1:3478",'username': 'bayaz',"credential":"magi"}).then(function(bool){
    console.log('is TURN server active? ', bool? 'yes':'no');
}).catch(console.error.bind(console));

创建用户的位置;

turnadmin -A -u bayaz -p magi

这是配置文件中未注释的行:

listening-port=3478
tls-listening-port=5349
listening-ip=IP1
listening-ip=IP2    
verbose 
lt-cred-mech
realm=mydomain.com
cert=/etc/letsencrypt/live/mydomain.com/cert.pem
pkey=/etc/letsencrypt/live/mydomain.com/privkey.pem

这是运行的输出turnserver -c path/to/file.conf

0: log file opened: /var/tmp/turn_10200_2019-05-17.log
0: Listener address to use: IP1
0: Listener address to use: IP2
0: 
RFC 3489/5389/5766/5780/6062/6156 STUN/TURN Server
Version Coturn-4.5.0.8 'dan Eider'
0: 
Max number of open files/sockets allowed for this process: 4096
0: 
Due to the open files/sockets limitation,
max supported number of TURN Sessions possible is: 2000 (approximately)
0: 

==== Show him the instruments, Practical Frost: ====

0: TLS supported
0: DTLS supported
0: DTLS 1.2 supported
0: TURN/STUN ALPN supported
0: Third-party authorization (oAuth) supported
0: GCM (AEAD) supported
0: OpenSSL compile-time version: OpenSSL 1.0.2k-fips  26 Jan 2017 (0x100020bf)
0: 
0: SQLite supported, default database location is /usr/local/var/db/turndb
0: Redis is not supported
0: PostgreSQL is not supported
0: MySQL is not supported
0: MongoDB is not supported
0: 
0: Default Net Engine version: 3 (UDP thread per CPU core)

=====================================================

0: Domain name: 
0: Default realm: mydomain.com
0: SSL23: Certificate file found: /etc/letsencrypt/live/mydomain.com/cert.pem
0: SSL23: Private key file found: /etc/letsencrypt/live/mydomain.com/privkey.pem
0: TLS1.0: Certificate file found: /etc/letsencrypt/live/mydomain.com/cert.pem
0: TLS1.0: Private key file found: /etc/letsencrypt/live/mydomain.com/privkey.pem
0: TLS1.1: Certificate file found: /etc/letsencrypt/live/mydomain.com/cert.pem
0: TLS1.1: Private key file found: /etc/letsencrypt/live/mydomain.com/privkey.pem
0: TLS1.2: Certificate file found: /etc/letsencrypt/live/mydomain.com/cert.pem
0: TLS1.2: Private key file found: /etc/letsencrypt/live/mydomain.com/privkey.pem
0: TLS cipher suite: DEFAULT
0: DTLS: Certificate file found: /etc/letsencrypt/live/mydomain.com/cert.pem
0: DTLS: Private key file found: /etc/letsencrypt/live/mydomain.com/privkey.pem
0: DTLS1.2: Certificate file found: /etc/letsencrypt/live/mydomain.com/cert.pem
0: DTLS1.2: Private key file found: /etc/letsencrypt/live/mydomain.com/privkey.pem
0: DTLS cipher suite: DEFAULT
0: Relay address to use: IP1
0: Relay address to use: IP2
Cannot create pid file: /var/run/turnserver.pid: Permission denied
0: Cannot create pid file: /var/run/turnserver.pid
0: pid file created: /var/tmp/turnserver.pid
0: IO method (main listener thread): epoll (with changelist)
0: Wait for relay ports initialization...
0:   relay IP1 initialization...
0:   relay IP1 initialization done
0:   relay IP2 initialization...
0:   relay IP2 initialization done
0: Relay ports initialization done
0: IO method (general relay thread): epoll (with changelist)
0: turn server id=1 created
0: IPv4. TLS/SCTP listener opened on : IP1:3478
0: IPv4. TLS/TCP listener opened on : IP1:3478
0: IPv4. TLS/SCTP listener opened on : IP1:3479
0: IPv4. TLS/TCP listener opened on : IP1:3479
0: IPv4. TLS/SCTP listener opened on : IP1:5349
0: IPv4. TLS/TCP listener opened on : IP1:5349
0: IPv4. TLS/SCTP listener opened on : IP1:5350
0: IPv4. TLS/TCP listener opened on : IP1:5350
0: IPv4. TLS/SCTP listener opened on : IP2:3478
0: IPv4. TLS/TCP listener opened on : IP2:3478
0: IPv4. TLS/SCTP listener opened on : IP2:3479
0: IPv4. TLS/TCP listener opened on : IP2:3479
0: IPv4. TLS/SCTP listener opened on : IP2:5349
0: IPv4. TLS/TCP listener opened on : IP2:5349
0: IPv4. TLS/SCTP listener opened on : IP2:5350
0: IPv4. TLS/TCP listener opened on : IP2:5350
0: IO method (general relay thread): epoll (with changelist)
0: turn server id=0 created
0: IPv4. TLS/TCP listener opened on : IP1:3478
0: IPv4. TLS/TCP listener opened on : IP1:3479
0: IPv4. TLS/TCP listener opened on : IP1:5349
0: IPv4. TLS/TCP listener opened on : IP1:5350
0: IPv4. TLS/TCP listener opened on : IP2:3478
0: IPv4. TLS/TCP listener opened on : IP2:3479
0: IPv4. TLS/TCP listener opened on : IP2:5349
0: IPv4. TLS/TCP listener opened on : IP2:5350
0: IPv4. DTLS/UDP listener opened on: IP1:3478
0: IPv4. DTLS/UDP listener opened on: IP1:3479
0: IPv4. DTLS/UDP listener opened on: IP1:5349
0: IPv4. DTLS/UDP listener opened on: IP1:5350
0: IPv4. DTLS/UDP listener opened on: IP2:3478
0: IPv4. DTLS/UDP listener opened on: IP2:3479
0: IPv4. DTLS/UDP listener opened on: IP2:5349
0: IPv4. DTLS/UDP listener opened on: IP2:5350
0: Total General servers: 2
0: IO method (admin thread): epoll (with changelist)
0: IO method (auth thread): epoll (with changelist)
0: IO method (auth thread): epoll (with changelist)
0: IPv4. CLI listener opened on : 127.0.0.1:5766
0: SQLite DB connection success: /usr/local/var/db/turndb

当我测试我的轮到服务器时,我"is TURN server active? no"在控制台中收到了我的自定义错误消息,这表明我没有得到服务器的响应。

我已经花了几天时间试图弄清楚这一点,但我没有运气。我在这里想念什么?

4

1 回答 1

0
sudo systemctl start coturn

是做这些事情的简单方法......当然你可以使用turnserver命令,但适合你的情况的正确命令并不容易做到。使用该命令,您可以启动 turn.conf 服务器,而不会出现其他问题....这是我的配置webrtc 应用程序显示我的 Turn 服务器已损坏,但它可以工作...我在本地服务器 apache2 中将它与 dns 一起使用,并带有重定向和代理,所有流量 UDP 都在 443 端口上(显然不适合轮流)。科特恩是 4.5。注意 no-cli 和 all cli 选项...如果我只使用 no-cli 选项,则服务器不会运行。也阅读我的回复。

于 2019-05-18T21:21:23.910 回答