WebRTC - RTCDataChannel APIs



WebRTC is not only good at transferring audio and video streams, but any arbitrary data we might have. This is where the RTCDataChannel object comes into play.

RTCDataChannel API

Properties

  • RTCDataChannel.label (read only) − Returns a string containing the data channel name.

  • RTCDataChannel.ordered (read only) − Returns true if the order of delivery of the messages is guaranteed or false if it is not guaranteed.

  • RTCDataChannel.protocol (read only) − Returns a string containing subprotocol name used for this channel.

  • RTCDataChannel.id (read only) − Returns a unique id for the channel which is set at the creation of the RTCDataChannel object.

  • RTCDataChannel.readyState (read only) − Returns the RTCDataChannelState enum representing the state of the connection. The possible values −

    • connecting − Indicates that the connection is not yet active. This is the initial state.

    • open − Indicates that the connection is running.

    • closing − Indicates that the connection is in the process of shutting down. The cached messages are in the process of being sent or received, but no newly created task is accepting.

    • closed − Indicates that the connection could not be established or has been shut down.

  • RTCDataChannel.bufferedAmount (read only) − Returns the amount of bytes that have been queued for sending. This is the amount of data that has not been sent yet via RTCDataChannel.send().

  • RTCDataChannel.bufferedAmountLowThreshold − Returns the number of bytes at which the RTCDataChannel.bufferedAmount is taken up as low. When the RTCDataChannel.bufferedAmount decreases below this threshold, the bufferedamountlow event is fired.

  • RTCDataChannel.binaryType − Returns the type of the binary data transmitted by the connection. Can be “blob” or “arraybuffer”.

  • RTCDataChannel.maxPacketLifeType (read only) − Returns an unsigned short that indicates the length in milliseconds of the window in when messaging is going in unreliable mode.

  • RTCDataChannel.maxRetransmits (read only) − Returns an unsigned short that indicates the maximum number of times a channel will retransmit data if it is not delivered.

  • RTCDataChannel.negotiated (read only) − Returns a boolean that indicates if the channel has been negotiated by the user-agent, or by the application.

  • RTCDataChannel.reliable (read only) − Returns a boolean that indicates of the connection can send messages in unreliable mode.

  • RTCDataChannel.stream (read only) − Synonym for RTCDataChannel.id

Event Handlers

  • RTCDataChannel.onopen − This event handler is called when the open event is fired. This event is sent when the data connection has been established.

  • RTCDataChannel.onmessage − This event handler is called when the message event is fired. The event is sent when a message is available on the data channel.

  • RTCDataChannel.onbufferedamountlow − This event handler is called when the bufferedamoutlow event is fired. This event is sent when RTCDataChannel.bufferedAmount decreases below the RTCDataChannel.bufferedAmountLowThreshold property.

  • RTCDataChannel.onclose − This event handler is called when the close event is fired. This event is sent when the data connection has been closed.

  • RTCDataChannel.onerror − This event handler is called when the error event is fired. This event is sent when an error has been encountered.

Methods

  • RTCDataChannel.close() − Closes the data channel.

  • RTCDataChannel.send() − Sends the data in the parameter over the channel. The data can be a blob, a string, an ArrayBuffer or an ArrayBufferView.

Advertisements