RTCPeerConnection: sự kiện datachannel

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Sự kiện datachannel của giao diện RTCPeerConnection được gửi khi máy ngang hàng từ xa thêm một RTCDataChannel vào kết nối.

Cú pháp

js
addEventListener("datachannel", (event) => { })

ondatachannel = (event) => { }

Loại sự kiện

Một RTCDataChannelEvent.

Ví dụ

js
pc.ondatachannel = (event) => {
  const channel = event.channel;
  console.log(channel.label);
};

Thông số kỹ thuật

Specification
WebRTC: Real-Time Communication in Browsers
# dom-rtcpeerconnection-ondatachannel

Tương thích trình duyệt