Class PeerConnection
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enumJava version of PeerConnectionInterface.BundlePolicystatic enumJava version of PeerConnectionInterface.CandidateNetworkPolicystatic enumJava version of PeerConnectionInterface.ContinualGatheringPolicystatic enumTracks PeerConnectionInterface::IceConnectionStatestatic enumTracks PeerConnectionInterface::IceGatheringStatestatic classJava version of PeerConnectionInterface.IceServer.static enumJava version of PeerConnectionInterface.IceTransportsTypestatic enumJava version of rtc::KeyTypestatic interfaceJava version of PeerConnectionObserver.static enumTracks PeerConnectionInterface::PeerConnectionStatestatic enumJava version of webrtc::PortPrunePolicystatic classJava version of PeerConnectionInterface.RTCConfigurationstatic enumJava version of PeerConnectionInterface.RtcpMuxPolicystatic enumJava version of webrtc::SdpSemantics.static enumTracks PeerConnectionInterface::SignalingStatestatic enumJava version of PeerConnectionInterface.TcpCandidatePolicystatic enumTracks PeerConnectionInterface::TlsCertPolicy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<MediaStream>private final longprivate List<RtpReceiver>private List<RtpTransceiver> -
Constructor Summary
ConstructorsConstructorDescriptionPeerConnection(long nativePeerConnection) Wraps a PeerConnection created by the factory. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddIceCandidate(IceCandidate candidate) voidaddIceCandidate(IceCandidate candidate, AddIceObserver observer) booleanaddStream(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) voidclose()voidcreateAnswer(SdpObserver observer, MediaConstraints constraints) createDataChannel(String label, DataChannel.Init init) static longvoidcreateOffer(SdpObserver observer, MediaConstraints constraints) createSender(String kind, String stream_id) Creates an RtpSender without a track.voiddispose()Free native resources associated with this PeerConnection instance.(package private) longlongReturns a pointer to the native webrtc::PeerConnectionInterface.Gets all RtpReceivers associated with this peer connection.Gets all RtpSenders associated with this peer connection.voidgetStats(RTCStatsCollectorCallback callback) Gets stats using the new stats collection API, see webrtc/api/stats/.booleangetStats(StatsObserver observer, MediaStreamTrack track) Deprecated.Gets all RtpTransceivers associated with this peer connection.private booleannativeAddIceCandidate(String sdpMid, int sdpMLineIndex, String iceCandidateSdp) private voidnativeAddIceCandidateWithObserver(String sdpMid, int sdpMLineIndex, String iceCandidateSdp, AddIceObserver observer) private booleannativeAddLocalStream(long stream) private RtpSendernativeAddTrack(long track, List<String> streamIds) private RtpTransceivernativeAddTransceiverOfType(MediaStreamTrack.MediaType mediaType, RtpTransceiver.RtpTransceiverInit init) private RtpTransceivernativeAddTransceiverWithTrack(long track, RtpTransceiver.RtpTransceiverInit init) private voidprivate voidnativeCreateAnswer(SdpObserver observer, MediaConstraints constraints) private DataChannelnativeCreateDataChannel(String label, DataChannel.Init init) private voidnativeCreateOffer(SdpObserver observer, MediaConstraints constraints) private static longprivate RtpSendernativeCreateSender(String kind, String stream_id) private static voidnativeFreeOwnedPeerConnection(long ownedPeerConnection) private RtcCertificatePemprivate SessionDescriptionprivate longprivate List<RtpReceiver>private SessionDescriptionprivate List<RtpTransceiver>private PeerConnection.IceGatheringStateprivate voidnativeNewGetStats(RTCStatsCollectorCallback callback) private booleannativeOldGetStats(StatsObserver observer, long nativeTrack) private booleannativeRemoveIceCandidates(IceCandidate[] candidates) private voidnativeRemoveLocalStream(long stream) private booleannativeRemoveTrack(long sender) private voidprivate voidnativeSetAudioPlayout(boolean playout) private voidnativeSetAudioRecording(boolean recording) private booleannativeSetBitrate(Integer min, Integer current, Integer max) private booleanprivate voidnativeSetLocalDescription(SdpObserver observer, SessionDescription sdp) private voidprivate voidnativeSetRemoteDescription(SdpObserver observer, SessionDescription sdp) private PeerConnection.SignalingStateprivate booleannativeStartRtcEventLog(int file_descriptor, int max_size_bytes) private voidbooleanremoveIceCandidates(IceCandidate[] candidates) voidremoveStream(MediaStream stream) Removes the given media stream from this peer connection.booleanremoveTrack(RtpSender sender) Stops sending media from sender.voidTells the PeerConnection that ICE should be restarted.voidsetAudioPlayout(boolean playout) Enables/disables playout of received audio streams.voidsetAudioRecording(boolean recording) Enables/disables recording of transmitted audio streams.booleansetBitrate(Integer min, Integer current, Integer max) Limits the bandwidth allocated for all RTP streams sent by this PeerConnection.booleanvoidsetLocalDescription(SdpObserver observer) voidsetLocalDescription(SdpObserver observer, SessionDescription sdp) voidsetRemoteDescription(SdpObserver observer, SessionDescription sdp) booleanstartRtcEventLog(int file_descriptor, int max_size_bytes) Starts recording an RTC event log.voidStops recording an RTC event log.
-
Field Details
-
localStreams
-
nativePeerConnection
private final long nativePeerConnection -
senders
-
receivers
-
transceivers
-
-
Constructor Details
-
PeerConnection
Wraps a PeerConnection created by the factory. Can be used by clients that want to implement their PeerConnection creation in JNI. -
PeerConnection
PeerConnection(long nativePeerConnection)
-
-
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. -
getNativeOwnedPeerConnection
long getNativeOwnedPeerConnection() -
createNativePeerConnectionObserver
-
nativeGetNativePeerConnection
private long nativeGetNativePeerConnection() -
nativeGetLocalDescription
-
nativeGetRemoteDescription
-
nativeGetCertificate
-
nativeCreateDataChannel
-
nativeCreateOffer
-
nativeCreateAnswer
-
nativeSetLocalDescriptionAutomatically
-
nativeSetLocalDescription
-
nativeSetRemoteDescription
-
nativeRestartIce
private void nativeRestartIce() -
nativeSetAudioPlayout
private void nativeSetAudioPlayout(boolean playout) -
nativeSetAudioRecording
private void nativeSetAudioRecording(boolean recording) -
nativeSetBitrate
-
nativeSignalingState
-
nativeIceConnectionState
-
nativeConnectionState
-
nativeIceGatheringState
-
nativeClose
private void nativeClose() -
nativeCreatePeerConnectionObserver
-
nativeFreeOwnedPeerConnection
private static void nativeFreeOwnedPeerConnection(long ownedPeerConnection) -
nativeSetConfiguration
-
nativeAddIceCandidate
-
nativeAddIceCandidateWithObserver
private void nativeAddIceCandidateWithObserver(String sdpMid, int sdpMLineIndex, String iceCandidateSdp, AddIceObserver observer) -
nativeRemoveIceCandidates
-
nativeAddLocalStream
private boolean nativeAddLocalStream(long stream) -
nativeRemoveLocalStream
private void nativeRemoveLocalStream(long stream) -
nativeOldGetStats
-
nativeNewGetStats
-
nativeCreateSender
-
nativeGetSenders
-
nativeGetReceivers
-
nativeGetTransceivers
-
nativeAddTrack
-
nativeRemoveTrack
private boolean nativeRemoveTrack(long sender) -
nativeAddTransceiverWithTrack
private RtpTransceiver nativeAddTransceiverWithTrack(long track, RtpTransceiver.RtpTransceiverInit init) -
nativeAddTransceiverOfType
private RtpTransceiver nativeAddTransceiverOfType(MediaStreamTrack.MediaType mediaType, RtpTransceiver.RtpTransceiverInit init) -
nativeStartRtcEventLog
private boolean nativeStartRtcEventLog(int file_descriptor, int max_size_bytes) -
nativeStopRtcEventLog
private void nativeStopRtcEventLog()
-