- java.lang.Object
-
- dev.onvoid.webrtc.internal.NativeObject
-
- dev.onvoid.webrtc.RTCPeerConnection
-
public class RTCPeerConnection extends dev.onvoid.webrtc.internal.NativeObjectThe RTCPeerConnection represents a WebRTC connection between the local computer and a remote peer. Communications are coordinated by the exchange of control messages (called a signaling protocol) over a signaling channel.- Author:
- Alex Andres
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddIceCandidate(RTCIceCandidate candidate)Adds a remote ICE candidate to the ICE Agent.RTCRtpSenderaddTrack(MediaStreamTrack track, List<String> streamIds)Adds a new track to the RTCPeerConnection, and indicates that it is contained in the specified MediaStreams.RTCRtpTransceiveraddTransceiver(MediaStreamTrack track, RTCRtpTransceiverInit init)Create a new RTCRtpTransceiver and add it to the set of transceivers.voidclose()Closes the peer connection, terminates all media and releases any used resources.voidcreateAnswer(RTCAnswerOptions options, CreateSessionDescriptionObserver observer)Generates an SDP answer to an offer received from a remote peer with the supported configuration for the session that is compatible with the parameters in the remote configuration.RTCDataChannelcreateDataChannel(String label, RTCDataChannelInit dict)Creates a new RTCDataChannel object with the given label.voidcreateOffer(RTCOfferOptions options, CreateSessionDescriptionObserver observer)Initiates the creation of an SDP that contains an RFC 3264 offer with the supported configurations for the session, including descriptions of the local MediaStreamTracks attached to this RTCPeerConnection, the codec/RTP/RTCP capabilities supported by this implementation, and parameters of the ICE agent and the DTLS connection.RTCConfigurationgetConfiguration()Returns an RTCConfiguration object representing the current configuration of this RTCPeerConnection.RTCPeerConnectionStategetConnectionState()Returns the connection state of the RTCPeerConnection.RTCSessionDescriptiongetCurrentLocalDescription()Returns the local description that was successfully negotiated the last time the RTCPeerConnection transitioned into the stable state plus any local candidates that have been generated by the ICE Agent since the offer or answer was created.RTCSessionDescriptiongetCurrentRemoteDescription()Returns the last remote description that was successfully negotiated the last time the RTCPeerConnection transitioned into the stable state plus any remote candidates that have been supplied via addIceCandidate() since the offer or answer was created.RTCIceConnectionStategetIceConnectionState()Returns the ICE connection state of the RTCPeerConnection.RTCIceGatheringStategetIceGatheringState()Returns the ICE gathering state of the RTCPeerConnection.RTCSessionDescriptiongetLocalDescription()Returns a pending local description if it is not null, otherwise it returns the current local description.RTCSessionDescriptiongetPendingLocalDescription()Returns a local description that is in the process of being negotiated plus any local candidates that have been generated by the ICE Agent since the offer or answer was created.RTCSessionDescriptiongetPendingRemoteDescription()Returns a remote description that is in the process of being negotiated, complete with any remote candidates that have been supplied viaaddIceCandidate(dev.onvoid.webrtc.RTCIceCandidate)since the offer or answer was created.RTCRtpReceiver[]getReceivers()Returns an array ofRTCRtpReceiverobjects representing the RTP receivers that belong to non-stoppedRTCRtpTransceiverobjects currently attached to this RTCPeerConnection.RTCSessionDescriptiongetRemoteDescription()Returns a pending remote description if it is not null, otherwise it returns the current remote description.RTCRtpSender[]getSenders()Returns an array ofRTCRtpSenderobjects representing the RTP senders that belong to non-stoppedRTCRtpTransceiverobjects currently attached to this RTCPeerConnection.RTCSignalingStategetSignalingState()Returns the signaling state of the RTCPeerConnection.voidgetStats(RTCRtpReceiver receiver, RTCStatsCollectorCallback callback)Gathers the current statistics of the specified RTCRtpReceiver.voidgetStats(RTCRtpSender sender, RTCStatsCollectorCallback callback)Gathers the current statistics of the specified RTCRtpSender.voidgetStats(RTCStatsCollectorCallback callback)Gathers the current statistics of this RTCPeerConnection.RTCRtpTransceiver[]getTransceivers()Returns an array ofRTCRtpTransceiverobjects representing the RTP transceivers that are currently attached to this RTCPeerConnection.voidremoveIceCandidates(RTCIceCandidate[] candidates)Removes a group of remote ICE candidates from the ICE agent.voidremoveTrack(RTCRtpSender sender)Stops sending media from sender.voidrestartIce()Tells the RTCPeerConnection that ICE should be restarted.voidsetConfiguration(RTCConfiguration configuration)Updates the configuration of this RTCPeerConnection.voidsetLocalDescription(RTCSessionDescription description, SetSessionDescriptionObserver observer)Instructs the RTCPeerConnection to apply the supplied RTCSessionDescription as the local description.voidsetRemoteDescription(RTCSessionDescription description, SetSessionDescriptionObserver observer)Instructs the RTCPeerConnection to apply the supplied RTCSessionDescription as the remote offer or answer.
-
-
-
Method Detail
-
getSenders
public RTCRtpSender[] getSenders()
Returns an array ofRTCRtpSenderobjects representing the RTP senders that belong to non-stoppedRTCRtpTransceiverobjects currently attached to this RTCPeerConnection.- Returns:
- An array of RTP senders.
-
getReceivers
public RTCRtpReceiver[] getReceivers()
Returns an array ofRTCRtpReceiverobjects representing the RTP receivers that belong to non-stoppedRTCRtpTransceiverobjects currently attached to this RTCPeerConnection.- Returns:
- An array of RTP receivers.
-
getTransceivers
public RTCRtpTransceiver[] getTransceivers()
Returns an array ofRTCRtpTransceiverobjects representing the RTP transceivers that are currently attached to this RTCPeerConnection.- Returns:
- An array of RTP transceivers.
-
addTrack
public RTCRtpSender addTrack(MediaStreamTrack track, List<String> streamIds)
Adds a new track to the RTCPeerConnection, and indicates that it is contained in the specified MediaStreams.- Parameters:
track- A MediaStreamTrack representing the media track to transmit.streamIds- A list of MediaStream ids to which the track belongs to.- Returns:
- The RTCRtpSender which will be used to transmit the media data.
-
removeTrack
public void removeTrack(RTCRtpSender sender)
Stops sending media from sender. The RTCRtpSender will still appear ingetSenders(). Doing so will cause future calls tocreateOffer(dev.onvoid.webrtc.RTCOfferOptions, dev.onvoid.webrtc.CreateSessionDescriptionObserver)to mark the media description for the corresponding transceiver asRTCRtpTransceiverDirection.RECV_ONLYorRTCRtpTransceiverDirection.INACTIVE.- Parameters:
sender- The RTCRtpSender to remove from the connection.
-
addTransceiver
public RTCRtpTransceiver addTransceiver(MediaStreamTrack track, RTCRtpTransceiverInit init)
Create a new RTCRtpTransceiver and add it to the set of transceivers. Adding a transceiver will cause future calls tocreateOffer(dev.onvoid.webrtc.RTCOfferOptions, dev.onvoid.webrtc.CreateSessionDescriptionObserver)to add a media description for the corresponding transceiver.- Parameters:
track- A MediaStreamTrack representing the media track to transmit.init- The transceiver configuration options.- Returns:
- The RTCRtpTransceiver which will be used to transmit and receive the media data.
-
createDataChannel
public RTCDataChannel createDataChannel(String label, RTCDataChannelInit dict)
Creates a new RTCDataChannel object with the given label. The RTCDataChannelInit dictionary can be used to configure properties of the underlying channel such as data reliability.- Parameters:
label- A human-readable name for the channel.dict- An RTCDataChannelInit providing configuration options for the data channel.- Returns:
- A new RTCDataChannel object.
-
createOffer
public void createOffer(RTCOfferOptions options, CreateSessionDescriptionObserver observer)
Initiates the creation of an SDP that contains an RFC 3264 offer with the supported configurations for the session, including descriptions of the local MediaStreamTracks attached to this RTCPeerConnection, the codec/RTP/RTCP capabilities supported by this implementation, and parameters of the ICE agent and the DTLS connection.- Parameters:
options- The options to provide additional control over the offer.observer- The observer to obtain the created RTCSessionDescription.
-
createAnswer
public void createAnswer(RTCAnswerOptions options, CreateSessionDescriptionObserver observer)
Generates an SDP answer to an offer received from a remote peer with the supported configuration for the session that is compatible with the parameters in the remote configuration. LikecreateOffer, the returned SDP contains descriptions of the local MediaStreamTracks attached to this RTCPeerConnection, the codec/RTP/RTCP options negotiated for this session, and any candidates that have been gathered by the ICE Agent.- Parameters:
options- The options to provide additional control over the answer.observer- The observer to obtain the created RTCSessionDescription.
-
getCurrentLocalDescription
public RTCSessionDescription getCurrentLocalDescription()
Returns the local description that was successfully negotiated the last time the RTCPeerConnection transitioned into the stable state plus any local candidates that have been generated by the ICE Agent since the offer or answer was created.- Returns:
- The last successfully negotiated local description.
-
getLocalDescription
public RTCSessionDescription getLocalDescription()
Returns a pending local description if it is not null, otherwise it returns the current local description.- Returns:
- The currently pending local description.
-
getPendingLocalDescription
public RTCSessionDescription getPendingLocalDescription()
Returns a local description that is in the process of being negotiated plus any local candidates that have been generated by the ICE Agent since the offer or answer was created. If the RTCPeerConnection is in the stable state, the value is null.- Returns:
- The local description that is in the process of being negotiated.
-
getCurrentRemoteDescription
public RTCSessionDescription getCurrentRemoteDescription()
Returns the last remote description that was successfully negotiated the last time the RTCPeerConnection transitioned into the stable state plus any remote candidates that have been supplied via addIceCandidate() since the offer or answer was created.- Returns:
- The last successfully negotiated remote description.
-
getRemoteDescription
public RTCSessionDescription getRemoteDescription()
Returns a pending remote description if it is not null, otherwise it returns the current remote description.- Returns:
- The currently pending remote description.
-
getPendingRemoteDescription
public RTCSessionDescription getPendingRemoteDescription()
Returns a remote description that is in the process of being negotiated, complete with any remote candidates that have been supplied viaaddIceCandidate(dev.onvoid.webrtc.RTCIceCandidate)since the offer or answer was created. If the RTCPeerConnection is in the stable state, the value isnull.- Returns:
- The remote description that is in the process of being negotiated.
-
setLocalDescription
public void setLocalDescription(RTCSessionDescription description, SetSessionDescriptionObserver observer)
Instructs the RTCPeerConnection to apply the supplied RTCSessionDescription as the local description.- Parameters:
description- An description which specifies the configuration to be applied to the local end of the connection.observer- The observer to be notified once the description has been successfully set.
-
setRemoteDescription
public void setRemoteDescription(RTCSessionDescription description, SetSessionDescriptionObserver observer)
Instructs the RTCPeerConnection to apply the supplied RTCSessionDescription as the remote offer or answer. Setting the remote description changes the local media state.- Parameters:
description- An description which specifies the remote peer's current offer or answer.observer- The observer to be notified once the description has been successfully set.
-
addIceCandidate
public void addIceCandidate(RTCIceCandidate candidate)
Adds a remote ICE candidate to the ICE Agent.- Parameters:
candidate- A new ICE candidate received from the remote peer over a signaling channel.
-
removeIceCandidates
public void removeIceCandidates(RTCIceCandidate[] candidates)
Removes a group of remote ICE candidates from the ICE agent.- Parameters:
candidates- The ICE candidates to remove.
-
getSignalingState
public RTCSignalingState getSignalingState()
Returns the signaling state of the RTCPeerConnection.- Returns:
- The current signaling state.
-
getIceGatheringState
public RTCIceGatheringState getIceGatheringState()
Returns the ICE gathering state of the RTCPeerConnection.- Returns:
- The current ICE gathering state.
-
getIceConnectionState
public RTCIceConnectionState getIceConnectionState()
Returns the ICE connection state of the RTCPeerConnection.- Returns:
- The current ICE connection state.
-
getConnectionState
public RTCPeerConnectionState getConnectionState()
Returns the connection state of the RTCPeerConnection.- Returns:
- The current connection state.
-
getConfiguration
public RTCConfiguration getConfiguration()
Returns an RTCConfiguration object representing the current configuration of this RTCPeerConnection.- Returns:
- The configuration that indicates the current configuration of this RTCPeerConnection.
-
setConfiguration
public void setConfiguration(RTCConfiguration configuration)
Updates the configuration of this RTCPeerConnection. This includes changing the configuration of the ICE Agent. When the ICE configuration changes in a way that requires a new gathering phase, an ICE restart is required.- Parameters:
configuration- The new configuration.
-
getStats
public void getStats(RTCStatsCollectorCallback callback)
Gathers the current statistics of this RTCPeerConnection.- Parameters:
callback- The callback to receive the generated stats.
-
getStats
public void getStats(RTCRtpReceiver receiver, RTCStatsCollectorCallback callback)
Gathers the current statistics of the specified RTCRtpReceiver.- Parameters:
receiver- The RTCRtpReceiver of which to gather the stats.callback- The callback to receive the generated stats.
-
getStats
public void getStats(RTCRtpSender sender, RTCStatsCollectorCallback callback)
Gathers the current statistics of the specified RTCRtpSender.- Parameters:
sender- The RTCRtpSender of which to gather the stats.callback- The callback to receive the generated stats.
-
restartIce
public void restartIce()
Tells the RTCPeerConnection that ICE should be restarted. Subsequent calls tocreateOfferwill create descriptions that will restart ICE.
-
close
public void close()
Closes the peer connection, terminates all media and releases any used resources.
-
-