我在本地主机上运行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())并生成输出用户名:1601663142: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

我怎么才能让它工作呢?
发布于 2021-08-28 17:00:27
我认为答案很简单,您已经指定了credentials,但错误是缺少credential,因此删除s并重试。
https://stackoverflow.com/questions/64172040
复制相似问题