我不明白为什么我的 TURN 服务器测试不起作用。
我的 coturn 服务器(在主机容器中):10.200.197.74
我的网络服务器((WSL)位于带有 -p 80:80 和 -p 3478:3478 的桥接容器中):10.200.194.65
它们都可以 ping 自己,并且
turnutils_uclient 10.200.197.74 -u username -w password -y
可以正常工作,网络服务器不会出现任何问题。
这是我用来测试我的服务器的代码(来自https://hackernoon.com/a-simple-script-to-test-whether-a-stunturn-server-is-working-properly):
<!DOCTYPE html>
<html>
<head>
<title>Test Stun/Turn Servers</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<h1>Test Ice Servers</h1>
<hr />
<pre id='ice' style='overflow: auto'></pre>
<hr />
<p id='ip'></p>
<p id='stun'>🔴 The STUN server is NOT reachable!</p>
<p id='turn'>🔴 The TURN server is NOT reachable!</p>
<p id='err'></p>
<hr />
<script>
const Ice = document.getElementById('ice');
const IP = document.getElementById('ip');
const Stun = document.getElementById('stun');
const Turn = document.getElementById('turn');
const Err = document.getElementById('err');
const iceServers = [
// Test some STUN server
{
urls: 'stun:stun.l.google.com:19302',
},
// Test some TURN server
{
urls: 'turn:10.200.197.74',
username: 'username',
credential: 'password',
},
];
// Print iceServers config
Ice.innerHTML = JSON.stringify(iceServers, null, 4);
// Test the connections
const pc = new RTCPeerConnection({
iceServers
});
pc.onicecandidate = (e) => {
if (!e.candidate) return;
console.log(e.candidate.candidate);
// If a srflx candidate was found, notify that the STUN server works!
if (e.candidate.type == 'srflx' || e.candidate.candidate.includes('srflx')) {
let ip = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
let address = e.candidate.address
? e.candidate.address
: e.candidate.candidate.match(ip);
IP.innerHTML = '🟢 Your Public IP Address is ' + address;
Stun.innerHTML = '🟢 The STUN server is reachable!';
}
// If a relay candidate was found, notify that the TURN server works!
if (e.candidate.type == 'relay' || e.candidate.candidate.includes('relay')) {
Turn.innerHTML = '🟢 The TURN server is reachable!';
}
};
// handle error
pc.onicecandidateerror = (e) => {
console.error(e);
Err.innerHTML = '🔴 Error: ' + e.errorText;
};
pc.createDataChannel('test');
pc.createOffer().then(offer => pc.setLocalDescription(offer));
</script>
</body>
</html>
网页总是返回“🔴无法访问 TURN 服务器!”
我不明白为什么,因为
turnutils_uclient 10.200.197.74 -u username -w password -y
的网络服务器没有任何问题。
这是我的 coTURN 配置文件
listening-ip=10.214.197.74
listening-port=3478
min-port=49152
max-port=49999
verbose
lt-cred-mech
user=username:password
我希望 TURN 服务器测试能够在 js 中运行
问题来自 TURN 服务器配置文件。
我将
realm=mydomain.com
添加到conf 文件中并且它起作用了。