0

我在本地主机上的 ubuntu 中运行 coturn 服务器这是我的 turnserver.conf

verbose
listening-ip=127.0.0.1
realm=test.demo
static-auth-secret=fb1d5d356dff13e709980e2a07dfcef130a713d53e4c6701efe4b770f27e17d4
use-auth-secret

启动服务器为

service coturn start
service coturn status

回来

● coturn.service - LSB: coturn TURN Server
   Loaded: loaded (/etc/init.d/coturn; generated)
   Active: active (running) since Fri 2020-10-02 17:28:08 PKT; 3s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 18905 ExecStop=/etc/init.d/coturn stop (code=exited, status=0/SUCCESS)
  Process: 18912 ExecStart=/etc/init.d/coturn start (code=exited, status=0/SUCCESS)
    Tasks: 15 (limit: 4915)
   CGroup: /system.slice/coturn.service
           └─18934 /usr/bin/turnserver -c /etc/turnserver.conf -o -v

Oct 02 17:28:08 user-Inspiron-7773 systemd[1]: Starting LSB: coturn TURN Server...
Oct 02 17:28:08 user-Inspiron-7773 coturn[18912]:  * Starting coturn  turnserver
Oct 02 17:28:08 user-Inspiron-7773 coturn[18912]:    ...done.
Oct 02 17:28:08 user-Inspiron-7773 systemd[1]: Started LSB: coturn TURN Server.

sudo netstat -npta | grep turnserver给出

tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    

我已经生成了临时用户名和密码

val secretKey = "fb1d5d356dff13e709980e2a07dfcef130a713d53e4c6701efe4b770f27e17d4"
val userId= "abcd1234"
val ttl:Long = 3600 * 6
val unixTimeStamp =System.currentTimeMillis()/1000L + ttl
val userName = unixTimeStamp +":"+ userId
val secret = new SecretKeySpec(secretKey.getBytes, "HmacSHA1")
val mac = Mac.getInstance("HmacSHA1")
mac.init(secret)
val result: Array[Byte] = mac.doFinal(userName.getBytes)
val hashStr= new String(result.map(_.toChar))
val password = Base64.getEncoder.encodeToString(hashStr.getBytes())

它产生输出用户名:1​​601663142:abcd1234 密码:Wi4H776QJCoFbe+/hgrvv7Pvv5te77+m776L776K776N77+Y77+UUQ==

我首先在 chrome 控制台中以两种方式对此进行了测试,以下代码引发了异常

var iceConfiguration = {
    iceServers: [
        {
            urls: 'turn:127.0.0.1:3478',
            username: '1601663142:abcd1234',
            credentials: 'Wi4H776QJCoFbe+/hgrvv7Pvv5te77+m776L776K776N77+Y77+UUQ=='
        }

    ]
}

var peerConnection = new RTCPeerConnection(iceConfiguration);

Uncaught DOMException: Failed to construct 'RTCPeerConnection': Both username and credential are required when the URL scheme is "turn" or "turns".
    at <anonymous>:12:22
(anonymous) @ VM41:12

三片冰

在此处输入图像描述

我怎样才能让它工作

4

1 回答 1

1

我认为答案很简单,您已经指定credentials并且错误是credential缺少,所以删除并重s试。

于 2021-08-28T17:00:26.780 回答