WebRTC无法添加ICE候选人

时间:2014-08-18 03:24:46

标签: javascript webrtc

我正在尝试与两个对等方建立p2p音频/视频连接。以下:Getting started with WebRTC

在两台PC之间的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();
        }
    }

当第一个用户收到消息"键入":"候选人",出错

和控制台日志的一部分:

  • 创建PeerConnection
  • 创建了webkitRTCPeerConnnection with config" {" iceServers":[{" url":" stun:stun.l.google.com:19302" }]}"
  • 添加本地流
  • 向同行发送答案
  • 收到的消息:{"输入":"候选人","标签":0," id":"音频& #34;,"候选人":" a =候选人:1613033416 1 udp 2113937151 192.168.1.233 56946 typ host generation 0 \ r \ n"}
  • 未捕获的SyntaxError:无法执行' addIceCandidate' on' RTCPeerConnection':无法添加ICE候选人
  • 收到的消息:{" type":" candidat" .......}
  • 未捕获的SyntaxError:无法执行' addIceCandidate' on' RTCPeerConnection':无法添加ICE候选人
  • 收到的消息:{" type":" candidat" .......}
  • 未捕获的SyntaxError:无法执行' addIceCandidate' on' RTCPeerConnection':无法添加ICE候选人

1 个答案:

答案 0 :(得分:0)

我认为您可以使用msg.candidate

创建ICE候选消息
var candidate = new RTCIceCandidate(msg.candidate);

并将其传递到addIceCandidate函数