RTCDataChannelEvent: thuộc tính channel

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.

Thuộc tính chỉ đọc RTCDataChannelEvent.channel trả về RTCDataChannel liên kết với sự kiện.

Giá trị

Một đối tượng RTCDataChannel đại diện cho kênh dữ liệu liên kết RTCPeerConnection nhận với peer từ xa của nó.

Ví dụ

Dòng đầu tiên của mã trong trình xử lý sự kiện datachannel hiển thị bên dưới lấy kênh từ đối tượng sự kiện và lưu nó cục bộ để sử dụng bởi mã xử lý lưu lượng dữ liệu.

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

Thông số kỹ thuật

Specification
WebRTC: Real-Time Communication in Browsers
# dom-datachannelevent-channel

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

Xem thêm