RTCDataChannelEvent - Web APIs 编辑

Experimental

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The RTCDataChannelEvent() constructor returns a new RTCDataChannelEvent object, which represents a datachannel event. These events sent to an RTCPeerConnection when its remote peer is asking to open an RTCDataChannel between the two peers.

You will rarely if ever construct an RTCDataChannelEvent by hand; instead, the WebRTC layer will generate and deliver them to you at the appropriate time. Just listen for the datachannel event to be received by the RTCPeerConnection and when you receive it, use the RTCDataChannelEvent.channel property to gain access to the data channel which has been opened.

Constructor

RTCDataChannelEvent() This is an experimental API that should not be used in production code.
The RTCDataChannelEvent() constructor creates a new RTCDataChannelEvent.

Properties

Also inherits properties from: Event

channel This is an experimental API that should not be used in production code. undefined
The read-only property RTCDataChannelEvent.channel returns the RTCDataChannel associated with the event.

Methods

This interface has no methods, but inherits methods from: Event

Examples

In this example, the datachannel event handler is set up to save the data channel reference and set up handlers for the events which need to be monitored. The channel property provides the RTCDataChannel representing the connection to the other peer.

pc.ondatachannel = function(event) {
  inboundDataChannel = event.channel;
  inboundDataChannel.onmessage = handleIncomingMessage;
  inboundDataChannel.onopen = handleChannelOpen;
  inboundDataChannel.onclose = handleChannelClose;
}

See A simple RTCDataChannel sample for another, more complete, example of how to use data channels.

Specifications

SpecificationStatusComment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCDataChannelEvent' in that specification.
Candidate RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:129 次

字数:5952

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文