Package tel.schich.libdatachannel
Class DataChannel
java.lang.Object
tel.schich.libdatachannel.DataChannel
- All Implemented Interfaces:
Closeable,AutoCloseable
An RTC data channel, created from a
PeerConnection.-
Field Summary
FieldsModifier and TypeFieldDescription -
Method Summary
Modifier and TypeMethodDescriptionintReturns the available amount, i.e., the total size of messages pending reception withreceiveMessage().intReturns the current buffered amount, i.e., the total size of currently buffered messages waiting to be actually sent in the channel.voidbufferedAmountLowThreshold(int amount) Changes the buffered amount threshold under whichDataChannelCallback.BufferedAmountLowis called.voidclose()Closes and deletes the channelbooleaninthashCode()booleanisClosed()Returns whether the channel exists and is closed (not open and not connecting), false otherwisebooleanisOpen()Returns whether the channel exists and is open, false otherwiselabel()Returns the label of this channelintReturns the maximum message size for data channels on the peer connection as negotiated with the remote peer.peer()Returns thePeerConnectionthis channel belongs toprotocol()Returns the protocol of this channelReturns a pending message if available.intreceiveMessage(ByteBuffer buffer) Returns a pending message if available.Returns the configuredDataChannelReliabilityof this channelvoidsendMessage(String message) Sends a text message in the channelvoidsendMessage(ByteBuffer data) Sends a binary message in the channelintstreamId()Returns the stream ID of this channel 0
-
Field Details
-
onOpen
-
onClosed
-
onError
-
onMessage
-
onBufferedAmountLow
-
onAvailable
-
-
Method Details
-
peer
Returns thePeerConnectionthis channel belongs to- Returns:
- the peer connection
-
sendMessage
Sends a binary message in the channel- Parameters:
data- the data
-
sendMessage
Sends a text message in the channel- Parameters:
message- the message
-
close
public void close()Closes and deletes the channelThis 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
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 whichDataChannelCallback.BufferedAmountLowis 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
Returns a pending message if available.The may only be called if the
onMessagecallback is not set.- Returns:
- the received message
-
receiveMessage
Returns a pending message if available.This method may only be called if the
onMessagecallback 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 withreceiveMessage().This may only be called if the
onMessagecallback 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
Returns the label of this channel- Returns:
- the label
-
protocol
Returns the protocol of this channel- Returns:
- the protocol
-
reliability
Returns the configuredDataChannelReliabilityof this channel- Returns:
- the reliability
-
equals
-
hashCode
public int hashCode()
-