Class RTCDataChannel
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The RTCDataChannel interface represents a network channel which can be used for bidirectional peer-to-peer transfers of arbitrary data. Every data channel is associated with an RTCPeerConnection, 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).
[Value("RTCDataChannel")]
public class RTCDataChannel : EventTarget
- Inheritance
-
RTCDataChannel
- Inherited Members
Remarks
To create a data channel and ask a remote peer to join you, call the RTCPeerConnection's CreateDataChannel(string, RTCDataChannelInit) method. The peer being invited to exchange data receives a RTCPeerConnection.Datachannel event (which has type RTCDataChannelEvent) to let it know the data channel has been added to the connection.
RTCDataChannel is a transferable object.
Constructors
RTCDataChannel()
public RTCDataChannel()
Properties
BinaryType
The property binaryType on the
RTCDataChannel interface is a string which specifies
the type of object which should be used to represent binary data received
on the RTCDataChannel. Values allowed by the
BinaryType property are also permitted here:blob if Blob objects are being used orarraybuffer if ArrayBuffer objects are being used. The
default is arraybuffer.
[Value("binaryType")]
public BinaryType BinaryType { get; set; }
Property Value
- BinaryType
A string that can have one of these values:
Remarks
When a binary message is received on the data channel, the resulting
RTCDataChannel.Message event's Data property is an object of
the type specified by the binaryType.
-WebRTC
-Using WebRTC data channels
-RTCDataChannel
-Send(string)
BufferedAmount
The read-only RTCDataChannel propertybufferedAmount returns the number of bytes of data
currently queued to be sent over the data channel. The queue may build up as a
result of calls to the Send(string) method. This only
includes data buffered by the user agent itself; it doesn't include any framing overhead
or buffering done by the operating system or network hardware.
[Value("bufferedAmount")]
public ulong BufferedAmount { get; }
Property Value
- ulong
The number of bytes of data currently queued to be sent over the data channel but have
not yet been sent.
Remarks
The user agent may implement the process of actually sending data in any way it
chooses; this may be done periodically during the event loop or truly asynchronously. As
messages are actually sent, this value is reduced accordingly.
NOTE
Closing the data channel doesn't reset this count, even though the user agent purges
the queued messages. However, even after closing the channel, attempts to send
messages continue to add to thebufferedAmountvalue, even though the
messages are neither sent nor buffered.
Whenever this value decreases to fall to or below the value specified in the
BufferedAmountLowThreshold
property, the user agent fires the RTCDataChannel.Bufferedamountlow event. This event may
be used, for example, to implement code which queues more messages to be sent whenever
there's room to buffer them.
-WebRTC
-Using WebRTC data channels
-RTCDataChannel
-BufferedAmountLowThreshold
-RTCDataChannel.Bufferedamountlow event
BufferedAmountLowThreshold
The RTCDataChannel propertybufferedAmountLowThreshold is used to specify the number
of bytes of buffered outgoing data that is considered "low." The default value is
0. When the number of buffered outgoing bytes, as indicated by the
BufferedAmount property, falls to or
below this value, a RTCDataChannel.Bufferedamountlow event is fired. This event may be
used, for example, to implement code which queues more messages to be sent whenever
there's room to buffer them. Listeners may be added with
RTCDataChannel.Bufferedamountlow or
AddEventListener(string, Action?, Union26).
[Value("bufferedAmountLowThreshold")]
public ulong BufferedAmountLowThreshold { get; set; }
Property Value
- ulong
The number of queued outgoing data bytes below which the buffer is considered to be
"low."
Remarks
The user agent may implement the process of actually sending data in any way it
chooses; this may be done periodically during the event loop or truly asynchronously. As
messages are actually sent, this value is reduced accordingly.
NOTE
bufferedamountlowevents are not fired after the data channel is closed.
-WebRTC
-Using WebRTC data channels
-RTCDataChannel
-BufferedAmount
-RTCDataChannel.Bufferedamountlow event
Id
The read-only RTCDataChannel propertyid returns an ID number (between 0 and 65,534) which
uniquely identifies the RTCDataChannel. This ID is set at the
time the data channel is created, either by the user agent (if
Negotiated is false) or by the site or app
script (if negotiated is true).
[Value("id")]
public ushort? Id { get; }
Property Value
- ushort?
An
unsigned shortvalue (that is, an integer between 0 and 65,535) which
uniquely identifies the data channel.While the Label property doesn't have to be
unique, this ID number is guaranteed to be unique among all data channels. Additionally,
known implementations of WebRTC use the same ID on both peers. A unique ID makes it
easier for your code to do its own out-of-band data channel-related signaling.This can be also useful for logging and debugging purposes.
Remarks
Each RTCPeerConnection can therefore have up to a theoretical maximum of
65,534 data channels on it, although the actual maximum may vary from browser to
browser.
-WebRTC
-RTCDataChannel
-CreateDataChannel(string, RTCDataChannelInit)
Label
The read-only RTCDataChannel property label
returns a string containing a name describing the data channel. These
labels are not required to be unique.
[Value("label")]
public string Label { get; }
Property Value
- string
A string identifier assigned by the website or app when the data channel was created,
as specified when CreateDataChannel(string, RTCDataChannelInit) was called to
create the channel.
Remarks
You may use the label as you wish; you could use it to identify all the channels that
are being used for the same purpose, by giving them all the same name. Or you could give
each channel a unique label for tracking purposes. It's entirely up to the design
decisions made when building your site or app.
A unique ID can be found in the Id property.
NOTE
A data channel's label is set when the channel is created by calling
CreateDataChannel(string, RTCDataChannelInit). It cannot be changed after that.
-WebRTC
-RTCDataChannel
-Id
-CreateDataChannel(string, RTCDataChannelInit)
MaxPacketLifeTime
The read-only RTCDataChannel propertymaxPacketLifeTime 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, or null. This limits how long
the browser can continue to attempt to transmit and retransmit the message before giving
up.
[Value("maxPacketLifeTime")]
public ushort? MaxPacketLifeTime { get; }
Property Value
- ushort?
The number of milliseconds over which the browser may continue to attempt to transmit
the message until it either succeeds or gives up. If not set when
CreateDataChannel(string, RTCDataChannelInit) was called to create the data
channel, this value isnull.
Remarks
MaxRetransmits
The read-only RTCDataChannel propertymaxRetransmits returns the maximum number of times the
browser should try to retransmit a message before giving up, as set when the data
channel was created, or null, which indicates that there is no
maximum. This can only be set when the RTCDataChannel is created
by calling CreateDataChannel(string, RTCDataChannelInit), using themaxRetransmits field in the specified options.
[Value("maxRetransmits")]
public ushort? MaxRetransmits { get; }
Property Value
- ushort?
The maximum number of times the browser will try to retransmit a message before giving
up, ornullif not set when
CreateDataChannel(string, RTCDataChannelInit) was called. The default isnull.
Remarks
-WebRTC
-RTCDataChannel
-RTCDataChannel.MaxPacketLifetime
-CreateDataChannel(string, RTCDataChannelInit)
Negotiated
The read-only RTCDataChannel propertynegotiated indicates whether the
RTCDataChannel's connection was negotiated by the Web app
(true) or by the WebRTC layer (false). The
default is false.
[Value("negotiated")]
public bool Negotiated { get; }
Property Value
- bool
trueif the RTCDataChannel's connection was negotiated by
the Web app itself;falseif the negotiation was handled by the WebRTC
layer. The default isfalse.
Remarks
See Creating a data channel for further information about this property.
-WebRTC
-Using WebRTC data channels
-RTCDataChannel
-CreateDataChannel(string, RTCDataChannelInit)
Onbufferedamountlow
[Value("onbufferedamountlow")]
public EventHandlerNonNull Onbufferedamountlow { get; set; }
Property Value
Onclose
[Value("onclose")]
public EventHandlerNonNull Onclose { get; set; }
Property Value
Onclosing
[Value("onclosing")]
public EventHandlerNonNull Onclosing { get; set; }
Property Value
Onerror
[Value("onerror")]
public EventHandlerNonNull Onerror { get; set; }
Property Value
Onmessage
[Value("onmessage")]
public EventHandlerNonNull Onmessage { get; set; }
Property Value
Onopen
[Value("onopen")]
public EventHandlerNonNull Onopen { get; set; }
Property Value
Ordered
The read-only RTCDataChannel property ordered indicates
whether or not the data channel guarantees in-order delivery of messages;
the default is true,
which indicates that the data channel is indeed ordered.
This is set when the RTCDataChannel is created,
by setting the ordered property
on the object passed as CreateDataChannel(string, RTCDataChannelInit)'s options parameter.
[Value("ordered")]
public bool Ordered { get; }
Property Value
- bool
A boolean value which is
trueif in-order delivery is
guaranteed and is otherwisefalse.
Remarks
Priority
[Value("priority")]
public RTCPriorityType Priority { get; }
Property Value
Protocol
The read-only RTCDataChannel propertyprotocol returns a string containing the
name of the subprotocol in use. If no protocol was specified when the data channel was
created, then this property's value is the empty string ("").
[Value("protocol")]
public string Protocol { get; }
Property Value
- string
A string identifying the app-defined subprotocol being used for exchanging data on the
channel. If none has been established, this is an empty string ("").
Remarks
NOTE
The permitted values of this property are defined by the website or app using the
data channel.
The ability for each channel to have a defined subprotocol lets your app, for example,
use JSON objects as messages on one channel while another channel is plaintext and
another is raw binary or even some other format.
-WebRTC
-RTCDataChannel
-CreateDataChannel(string, RTCDataChannelInit)
ReadyState
The read-only RTCDataChannel property readyState returns a string which indicates the state of the data channel's underlying data connection.
[Value("readyState")]
public RTCDataChannelState ReadyState { get; }
Property Value
- RTCDataChannelState
A string indicating the current state of the underlying data transport, which is one of the following values:
Remarks
Methods
Close()
The RTCDataChannel.close() method closes the
RTCDataChannel. Either peer is permitted to call this method to initiate
closure of the channel.
[Value("close")]
public GlobalObject.Undefined Close()
Returns
Remarks
Closure of the data channel is not instantaneous. Most of the process of closing the
connection is handled asynchronously; you can detect when the channel has finished
closing by watching for a Close() event on the data channel.
The sequence of events which occurs in response to this method being called:
-WebRTC
-RTCDataChannel
-ReadyState
-Close() event
Send(Blob)
The send() method of the
RTCDataChannel interface sends data across the data channel to the
remote peer.
This can be done any time except during the initial process of
creating the underlying transport channel. Data sent before connecting is buffered if
possible (or an error occurs if it's not possible), and is also buffered if sent while
the connection is closing or closed.
[Value("send")]
public GlobalObject.Undefined Send(Blob data)
Parameters
dataBlob
Returns
Remarks
NOTE
Different browsers have different limitations on the size of the message you can
send. Specifications exist to define how to automatically fragment large messages, but
not all browsers implement them, and those that do have various additional
restrictions. This will get less complicated over time, but for now, if you have
questions, see Understanding message size limits.
-WebRTC
-RTCDataChannel
-ReadyState
-Close() event
Send(ArrayBuffer)
The send() method of the
RTCDataChannel interface sends data across the data channel to the
remote peer.
This can be done any time except during the initial process of
creating the underlying transport channel. Data sent before connecting is buffered if
possible (or an error occurs if it's not possible), and is also buffered if sent while
the connection is closing or closed.
[Value("send")]
public GlobalObject.Undefined Send(ArrayBuffer data)
Parameters
dataArrayBuffer
Returns
Remarks
NOTE
Different browsers have different limitations on the size of the message you can
send. Specifications exist to define how to automatically fragment large messages, but
not all browsers implement them, and those that do have various additional
restrictions. This will get less complicated over time, but for now, if you have
questions, see Understanding message size limits.
-WebRTC
-RTCDataChannel
-ReadyState
-Close() event
Send(Union223)
The send() method of the
RTCDataChannel interface sends data across the data channel to the
remote peer.
This can be done any time except during the initial process of
creating the underlying transport channel. Data sent before connecting is buffered if
possible (or an error occurs if it's not possible), and is also buffered if sent while
the connection is closing or closed.
[Value("send")]
public GlobalObject.Undefined Send(Union223 data)
Parameters
dataUnion223
Returns
Remarks
NOTE
Different browsers have different limitations on the size of the message you can
send. Specifications exist to define how to automatically fragment large messages, but
not all browsers implement them, and those that do have various additional
restrictions. This will get less complicated over time, but for now, if you have
questions, see Understanding message size limits.
-WebRTC
-RTCDataChannel
-ReadyState
-Close() event
Send(string)
The send() method of the
RTCDataChannel interface sends data across the data channel to the
remote peer.
This can be done any time except during the initial process of
creating the underlying transport channel. Data sent before connecting is buffered if
possible (or an error occurs if it's not possible), and is also buffered if sent while
the connection is closing or closed.
[Value("send")]
public GlobalObject.Undefined Send(string data)
Parameters
datastring
Returns
Remarks
NOTE
Different browsers have different limitations on the size of the message you can
send. Specifications exist to define how to automatically fragment large messages, but
not all browsers implement them, and those that do have various additional
restrictions. This will get less complicated over time, but for now, if you have
questions, see Understanding message size limits.
-WebRTC
-RTCDataChannel
-ReadyState
-Close() event