Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

RTCDataChannel

BaselineWidely available *

TheRTCDataChannel interface represents a network channel which can be used for bidirectional peer-to-peer transfers of arbitrary data. Every data channel is associated with anRTCPeerConnection, and each peer connection can have up to a theoretical maximum of 65,534 data channels (the actual limit may vary from browser to browser).

To create a data channel and ask a remote peer to join you, call theRTCPeerConnection'screateDataChannel() method. The peer being invited to exchange data receives adatachannel event (which has typeRTCDataChannelEvent) to let it know the data channel has been added to the connection.

RTCDataChannel is atransferable object.

EventTarget RTCDataChannel

Instance properties

Also inherits properties fromEventTarget.

binaryType

A string specifying the type of objectthat should be used to represent binary data received on theRTCDataChannel.Values are the same as allowed on theWebSocket.binaryType property:blob ifBlob objects are being used,orarraybuffer ifArrayBuffer objects are being used.The default isarraybuffer.

bufferedAmountRead only

Returns the number of bytes of datacurrently queued to be sent over the data channel.

bufferedAmountLowThreshold

Specifies the number of bytes of buffered outgoing data that is considered "low".The default value is 0.

idRead only

Returns an ID number (between 0 and 65,534)which uniquely identifies theRTCDataChannel.

labelRead only

Returns a string that contains a name describing the data channel.These labels are not required to be unique.

maxPacketLifeTimeRead only

Returns the amount of time,in milliseconds,the browser is allowed to take to attempt to transmit a message,as set when the data channel was created,ornull.

maxRetransmitsRead only

Returns the maximum number of timesthe browser should try to retransmit a message before giving up,as set when the data channel was created,ornull, which indicates that there is no maximum.

negotiatedRead only

Indicateswhether theRTCDataChannel's connection was negotiated by the Web app(true)or by the WebRTC layer (false).The default isfalse.

orderedRead only

Indicates whether or not the data channel guarantees in-order delivery of messages;the default istrue, which indicates that the data channel is indeed ordered.

protocolRead only

Returns a string containing the name of the subprotocol in use.If no protocol was specifiedwhen the data channel was created,then this property's value is the empty string ("").

readyStateRead only

Returns a stringwhich indicates the state of the data channel's underlying data connection.It can have one of the following values:connecting,open,closing, orclosed.

Obsolete properties

Instance methods

Also inherits methods fromEventTarget.

close()

Closes theRTCDataChannel.Either peer is permitted to call this methodto initiate closure of the channel.

send()

Sends data across the data channel to the remote peer.

Events

bufferedamountlow

Sentwhen the number of bytes of data in the outgoing data bufferfalls below the value specified bybufferedAmountLowThreshold.

close

Sent when the underlying data transport closes.

closing

Sent when the underlying data transport is about to start closing.

error

Sent when an error occurs on the data channel.

message

Sent when a message has been received from the remote peer.The message contents can be foundin the event'sdata property.

open

Sent when the data channel is first opened,or when an existing data channel's underlying connection re-opens.

Data format

The underlying data format is defined by the IEEE specificationSDP Offer/Answer Procedures for SCTP over DTLS Transport(RFC 8841). The current format specifies its protocol as either"UDP/DTLS/SCTP" (UDP carrying DTLS carrying SCTP) or"TCP/DTLS/SCTP" (TCP carrying DTLS carrying SCTP). Older browsers may only specify"DTLS/SCTP".

Example

js
const pc = new RTCPeerConnection();const dc = pc.createDataChannel("my channel");dc.onmessage = (event) => {  console.log(`received: ${event.data}`);};dc.onopen = () => {  console.log("datachannel open");};dc.onclose = () => {  console.log("datachannel close");};

Specifications

Specification
WebRTC: Real-Time Communication in Browsers
# rtcdatachannel

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp