RTCPeerConnection: icecandidate event
Experimental: 这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。
当 RTCPeerConnection
通过RTCPeerConnection.setLocalDescription()
(en-US)方法更改本地描述之后,该RTCPeerConnection
会抛出icecandidate
事件。该事件的监听器需要将更改后的描述信息传送给远端RTCPeerConnection
,以更新远端的备选源。
使用指南
icecandidate
的类型为 RTCPeerIceCandidateEvent
, 在以下三种情况下会触发该事件:
分享新的源
触发icecandidate
事件的首要原因:当获得新的源之后,需要将该源的信息发送给远端信号服务器,并分发至其他端的RTCPeerConnection
。其他RTCPeerConnection
通过addIceCandidate()
方法将新candidate
中携带的信息,将新的源描述信息添加进它的备选池中;
rtcPeerConnection.onicecandidate = (event) => { if (event.candidate) { sendCandidateToRemotePeer(event.candidate) } }
概述
- 规范
- WebRTC 1.0: Real-time Communication Between Browsers
icecandidate - 接口
RTCPeerConnectionIceEvent
(en-US)- 事件冒泡
- 否
- 能否取消默认
- 否
- 事件目标
RTCPeerConnection
- 默认行为
- 无
属性
方法
相关事件
- 无
规范
规范 | 状态 | 注释 |
---|---|---|
WebRTC 1.0: Real-time Communication Between Browsers icecandidate |
Candidate Recommendation |
兼容性
BCD tables only load in the browser