WebRTC
The RTCDataChannelEvent interface
represents an event related to a specific RTCDataChannel.
Constructor
- RTCDataChannelEvent.RTCDataChannelEvent
- : Creates a new
RTCDataChannelEvent.
- : Creates a new
Instance properties
Also inherits properties from Event.
- RTCDataChannelEvent.channel
- : Returns the RTCDataChannel associated with the 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 RTCDataChannelEvent.channel property provides the RTCDataChannel representing the connection to the other peer.
pc.ondatachannel = (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
Browser compatibility
See also
- WebRTC
- RTCDataChannel
- A simple RTCDataChannel sample
- RTCPeerConnection (the target interface for RTCPeerConnection.datachannel_event events)
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
