Class PeerConnection
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
Java version of PeerConnectionInterface.BundlePolicystatic enum
Java version of PeerConnectionInterface.CandidateNetworkPolicystatic enum
Java version of PeerConnectionInterface.ContinualGatheringPolicystatic enum
Tracks PeerConnectionInterface::IceConnectionStatestatic enum
Tracks PeerConnectionInterface::IceGatheringStatestatic class
Java version of PeerConnectionInterface.IceServer.static enum
Java version of PeerConnectionInterface.IceTransportsTypestatic enum
Java version of rtc::KeyTypestatic interface
Java version of PeerConnectionObserver.static enum
Tracks PeerConnectionInterface::PeerConnectionStatestatic enum
Java version of webrtc::PortPrunePolicystatic class
Java version of PeerConnectionInterface.RTCConfigurationstatic enum
Java version of PeerConnectionInterface.RtcpMuxPolicystatic enum
Java version of webrtc::SdpSemantics.static enum
Tracks PeerConnectionInterface::SignalingStatestatic enum
Java version of PeerConnectionInterface.TcpCandidatePolicystatic enum
Tracks PeerConnectionInterface::TlsCertPolicy -
Constructor Summary
ConstructorDescriptionWraps a PeerConnection created by the factory. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addIceCandidate
(IceCandidate candidate) void
addIceCandidate
(IceCandidate candidate, AddIceObserver observer) boolean
addStream
(MediaStream stream) Adds a new MediaStream to be sent on this peer connection.addTrack
(MediaStreamTrack track) Adds a new media stream track to be sent on this peer connection, and returns the newly created RtpSender.addTrack
(MediaStreamTrack track, List<String> streamIds) addTransceiver
(MediaStreamTrack track) Creates a new RtpTransceiver and adds it to the set of transceivers.addTransceiver
(MediaStreamTrack.MediaType mediaType) addTransceiver
(MediaStreamTrack.MediaType mediaType, RtpTransceiver.RtpTransceiverInit init) void
close()
void
createAnswer
(SdpObserver observer, MediaConstraints constraints) createDataChannel
(String label, DataChannel.Init init) static long
void
createOffer
(SdpObserver observer, MediaConstraints constraints) createSender
(String kind, String stream_id) Creates an RtpSender without a track.void
dispose()
Free native resources associated with this PeerConnection instance.long
Returns a pointer to the native webrtc::PeerConnectionInterface.Gets all RtpReceivers associated with this peer connection.Gets all RtpSenders associated with this peer connection.void
getStats
(RTCStatsCollectorCallback callback) Gets stats using the new stats collection API, see webrtc/api/stats/.boolean
getStats
(StatsObserver observer, MediaStreamTrack track) Deprecated.Gets all RtpTransceivers associated with this peer connection.boolean
removeIceCandidates
(IceCandidate[] candidates) void
removeStream
(MediaStream stream) Removes the given media stream from this peer connection.boolean
removeTrack
(RtpSender sender) Stops sending media from sender.void
Tells the PeerConnection that ICE should be restarted.void
setAudioPlayout
(boolean playout) Enables/disables playout of received audio streams.void
setAudioRecording
(boolean recording) Enables/disables recording of transmitted audio streams.boolean
setBitrate
(Integer min, Integer current, Integer max) Limits the bandwidth allocated for all RTP streams sent by this PeerConnection.boolean
void
setLocalDescription
(SdpObserver observer) void
setLocalDescription
(SdpObserver observer, SessionDescription sdp) void
setRemoteDescription
(SdpObserver observer, SessionDescription sdp) boolean
startRtcEventLog
(int file_descriptor, int max_size_bytes) Starts recording an RTC event log.void
Stops recording an RTC event log.
-
Constructor Details
-
PeerConnection
Wraps a PeerConnection created by the factory. Can be used by clients that want to implement their PeerConnection creation in JNI.
-
-
Method Details
-
getLocalDescription
-
getRemoteDescription
-
getCertificate
-
createDataChannel
-
createOffer
-
createAnswer
-
setLocalDescription
-
setLocalDescription
-
setRemoteDescription
-
restartIce
public void restartIce()Tells the PeerConnection that ICE should be restarted. -
setAudioPlayout
public void setAudioPlayout(boolean playout) Enables/disables playout of received audio streams. Enabled by default. Note that even if playout is enabled, streams will only be played out if the appropriate SDP is also applied. The main purpose of this API is to be able to control the exact time when audio playout starts. -
setAudioRecording
public void setAudioRecording(boolean recording) Enables/disables recording of transmitted audio streams. Enabled by default. Note that even if recording is enabled, streams will only be recorded if the appropriate SDP is also applied. The main purpose of this API is to be able to control the exact time when audio recording starts. -
setConfiguration
-
addIceCandidate
-
addIceCandidate
-
removeIceCandidates
-
addStream
Adds a new MediaStream to be sent on this peer connection. Note: This method is not supported with SdpSemantics.UNIFIED_PLAN. Please use addTrack instead. -
removeStream
Removes the given media stream from this peer connection. This method is not supported with SdpSemantics.UNIFIED_PLAN. Please use removeTrack instead. -
createSender
Creates an RtpSender without a track.This method allows an application to cause the PeerConnection to negotiate sending/receiving a specific media type, but without having a track to send yet.
When the application does want to begin sending a track, it can call RtpSender.setTrack, which doesn't require any additional SDP negotiation.
Example use:
audioSender = pc.createSender("audio", "stream1"); videoSender = pc.createSender("video", "stream1"); // Do normal SDP offer/answer, which will kick off ICE/DTLS and negotiate // media parameters.... // Later, when the endpoint is ready to actually begin sending: audioSender.setTrack(audioTrack, false); videoSender.setTrack(videoTrack, false);
Note: This corresponds most closely to "addTransceiver" in the official WebRTC API, in that it creates a sender without a track. It was implemented before addTransceiver because it provides useful functionality, and properly implementing transceivers would have required a great deal more work.
Note: This is only available with SdpSemantics.PLAN_B specified. Please use addTransceiver instead.
- Parameters:
kind
- Corresponds to MediaStreamTrack kinds (must be "audio" or "video").stream_id
- The ID of the MediaStream that this sender's track will be associated with when SDP is applied to the remote PeerConnection. If createSender is used to create an audio and video sender that should be synchronized, they should use the same stream ID.- Returns:
- A new RtpSender object if successful, or null otherwise.
-
getSenders
Gets all RtpSenders associated with this peer connection. Note that calling getSenders will dispose of the senders previously returned. -
getReceivers
Gets all RtpReceivers associated with this peer connection. Note that calling getReceivers will dispose of the receivers previously returned. -
getTransceivers
Gets all RtpTransceivers associated with this peer connection. Note that calling getTransceivers will dispose of the transceivers previously returned. Note: This is only available with SdpSemantics.UNIFIED_PLAN specified. -
addTrack
Adds a new media stream track to be sent on this peer connection, and returns the newly created RtpSender. If streamIds are specified, the RtpSender will be associated with the streams specified in the streamIds list.- Throws:
IllegalStateException
- if an error accors in C++ addTrack. An error can occur if: - A sender already exists for the track. - The peer connection is closed.
-
addTrack
-
removeTrack
Stops sending media from sender. The sender will still appear in getSenders. Future calls to createOffer will mark the m section for the corresponding transceiver as receive only or inactive, as defined in JSEP. Returns true on success. -
addTransceiver
Creates a new RtpTransceiver and adds it to the set of transceivers. Adding a transceiver will cause future calls to CreateOffer to add a media description for the corresponding transceiver.The initial value of `mid` in the returned transceiver is null. Setting a new session description may change it to a non-null value.
https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver
If a MediaStreamTrack is specified then a transceiver will be added with a sender set to transmit the given track. The kind of the transceiver (and sender/receiver) will be derived from the kind of the track.
If MediaType is specified then a transceiver will be added based upon that type. This can be either MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO.
Optionally, an RtpTransceiverInit structure can be specified to configure the transceiver from construction. If not specified, the transceiver will default to having a direction of kSendRecv and not be part of any streams.
Note: These methods are only available with SdpSemantics.UNIFIED_PLAN specified.
- Throws:
IllegalStateException
- if an error accors in C++ addTransceiver
-
addTransceiver
public RtpTransceiver addTransceiver(MediaStreamTrack track, @Nullable RtpTransceiver.RtpTransceiverInit init) -
addTransceiver
-
addTransceiver
public RtpTransceiver addTransceiver(MediaStreamTrack.MediaType mediaType, @Nullable RtpTransceiver.RtpTransceiverInit init) -
getStats
Deprecated. -
getStats
Gets stats using the new stats collection API, see webrtc/api/stats/. These will replace old stats collection API when the new API has matured enough. -
setBitrate
Limits the bandwidth allocated for all RTP streams sent by this PeerConnection. Pass null to leave a value unchanged. -
startRtcEventLog
public boolean startRtcEventLog(int file_descriptor, int max_size_bytes) Starts recording an RTC event log. Ownership of the file is transfered to the native code. If an RTC event log is already being recorded, it will be stopped and a new one will start using the provided file. Logging will continue until the stopRtcEventLog function is called. The max_size_bytes argument is ignored, it is added for future use. -
stopRtcEventLog
public void stopRtcEventLog()Stops recording an RTC event log. If no RTC event log is currently being recorded, this call will have no effect. -
signalingState
-
iceConnectionState
-
connectionState
-
iceGatheringState
-
close
public void close() -
dispose
public void dispose()Free native resources associated with this PeerConnection instance. This method removes a reference count from the C++ PeerConnection object, which should result in it being destroyed. It also calls equivalent "dispose" methods on the Java objects attached to this PeerConnection (streams, senders, receivers), such that their associated C++ objects will also be destroyed.Note that this method cannot be safely called from an observer callback (PeerConnection.Observer, DataChannel.Observer, etc.). If you want to, for example, destroy the PeerConnection after an "ICE failed" callback, you must do this asynchronously (in other words, unwind the stack first). See bug 3721 for more details.
-
getNativePeerConnection
public long getNativePeerConnection()Returns a pointer to the native webrtc::PeerConnectionInterface. -
createNativePeerConnectionObserver
-