Class PeerConnection
- All Implemented Interfaces:
Closeable,AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescription -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRemoteCandidate(String candidate) Adds a trickled remote candidate received from the remote peer by the user's method of choice.voidaddRemoteCandidate(String candidate, @Nullable String mediaId) Adds a trickled remote candidate received from the remote peer by the user's method of choice.voidclose()If it is not already closed, the Peer Connection is implicitly closed before being deleted.booleancloseAndAwait(Duration timeout) Force-close and await native transport teardown before deleting the peer.Starts native closure without blocking a worker on teardown.voidCloses all Data Channels.createDataChannel(String label) Adds a Data Channel on a Peer Connection.createDataChannel(String label, DataChannelInitSettings init) Adds a Data Channel on a Peer Connection.static PeerConnectionstatic PeerConnectioncreatePeer(PeerConnectionConfiguration config, Executor executor) Creates a Peer Connection.static PeerConnectioncreatePeer(PeerConnectionConfiguration config, Executor executor, @Nullable Path certificate, @Nullable Path key) Creates a peer using a paired PEM DTLS certificate/key, or the default identity if both null.static PeerConnectioncreatePeer(PeerConnectionConfiguration config, Executor executor, @Nullable Path certificate, @Nullable Path key, @Nullable String keyPassword) Imports an endpoint identity using the upstream native certificate configuration.static PeerConnectioncreatePeer(PeerConnectionConfiguration config, Executor executor, DtlsIdentity identity) voiddropTrackState(int trackHandle) booleaninthashCode()Retrieves the current local address, i.e.Retrieves the current local description in SDP format.Retrieves the current local description type as string.intRetrieves the maximum stream ID a Data Channel may use.static longDiagnostic count at native peer construction, including failed attempts.Retrieves the current remote address, i.e.Retrieves the current remote description in SDP format.@Nullable SessionDescriptionTypeRetrieves the current remote description type as string.intRetrieves the maximum message size for data channels on the peer connection as negotiated with the remote peer.rtt()Retrieves the round trip time of the underlying SCTP association.Retrieves the currently selected candidate pair.voidvoidsetLocalDescription(@Nullable String type) Initiates the handshake process.voidsetLocalDescription(@Nullable String type, String ufrag, String password) Installs the exact local ICE credentials before gathering starts.voidsetRemoteDescription(String sdp, @Nullable SessionDescriptionType type) Sets the remote description received from the remote peer by the user's method of choice.
-
Field Details
-
onLocalDescription
-
onLocalCandidate
-
onStateChange
-
onIceStateChange
-
onGatheringStateChange
public final EventListenerContainer<PeerConnectionCallback.GatheringStateChange> onGatheringStateChange -
onSignalingStateChange
public final EventListenerContainer<PeerConnectionCallback.SignalingStateChange> onSignalingStateChange -
onDataChannel
-
onTrack
-
-
Method Details
-
createPeer
Creates a Peer Connection. Remember toclose()when done.- Parameters:
config- the peer configurationexecutor- the executor to run callbacks on- Returns:
- the peer connection
-
createPeer
public static PeerConnection createPeer(PeerConnectionConfiguration config, Executor executor, DtlsIdentity identity) -
createPeer
public static PeerConnection createPeer(PeerConnectionConfiguration config, Executor executor, @Nullable Path certificate, @Nullable Path key) Creates a peer using a paired PEM DTLS certificate/key, or the default identity if both null. -
createPeer
public static PeerConnection createPeer(PeerConnectionConfiguration config, Executor executor, @Nullable Path certificate, @Nullable Path key, @Nullable String keyPassword) Imports an endpoint identity using the upstream native certificate configuration. -
nativeCreationAttempts
public static long nativeCreationAttempts()Diagnostic count at native peer construction, including failed attempts. -
createPeer
-
dropTrackState
public void dropTrackState(int trackHandle) -
close
public void close()If it is not already closed, the Peer Connection is implicitly closed before being deleted. After this function has been called, pc must not be used in a function call anymore. This function will block until all scheduled callbacks of pc return (except the one this function might be called in) and no other callback will be called for pc after it returns.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
closeAndAwait
Force-close and await native transport teardown before deleting the peer. Call only from an external owner thread, never a native callback. A timeout returns false and retains ownership so the caller can retry or fail closed. -
closeAsync
Starts native closure without blocking a worker on teardown. Safe from event callbacks. Completion follows transport destruction and Java handle cleanup. A peer still being initialized remains owned by its incoming-request handler. -
closeChannels
public void closeChannels()Closes all Data Channels. -
setLocalDescription
Installs the exact local ICE credentials before gathering starts. -
setLocalDescription
Initiates the handshake process.Following this call, the local description callback will be called with the local description, which must be sent to the remote peer by the user's method of choice.
Note this call is implicit after
setRemoteDescription(java.lang.String, tel.schich.libdatachannel.SessionDescriptionType)andcreateDataChannel(java.lang.String)if disableAutoNegotiation was not set on Peer Connection creation.- Parameters:
type- (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for autodetection.
-
localDescription
Retrieves the current local description in SDP format.- Returns:
- the current local description
-
localDescriptionType
Retrieves the current local description type as string. SeesetLocalDescription(java.lang.String, java.lang.String, java.lang.String).- Returns:
- the current local description type
-
setRemoteDescription
Sets the remote description received from the remote peer by the user's method of choice. The remote description may have candidates or not.If the remote description is an offer and disableAutoNegotiation was not set in rtcConfiguration, the library will automatically answer by calling rtcSetLocalDescription internally. Otherwise, the user must call it to answer the remote description.
- Parameters:
sdp- the remote Session Description Protocoltype- (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for autodetection.
-
remoteDescription
Retrieves the current remote description in SDP format.- Returns:
- the current remote description
-
remoteDescriptionType
Retrieves the current remote description type as string.- Returns:
- the current remote description type
-
addRemoteCandidate
Adds a trickled remote candidate received from the remote peer by the user's method of choice. The Peer Connection must have a remote description set.- Parameters:
candidate- a null-terminated SDP string representing the candidate (with or without the "a=" prefix)
-
addRemoteCandidate
Adds a trickled remote candidate received from the remote peer by the user's method of choice. The Peer Connection must have a remote description set.- Parameters:
candidate- a null-terminated SDP string representing the candidate (with or without the "a=" prefix)mediaId- (optional): a null-terminated string representing the mediaId of the candidate in the remote SDP description or NULL for autodetection
-
localAddress
Retrieves the current local address, i.e. the network address of the currently selected local candidate. The address will have the format "IP_ADDRESS:PORT", where IP_ADDRESS may be either IPv4 or IPv6. The call might fail if the PeerConnection is not in state RTC_CONNECTED, and the address might change after connection.- Returns:
- the local address
-
remoteAddress
Retrieves the current remote address, i.e. the network address of the currently selected remote candidate. The address will have the format "IP_ADDRESS:PORT", where IP_ADDRESS may be either IPv4 or IPv6. The call may fail if the state is not RTC_CONNECTED, and the address might change after connection.- Returns:
- the remote address
-
selectedCandidatePair
Retrieves the currently selected candidate pair. The call may fail if the state is not RTC_CONNECTED, and the selected candidate pair might change after connection.- Returns:
- the selected candidate pair
-
maxDataChannelStream
public int maxDataChannelStream()Retrieves the maximum stream ID a Data Channel may use. It is useful to create user-negotiated Data Channels with negotiated=true and manualStream=true. The maximum is negotiated during connection, therefore the final value after connection might be lower than before connection if the remote maximum is lower.- Returns:
- maximum stream ID
-
remoteMaxMessageSize
public int remoteMaxMessageSize()Retrieves the maximum message size for data channels on the peer connection as negotiated with the remote peer.- Returns:
- the maximum message size
-
rtt
Retrieves the round trip time of the underlying SCTP association.- Returns:
- the round trip time, empty until the association reports one
-
setAnswer
-
createDataChannel
Adds a Data Channel on a Peer Connection. The Peer Connection does not need to be connected, however, the Data Channel will be open only when the Peer Connection is connected.rtcDataChannel() is equivalent to rtcDataChannelEx() with settings set to ordered, reliable, non-negotiated, with automatic stream ID selection (all flags set to false), and protocol set to an empty string.
- Parameters:
label- a user-defined UTF-8 string representing the Data Channel name- Returns:
- the created data channel
-
createDataChannel
Adds a Data Channel on a Peer Connection. The Peer Connection does not need to be connected, however, the Data Channel will be open only when the Peer Connection is connected.- Parameters:
label- a user-defined UTF-8 string representing the Data Channel nameinit- a structure of initialization settings- Returns:
- the created data channel
-
addTrack
-
addTrack
-
equals
-
hashCode
public int hashCode()
-