Module webrtc.java

Class RTCPeerConnection


  • public class RTCPeerConnection
    extends dev.onvoid.webrtc.internal.NativeObject
    The 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 Detail

      • getSenders

        public RTCRtpSender[] getSenders()
        Returns an array of RTCRtpSender objects representing the RTP senders that belong to non-stopped RTCRtpTransceiver objects currently attached to this RTCPeerConnection.
        Returns:
        An array of RTP senders.
      • getReceivers

        public RTCRtpReceiver[] getReceivers()
        Returns an array of RTCRtpReceiver objects representing the RTP receivers that belong to non-stopped RTCRtpTransceiver objects currently attached to this RTCPeerConnection.
        Returns:
        An array of RTP receivers.
      • getTransceivers

        public RTCRtpTransceiver[] getTransceivers()
        Returns an array of RTCRtpTransceiver objects 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.
      • 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. Like createOffer, 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 via addIceCandidate(dev.onvoid.webrtc.RTCIceCandidate) since the offer or answer was created. If the RTCPeerConnection is in the stable state, the value is null.
        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 to createOffer will create descriptions that will restart ICE.
      • close

        public void close()
        Closes the peer connection, terminates all media and releases any used resources.