RTCDataChannelEvent

这是 实验性技术
检查 浏览器兼容性表格 在生产中使用这之前。

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.

构造函数

RTCDataChannelEvent()
RTCDataChannelEvent() constructor creates a new RTCDataChannelEvent .

特性

Also inherits properties from: Event

channel 只读
The read-only property RTCDataChannelEvent .channel returns the RTCDataChannel associated with the event.

方法

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

范例

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;
}
					

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

规范

规范 状态 Comment
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCDataChannelEvent' in that specification.
候选推荐 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
RTCDataChannelEvent Chrome Yes Edge ≤79 Firefox 22 IE No Opera Yes Safari Yes WebView Android Yes Chrome Android 28 Firefox Android 22 Opera Android Yes Safari iOS Yes Samsung Internet Android 1.5
RTCDataChannelEvent() 构造函数 Chrome 57 Edge ≤79 Firefox 22 IE No Opera 44 Safari ? WebView Android 57 Chrome Android 57 Firefox Android 22 Opera Android 43 Safari iOS ? Samsung Internet Android 7.0
channel Chrome Yes Edge ≤79 Firefox 22 IE No Opera Yes Safari Yes WebView Android Yes Chrome Android 28 Firefox Android 22 Opera Android Yes Safari iOS Yes Samsung Internet Android 1.5

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知

另请参阅