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

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() 构造函数创建新 RTCDataChannelEvent .

特性

Also inherits properties from: 事件

channel 只读
The read-only property RTCDataChannelEvent .channel 返回 RTCDataChannel 与事件关联。

方法

This interface has no methods, but inherits methods from: 事件

范例

在此范例中, 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.

规范

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

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
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

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: