我在 Python 中使用 Django 频道的后端。在其中,我有一个选择在线用户并将数据发送给另一个用户的方法。
但是当我要建立连接时,出现了一些错误和不稳定的情况。有时它可以完美运行并建立连接,有时会出现错误。
似乎“ICE Candidate”的发送随机进入了所有内容的前面,导致错误。有时它仅在响应后调用。
这个初始序列在我的 Javascript 中的 WebRTC 中是否正确?(OnIceCandidate 一直在拍摄)
function getUserMediaSuccess(stream) {
window.localStream = localStream = stream;
localVideo.srcObject = stream;
// localVideo.src = window.URL.createObjectURL(stream);
var iceServers = {
'iceServers': [
{'urls': 'stun:stun.services.mozilla.com'},
{'urls': 'stun:stun.l.google.com:19302'},
]
};
//creating our RTCPeerConnection object
peerConnection = new RTCPeerConnection(iceServers);
console.log("RTCPeerConnection object was created");
console.log(peerConnection);
peerConnection.addStream(localStream);
if ('ontrack' in peerConnection) {
// WebRTC Spec, Firefox
peerConnection.ontrack = function (event) {
remoteVideo.srcObject = event.streams[0];
};
} else {
// Chrome, etc. This can be removed once all browsers support `ontrack`
peerConnection.onaddstream = function (event) {
// remoteVideo.src = window.URL.createObjectURL(event.stream);
remoteVideo.srcObject = event.stream;
};
}
//setup ice handling
//when the browser finds an ice candidate we send it to another peer
peerConnection.onicecandidate = function (event) {
if (event.candidate) {
send("candidate", {candidate: event.candidate});
}
};
peerConnection.ondatachannel = function(event) {
var receiveChannel = event.channel;
receiveChannel.onmessage = function(event) {
console.log("ondatachannel message:", event.data);
};
};
openDataChannel();
}
- 不连接时...
日志 - 用户 1
Websocket Connected
RTCPeerConnection object was created
Send: Notices that it is available...
Received: Found peer
Send: offer
Send: candidate
Received: candidate
Uncaught (in promise) DOMException: Error processing ICE candidate
Received: candidate
Uncaught (in promise) DOMException: Error processing ICE candidate
Received: answer
Received: candidate
日志 - 用户 2
Websocket Connected
RTCPeerConnection object was created
Send: Notices that it is available...
Received: candidate
Uncaught (in promise) DOMException: Error processing ICE candidate
Uncaught (in promise) DOMException: Error processing ICE candidate
Uncaught (in promise) DOMException: Error processing ICE candidate
Received: offer
Send: answer
Received: candidate
Send: candidate
Received: candidate
Send: candidate
Received: candidate
Send: candidate
Received: candidate
- 当你连接...
日志 - 用户 1
Websocket Connected
RTCPeerConnection object was created
Send: Notices that it is available...
Received: Found peer
Send: offer
Send: candidate
Received: candidate
Uncaught (in promise) DOMException: Error processing ICE candidate
Received: candidate
Uncaught (in promise) DOMException: Error processing ICE candidate
Received: answer
Received: candidate
日志 - 用户 2
Websocket Connected
RTCPeerConnection object was created
Send: Notices that it is available...
Received: candidate
Uncaught (in promise) DOMException: Error processing ICE candidate
Received: candidate
Uncaught (in promise) DOMException: Error processing ICE candidate
Received: candidate
Uncaught (in promise) DOMException: Error processing ICE candidate
Received: offer
Send: answer
Send: candidate
Received: candidate
Send: candidate
Received: candidate