WebRTC onicecandidate事件 [英] WebRTC onicecandidate event
问题描述
我对RTCPeerConnection的onicecandidate事件有以下回调:
I have the following callback for the onicecandidate event of RTCPeerConnection:
function iceCallback(event) {
if (event.candidate) {
var candidate = event.candidate;
socSend("candidate", candidate. event.target.id);
}
}
我能够从活动中读取候选人。候选人。但是当我尝试读取event.target.id时,我得到一个异常,无法读取未定义的属性目标。
I am able to read the candidate from the event.candidate. But when I try to read the event.target.id, I get an exception, cannot read property target of undefined.
id是我之前为RTCPeerConnection创建的属性。这适用于多用户视频聊天。
"id" is a property I previously created for the RTCPeerConnection. This is for a multiuser video chat.
我试图找出哪个RTCPeerConnection触发了onicecandidate事件,所以我知道我需要向哪个客户端发送icecandidate。我正在使用adapter.js库。
I am trying to figure out which RTCPeerConnection fired the onicecandidate event so I know to which client I need to send the icecandidate. I am using the adapter.js library.
推荐答案
我认为你的代码的某些部分就像下面一样,我只是添加了一个简单的修改:
I assumed that some part of your code would be like below, I have just added a simple modification:
peerConnections ={};
function createNewConncection(id){
var pc = new RTCPeerConnection();
pc.onaddstream = ...
...
//pc.onicecandidate = iceCallback; // OLD CODE
pc.onicecandidate = iceCallback.bind({pc:pc, id:id}); // NEW CODE
peerConnections[id] = pc;
}
function iceCallback(event) {
if (event.candidate) {
var candidate = event.candidate;
//socSend("candidate", candidate. event.target.id); // OLD CODE
socSend("candidate", this.id); // NEW CODE
}
}
这篇关于WebRTC onicecandidate事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!