Class DataChannel

java.lang.Object
tel.schich.libdatachannel.DataChannel
All Implemented Interfaces:
Closeable, AutoCloseable

public class DataChannel extends Object implements Closeable
An RTC data channel, created from a PeerConnection.
  • Field Details

  • Method Details

    • peer

      public PeerConnection peer()
      Returns the PeerConnection this channel belongs to
      Returns:
      the peer connection
    • sendMessage

      public void sendMessage(ByteBuffer data)
      Sends a binary message in the channel
      Parameters:
      data - the data
    • sendMessage

      public void sendMessage(String message)
      Sends a text message in the channel
      Parameters:
      message - the message
    • close

      public void close()
      Closes and deletes the channel

      This function will block until all scheduled callbacks of this channel return (except the one this function might be called in)

      No other callback will be called for the channel after it returns.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • isClosed

      public boolean isClosed()
      Returns whether the channel exists and is closed (not open and not connecting), false otherwise
      Returns:
      true if closed
    • isOpen

      public boolean isOpen()
      Returns whether the channel exists and is open, false otherwise
      Returns:
      true if open
    • maxMessageSize

      public int maxMessageSize()
      Returns the maximum message size for data channels on the peer connection as negotiated with the remote peer.
      Returns:
      the maximum message size
    • bufferedAmountLowThreshold

      public void bufferedAmountLowThreshold(int amount)
      Changes the buffered amount threshold under which DataChannelCallback.BufferedAmountLow is called.

      The callback is called when the buffered amount was strictly superior and gets equal to or lower than the threshold when a message is sent.

      The initial threshold is 0, meaning the callback is called each time the buffered amount goes back to zero after being non-zero.

      Parameters:
      amount - the amount
    • receiveMessage

      public Optional<ByteBuffer> receiveMessage()
      Returns a pending message if available.

      The may only be called if the onMessage callback is not set.

      Returns:
      the received message
    • receiveMessage

      public int receiveMessage(ByteBuffer buffer)
      Returns a pending message if available.

      This method may only be called if the onMessage callback is not set.

      Parameters:
      buffer - the buffer to receive the message into
      Returns:
      the bytes received or the negative size of the message if the buffer was too small
    • availableAmount

      public int availableAmount()
      Returns the available amount, i.e., the total size of messages pending reception with receiveMessage().

      This may only be called if the onMessage callback is not set.

      Returns:
      the available amount
    • bufferedAmount

      public int bufferedAmount()
      Returns the current buffered amount, i.e., the total size of currently buffered messages waiting to be actually sent in the channel.

      This does not account for the data buffered at the transport level.

      Returns:
      the buffered amount
    • streamId

      public int streamId()
      Returns the stream ID of this channel 0
      Returns:
      the stream id
    • label

      public String label()
      Returns the label of this channel
      Returns:
      the label
    • protocol

      public String protocol()
      Returns the protocol of this channel
      Returns:
      the protocol
    • reliability

      public DataChannelReliability reliability()
      Returns the configured DataChannelReliability of this channel
      Returns:
      the reliability
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object