WebRTC ICE候选项无法添加

5

我正在尝试在两个对等端之间建立点对点音视频连接。请参考 入门WebRTC

在我的家庭局域网环境中,2台电脑之间可以正常工作,但在公司的局域网环境中运行时会出现错误消息,其中一部分是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();
        }
    }

当第一个用户收到消息 "type":"candidate" 时,出现错误

部分控制台日志:

  • 创建 PeerConnection
  • 使用配置创建 webkitRTCPeerConnnection "{"iceServers":[{"url":"stun:stun.l.google.com:19302"}]}"
  • 添加本地流
  • 向对等方发送答案
  • 接收到消息: {"type":"candidate","label":0,"id":"audio","candidate":"a=candidate:1613033416 1 udp 2113937151 192.168.1.233 56946 typ host generation 0\r\n"}
  • 未捕获的 SyntaxError: 在 'RTCPeerConnection' 上执行 'addIceCandidate' 失败:无法添加 ICE 候选项
  • 接收到消息: {"type":"candidate".......}
  • 未捕获的 SyntaxError: 在 'RTCPeerConnection' 上执行 'addIceCandidate' 失败:无法添加 ICE 候选项
  • 接收到消息: {"type":"candidate".......}
  • 未捕获的 SyntaxError: 在 'RTCPeerConnection' 上执行 'addIceCandidate' 失败:无法添加 ICE 候选项
1个回答

0

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

var candidate = new RTCIceCandidate(msg.candidate);

将其传递到addIceCandidate函数中。

10
我已解决了这个问题。在发送答案之前接收到 ICE 候选项会导致错误。应该设置 RemoteDescription(应在接收到offer时完成)。在我的代码中,我等待浏览器获取本地流后再设置remoteDescription和发送答案。 - yang Joe
2
你能加上答案吗? - johannesMatevosyan
@yangJoe 请记得在解决了自己的问题后写下答案,这样你就可以将其标记为该问题的解决方案。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接