此webrtc视频聊天应用程序在过去几个月中一直运行良好。今天,随机地,没有更改代码。该应用程序已停止工作,当我单击连接时,在firefox控制台中出现以下错误:
“ ICE失败,您的TURN服务器似乎已损坏,请参阅about:webrtc了解更多详细信息” “ InvalidStateError:无法在稳定状态下设置远程答复”
我在这里测试了我的转弯服务器:https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/ 并且似乎连接良好。
<div class="quash-demo">
<body onload="showMyFace()">
<div> <button onclick="showFriendsFace()" type="button" class="btn btn-primary btn-lg"> Start Quash</button></div>
<div class="quash-webrtc-container">
<video id="yourVideo" autoplay muted playsinline></video>
<video id="friendsVideo" autoplay playsinline></video>
</div>
</body>
</div>
<script>
var config = {
apiKey: "AIzaSyA4EFWzZG5lCdONactMvD3F71IB0-kliOw",
authDomain: "webrtc-test-ad30b.firebaseapp.com",
databaseURL: "https://webrtc-test-ad30b.firebaseio.com",
projectId: "webrtc-test-ad30b",
storageBucket: "webrtc-test-ad30b.appspot.com",
messagingSenderId: "818501134133"
};
if (!firebase.apps.length) {
firebase.initializeApp({});
}
var database = firebase.database().ref();
var yourVideo = document.getElementById("yourVideo");
var friendsVideo = document.getElementById("friendsVideo");
var yourId = Math.floor(Math.random()*1000000000);
var servers = {'iceServers': [{'urls': 'stun:stun.services.mozilla.com'}, {'urls': 'stun:stun.l.google.com:19302'}, {'urls': 'turn:numb.viagenie.ca','credential': '111222','username': 'scottpiligrim2018@yopmail.com'}]};
var pc = new RTCPeerConnection(servers);
pc.onicecandidate = (event => event.candidate?sendMessage(yourId, JSON.stringify({'ice': event.candidate})):console.log("Sent All Ice") );
pc.onaddstream = (event => friendsVideo.srcObject = event.stream);
function sendMessage(senderId, data) {
var msg = database.push({ sender: senderId, message: data });
msg.remove();
}
function readMessage(data) {
var msg = JSON.parse(data.val().message);
var sender = data.val().sender;
if (sender != yourId) {
if (msg.ice != undefined)
pc.addIceCandidate(new RTCIceCandidate(msg.ice));
else if (msg.sdp.type == "offer")
pc.setRemoteDescription(new RTCSessionDescription(msg.sdp))
.then(() => pc.createAnswer())
.then(answer => pc.setLocalDescription(answer))
.then(() => sendMessage(yourId, JSON.stringify({'sdp': pc.localDescription})));
else if (msg.sdp.type == "answer")
pc.setRemoteDescription(new RTCSessionDescription(msg.sdp));
}
};
database.on('child_added', readMessage);
function showMyFace() {
navigator.mediaDevices.getUserMedia({audio:true, video:true})
.then(stream => yourVideo.srcObject = stream)
.then(stream => pc.addStream(stream));
}
function showFriendsFace() {
pc.createOffer()
.then(offer => pc.setLocalDescription(offer) )
.then(() => sendMessage(yourId, JSON.stringify({'sdp': pc.localDescription})) );
}
</script>
任何建议将不胜感激。昨天的代码是相同的,并且可以正常运行。也不必担心凭据,它们仅用于测试目的。我对问题的根源感到困惑。