javascript WebRTC 无法添加 ICE 候选
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25355913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WebRTC The ICE candidate could not be added
提问by yang Joe
I am trying to establish a p2p audio/video connection b/w two peers. Following: Getting started with WebRTC.
我正在尝试建立 b/w 两个对等点的 p2p 音频/视频连接。如下:WebRTC 入门。
It works fine at my home in LAN Environment between 2 PCs, but throws an error message when running at my company's LAN Environment, there is part the javascript
它在我家的 2 台 PC 之间的 LAN 环境中运行良好,但是在我公司的 LAN 环境中运行时会抛出错误消息,部分是 javascript
function processSignalingMessage(message) {
var msg = JSON.parse(message);
if (msg.type === 'offer') {
// Callee creates PeerConnection
if (!initiator && !started)
maybeStart();
// We only know JSEP version after createPeerConnection().
if (isRTCPeerConnection)
pc.setRemoteDescription(new RTCSessionDescription(msg));
else
pc.setRemoteDescription(pc.SDP_OFFER,
new SessionDescription(msg.sdp));
doAnswer();
} else if (msg.type === 'answer' && started) {
pc.setRemoteDescription(new RTCSessionDescription(msg));
} else if (msg.type === 'candidate' && started) {
var candidate = new RTCIceCandidate({
sdpMLineIndex : msg.label,
candidate : msg.candidate
});
pc.addIceCandidate(candidate);
} else if (msg.type === 'bye' && started) {
onRemoteHangup();
}
}
when the first user recieved message "type":"candidate",get wrong
当第一个用户收到消息“type”:“candidate”时,出错
and part of the console log:
和控制台日志的一部分:
- Creating PeerConnection
- Created webkitRTCPeerConnnection with config "{"iceServers":[{"url":"stun:stun.l.google.com:19302"}]}"
- Adding local stream
- Sending answer to peer
- recieved message : {"type":"candidate","label":0,"id":"audio","candidate":"a=candidate:1613033416 1 udp 2113937151 192.168.1.233 56946 typ host generation 0\r\n"}
- Uncaught SyntaxError: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': The ICE candidate could not be added
- recieved message : {"type":"candidat".......}
- Uncaught SyntaxError: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': The ICE candidate could not be added
- recieved message : {"type":"candidat".......}
- Uncaught SyntaxError: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': The ICE candidate could not be added
- 创建对等连接
- 使用配置 "{"iceServers":[{"url":"stun:stun.l.google.com:19302"}]}" 创建了 webkitRTCPeerConnnection
- 添加本地流
- 将答案发送给对等方
- 收到消息:{"type":"candidate","label":0,"id":"audio","candidate":"a=candidate:1613033416 1 udp 2113937151 192.168.1.233 56946 typ\host generation n"}
- 未捕获的语法错误:无法在“RTCPeerConnection”上执行“addIceCandidate”:无法添加 ICE 候选
- 收到消息:{"type":"candidat".......}
- 未捕获的语法错误:无法在“RTCPeerConnection”上执行“addIceCandidate”:无法添加 ICE 候选
- 收到消息:{"type":"candidat".......}
- 未捕获的语法错误:无法在“RTCPeerConnection”上执行“addIceCandidate”:无法添加 ICE 候选
回答by wontonsoup
I think you can create the ICE candidate message by using just the msg.candidate,
我认为您可以仅使用 msg.candidate 来创建 ICE 候选消息,
var candidate = new RTCIceCandidate(msg.candidate);
And pass that into the addIceCandidate
function
并将其传递给addIceCandidate
函数