WebRTC 无法添加 ICE 候选者

yan*_*Joe 5 javascript webrtc

我正在尝试在两个对等点之间建立 p2p 音频/视频连接。以下:WebRTC 入门

它在我家的 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();
        }
    }
Run Code Online (Sandbox Code Playgroud)

当第一个用户收到消息“type”:“candidate”时,出错

以及控制台日志的一部分:

  • 创建对等连接
  • 使用配置“{”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典型主机生成0 \ r \ n”}
  • 未捕获的语法错误:无法在“RTCPeerConnection”上执行“addIceCandidate”:无法添加 ICE 候选者
  • 收到消息:{"type":"candidat".......}
  • 未捕获的语法错误:无法在“RTCPeerConnection”上执行“addIceCandidate”:无法添加 ICE 候选者
  • 收到消息:{"type":"candidat".......}
  • 未捕获的语法错误:无法在“RTCPeerConnection”上执行“addIceCandidate”:无法添加 ICE 候选者

小智 0

我认为您可以仅使用 msg.candidate 创建 ICE 候选消息,

var candidate = new RTCIceCandidate(msg.candidate);
Run Code Online (Sandbox Code Playgroud)

并将其传递到addIceCandidate函数中

  • 我已经解决了这个问题。[在发送答案之前收到 ICE 候选人时出现错误](http://stackoverflow.com/questions/13396071/errors-when-ice-candidates-are-received-before-answer-is-sent ) 应设置 RemoteDescription(应在收到报价时完成)。在我的代码中,我等待设置remoteDescription并发送答案,直到浏览器获取本地流。 (10认同)
  • 你能添加答案吗? (2认同)