我正在尝试在网页上实施WebRTC。我想使用TURN服务器进行通信,以确保一切对每个人都能正常工作。我的TURN服务器配置如下。在Javascript中将数据提供给TURN / STUN服务器。我的网页尚未完成,因为我遇到了一些问题,而且我不知道如何将某些用户彼此联系起来。我收集到的事实是,STUN / TURN给广播方UDP端口以进行通信,这是给接收方的,但是我认为问题出在浏览器<-> turnserver连接中,因为localDescription中没有任何端口或ip地址,并且只有本地主机地址代替。我的问题是,问题出在哪里?在配置或代码中。两者都附在下面。
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<p>
This example shows you the contents of the selected part of your display.
Click the Start Capture button to begin.
</p>
<p><button id="start">Start Capture</button> <button id="stop">Stop Capture</button></p>
<video style="width: 960px; height: 540px;" id="video" autoplay></video>
<video style="width: 960px; height: 540px;" id="remote-video" autoplay></video>
<br>
<strong>Log:</strong>
<br>
<pre id="log"></pre>
</body>
</html>
const Sender = new RTCPeerConnection({
iceServers: [
{
urls: "stun:<ip-address>:3478"
},
{
urls: "turn:<ip-address>:3478",
username: "<user>",
credential: "<pass>"
}
]
});
var displayMediaOptions = {
audio: false,
video: {
cursor: "always"
}
};
navigator.mediaDevices.getDisplayMedia(displayMediaOptions)
.then(stream => {
document.getElementById("video").srcObject = stream;
for (let track of stream.getTracks()) {
Sender.addTrack(track);
}
return Sender.createOffer();
})
.then(offer => {
Sender.setLocalDescription(new RTCSessionDescription(offer));
console.log(Sender.localDescription);
})
//.then(() => Reciver.setRemoteDescription(Sender.localDescription))
//.then(() => Reciver.createAnswer())
//.then(answer => Reciver.setLocalDescription(new RTCSessionDescription(answer)))
// .then(() => Sender.setRemoteDescription(Reciver.localDescription));
#**VPS server config (/etc/turnserver.conf)**
cli-password=12345678
listening-port=3478
#tls-listening-port=443
listening-ip=<my-server-ip>
relay-ip=<my-server-ip>
external-ip=<my-server-ip>
realm=<my-server-address>
server-name=<my-server-address>
lt-cred-mech
#userdb=/etc/turnuserdb.conf
user=<user:pass>
# use real-valid certificate/privatekey files
#cert=/etc/ssl/certificate.pem
#pkey=/etc/ssl/private.key
no-stdout-log
sdp: "v=0
↵o=- 409204313020118480 2 IN IP4 127.0.0.1
↵s=-
↵t=0 0
↵a=group:BUNDLE 0
↵a=msid-semantic: WMS
↵m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 122 127 121 125 107 108 109 124 120 123 119 114 115 116
↵c=IN IP4 0.0.0.0
↵a=rtcp:9 IN IP4 0.0.0.0
↵a=ice-ufrag:j2gk
↵a=ice-pwd:y+bSuFIV7IeKCoFDVbB4Lvw5
↵a=ice-options:trickle
↵a=fingerprint:sha-256
1E:44:A1:31:E5:80:B1:3C:14:56:EA:7A:5F:9C:5B:58:75:DA:3C:ED:D1:EB:77:DD:58:B8:C5:96:68:CC:AF:7E
↵a=setup:actpass
(...)