本文介绍了WebRTC无法添加ICE候选人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to establish a p2p audio/video connection b/w two peers. Following: Getting started with WebRTC.

它可以在2台电脑之间的局域网环境中正常工作,但在我公司的局域网环境中运行
时会抛出错误信息,部分是javascript

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

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时:候选人,出错了

when the first user recieved message "type":"candidate",get wrong

和部分控制台日志:


  • 创建PeerConnection

  • 使用config{iceServers创建了webkitRTCPeerConnnection:[{url:stun:stun.l.google.com:19302}]}

  • 添加本地流

  • 向同行发送答案

  • 收到的消息:{type:candidate,label :0,id:audio,candidate:a =候选人:1613033416 1 udp 2113937151 192.168.1.233 56946 typ host generation 0 \\ n}

  • Uncaught SyntaxError:无法在'RTCPeerConnection'上执行'addIceCandidate':无法添加ICE候选人

  • 收到的消息:{type:candidat...... 。}

  • 未捕获的SyntaxError:无法在'RTCPeerConnection'上执行'addIceCandidate':无法添加ICE候选者

  • 收到的消息:{键入 : candidat .... ...}

  • 未捕获的SyntaxError:无法在'RTCPeerConnection'上执行'addIceCandidate':无法添加ICE候选项

  • 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

推荐答案

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

I think you can create the ICE candidate message by using just the msg.candidate,

var candidate = new RTCIceCandidate(msg.candidate);

并将其传递到 addIceCandidate 函数

这篇关于WebRTC无法添加ICE候选人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 03:53