RTCPeerConnection.ondatachannel - Web APIs 编辑
Experimental
This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The RTCPeerConnection.ondatachannel
property is an EventHandler
which specifies a function which is called when the datachannel
event occurs on an RTCPeerConnection
. This event, of type RTCDataChannelEvent
, is sent when an RTCDataChannel
is added to the connection by the remote peer calling createDataChannel()
.
At the time this event is received, the RTCDataChannel
it indicates may not yet actually be open. Be sure to wait for the "open"
event to be fired on the new RTCDataChannel
before using it.
Syntax
RTCPeerConnection.ondatachannel = function;
Value
Set this property to be a function you provide which receives as input a single parameter: an RTCDataChannelEvent
which provides in its channel
property the RTCDataChannel
which has been created.
Example
pc.ondatachannel = function(ev) {
console.log('Data channel is created!');
ev.channel.onopen = function() {
console.log('Data channel is open and ready to be used.');
};
};
Specifications
Specification | Status | Comment |
---|---|---|
WebRTC 1.0: Real-time Communication Between Browsers The definition of 'RTCPeerConnection.ondatachannel' in that specification. | Candidate Recommendation | Initial specification. |
Browser compatibility
BCD tables only load in the browser
See also
- The
datachannel
event and its type,RTCDataChannelEvent
. RTCPeerConnection.createDataChannel()
- A simple RTCDataChannel sample
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论