未捕获的TypeError:无法读取未定义的属性“addIceCandidate”

时间:2018-06-11 06:22:25

标签: javascript c# signalr webrtc

我会跳进代码部分,因为标题是我面临的问题,我找不到更好的方法来描述它

function addIceCandidate(message) {
    if (message.candidate != null) {
        console.trace('add ice candidate');
        var iceCandidate = new RTCIceCandidate(message.candidate);
        pc1.addIceCandidate(iceCandidate);
    }    
}

是试图将冰候选者发送到远程对等方但是在远程对等方的chrome调试器中的函数

  

未捕获的TypeError:无法读取未定义的属性“addIceCandidate”   和

pc1.addIceCandidate(iceCandidate);

是发生错误的行

但是我的知识addIceCandidate是一个已经定义的WebRTC函数。

所以我做错了什么?

我已经完成了here,针对类似问题herehere以及here

以及整个项目Gist是here

Ty提前帮助,如果您需要其他信息,请通知我

2 个答案:

答案 0 :(得分:0)

  

未捕获的TypeError:无法读取未定义的属性“addIceCandidate”

此行本身已回答您的问题。未定义api/some_endpoint/instance_id/对象,您尝试访问pc1属性。

工作代码:

addIceCandidate

答案 1 :(得分:0)

要记住的事情:

  1. 一旦连接pc1通过onicecandidate()事件处理程序接收到冰候选者,pc1应通过信令服务器将冰候选者发送给远程对等体。

  2. 远程对等方应使用RTCPeerConnectionaddIceCandidate()添加通过信令服务器收到的候选冰。

  3. 请参阅Simple Peer-to-Peer Example