candidate组装的中event是哪里来的
来源:12-10 【来点实战-增加媒体协商的逻辑】WebRTC客户端的实现-3

weixin_慕勒4383646
2023-01-06
李老师:
学生在按照12-10节的内容实现端对端视频传输过程中,一开始是用的label:e.candidate.sdpMlineIndex、id:id:e.candidate.sdpMid和candidate:e.candidate.candidate。但经调试发现label一直是null且程序无法展示远端视频。后来学生按照您的代码将e换成了event程序就能正常运行了。
学生的问题是为什么这里要用event?这个event是什么?我在程序正没有定义这个event,它是怎么来的?
学生认真阅读了您的著作,但还是未找到答案,麻烦李老师解惑!!!
pc.onicecandidate = (e)=>{
if(e.candidate){
console.log('find a new candidate',e.candidate);
sendMessage(roomid,{
type:'candidate',
//label:e.candidate.sdpMlineIndex,
//id:e.candidate.sdpMid,
//candidate:e.candidate.candidate
label:event.candidate.sdpMLineIndex,
id:event.candidate.sdpMid,
candidate: event.candidate.candidate
});
}
};
写回答
1回答
-
李超
2023-01-08
event是浏览器回调你的js 函数时传过来的,e之所以不行可能它是一个特殊的关键字,你可以试试其他变量来接收这个参数。我当时直接使用了event 没遇到错,我也没关注过使用其他参数名是否会报错
112023-01-08
相似问题