public class PeerConnection
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
PeerConnection.AdapterType |
static class |
PeerConnection.BundlePolicy
Java version of PeerConnectionInterface.BundlePolicy
|
static class |
PeerConnection.CandidateNetworkPolicy
Java version of PeerConnectionInterface.CandidateNetworkPolicy
|
static class |
PeerConnection.ContinualGatheringPolicy
Java version of PeerConnectionInterface.ContinualGatheringPolicy
|
static class |
PeerConnection.IceConnectionState
Tracks PeerConnectionInterface::IceConnectionState
|
static class |
PeerConnection.IceGatheringState
Tracks PeerConnectionInterface::IceGatheringState
|
static class |
PeerConnection.IceServer
Java version of PeerConnectionInterface.IceServer.
|
static class |
PeerConnection.IceTransportsType
Java version of PeerConnectionInterface.IceTransportsType
|
static class |
PeerConnection.KeyType
Java version of rtc::KeyType
|
static interface |
PeerConnection.Observer
Java version of PeerConnectionObserver.
|
static class |
PeerConnection.PeerConnectionState
Tracks PeerConnectionInterface::PeerConnectionState
|
static class |
PeerConnection.PortPrunePolicy
Java version of webrtc::PortPrunePolicy
|
static class |
PeerConnection.RTCConfiguration
Java version of PeerConnectionInterface.RTCConfiguration
|
static class |
PeerConnection.RtcpMuxPolicy
Java version of PeerConnectionInterface.RtcpMuxPolicy
|
static class |
PeerConnection.SdpSemantics
Java version of webrtc::SdpSemantics.
|
static class |
PeerConnection.SignalingState
Tracks PeerConnectionInterface::SignalingState
|
static class |
PeerConnection.TcpCandidatePolicy
Java version of PeerConnectionInterface.TcpCandidatePolicy
|
static class |
PeerConnection.TlsCertPolicy
Tracks PeerConnectionInterface::TlsCertPolicy
|
Constructor and Description |
---|
PeerConnection(NativePeerConnectionFactory factory)
Wraps a PeerConnection created by the factory.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addIceCandidate(IceCandidate candidate) |
boolean |
addStream(MediaStream stream)
Adds a new MediaStream to be sent on this peer connection.
|
RtpSender |
addTrack(MediaStreamTrack track)
Adds a new media stream track to be sent on this peer connection, and returns
the newly created RtpSender.
|
RtpSender |
addTrack(MediaStreamTrack track,
java.util.List<java.lang.String> streamIds) |
RtpTransceiver |
addTransceiver(MediaStreamTrack.MediaType mediaType) |
RtpTransceiver |
addTransceiver(MediaStreamTrack.MediaType mediaType,
RtpTransceiver.RtpTransceiverInit init) |
RtpTransceiver |
addTransceiver(MediaStreamTrack track)
Creates a new RtpTransceiver and adds it to the set of transceivers.
|
RtpTransceiver |
addTransceiver(MediaStreamTrack track,
RtpTransceiver.RtpTransceiverInit init) |
void |
close() |
PeerConnection.PeerConnectionState |
connectionState() |
void |
createAnswer(SdpObserver observer,
MediaConstraints constraints) |
DataChannel |
createDataChannel(java.lang.String label,
DataChannel.Init init) |
static long |
createNativePeerConnectionObserver(PeerConnection.Observer observer) |
void |
createOffer(SdpObserver observer,
MediaConstraints constraints) |
RtpSender |
createSender(java.lang.String kind,
java.lang.String stream_id)
Creates an RtpSender without a track.
|
void |
dispose()
Free native resources associated with this PeerConnection instance.
|
RtcCertificatePem |
getCertificate() |
SessionDescription |
getLocalDescription() |
long |
getNativePeerConnection()
Returns a pointer to the native webrtc::PeerConnectionInterface.
|
java.util.List<RtpReceiver> |
getReceivers()
Gets all RtpReceivers associated with this peer connection.
|
SessionDescription |
getRemoteDescription() |
java.util.List<RtpSender> |
getSenders()
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.
|
java.util.List<RtpTransceiver> |
getTransceivers()
Gets all RtpTransceivers associated with this peer connection.
|
PeerConnection.IceConnectionState |
iceConnectionState() |
PeerConnection.IceGatheringState |
iceGatheringState() |
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 |
setAudioPlayout(boolean playout)
Enables/disables playout of received audio streams.
|
void |
setAudioRecording(boolean recording)
Enables/disables recording of transmitted audio streams.
|
boolean |
setBitrate(java.lang.Integer min,
java.lang.Integer current,
java.lang.Integer max)
Limits the bandwidth allocated for all RTP streams sent by this
PeerConnection.
|
boolean |
setConfiguration(PeerConnection.RTCConfiguration config) |
void |
setLocalDescription(SdpObserver observer,
SessionDescription sdp) |
void |
setRemoteDescription(SdpObserver observer,
SessionDescription sdp) |
PeerConnection.SignalingState |
signalingState() |
boolean |
startRtcEventLog(int file_descriptor,
int max_size_bytes)
Starts recording an RTC event log.
|
void |
stopRtcEventLog()
Stops recording an RTC event log.
|
public PeerConnection(NativePeerConnectionFactory factory)
public SessionDescription getLocalDescription()
public SessionDescription getRemoteDescription()
public RtcCertificatePem getCertificate()
public DataChannel createDataChannel(java.lang.String label, DataChannel.Init init)
public void createOffer(SdpObserver observer, MediaConstraints constraints)
public void createAnswer(SdpObserver observer, MediaConstraints constraints)
public void setLocalDescription(SdpObserver observer, SessionDescription sdp)
public void setRemoteDescription(SdpObserver observer, SessionDescription sdp)
public void setAudioPlayout(boolean playout)
public void setAudioRecording(boolean recording)
public boolean setConfiguration(PeerConnection.RTCConfiguration config)
public boolean addIceCandidate(IceCandidate candidate)
public boolean removeIceCandidates(IceCandidate[] candidates)
public boolean addStream(MediaStream stream)
public void removeStream(MediaStream stream)
public RtpSender createSender(java.lang.String kind, java.lang.String stream_id)
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.
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.public java.util.List<RtpSender> getSenders()
public java.util.List<RtpReceiver> getReceivers()
public java.util.List<RtpTransceiver> getTransceivers()
public RtpSender addTrack(MediaStreamTrack track)
java.lang.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.public RtpSender addTrack(MediaStreamTrack track, java.util.List<java.lang.String> streamIds)
public boolean removeTrack(RtpSender sender)
public RtpTransceiver addTransceiver(MediaStreamTrack track)
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.
java.lang.IllegalStateException
- if an error accors in C++ addTransceiverpublic RtpTransceiver addTransceiver(MediaStreamTrack track, @Nullable RtpTransceiver.RtpTransceiverInit init)
public RtpTransceiver addTransceiver(MediaStreamTrack.MediaType mediaType)
public RtpTransceiver addTransceiver(MediaStreamTrack.MediaType mediaType, @Nullable RtpTransceiver.RtpTransceiverInit init)
@Deprecated public boolean getStats(StatsObserver observer, @Nullable MediaStreamTrack track)
public void getStats(RTCStatsCollectorCallback callback)
public boolean setBitrate(java.lang.Integer min, java.lang.Integer current, java.lang.Integer max)
public boolean startRtcEventLog(int file_descriptor, int max_size_bytes)
public void stopRtcEventLog()
public PeerConnection.SignalingState signalingState()
public PeerConnection.IceConnectionState iceConnectionState()
public PeerConnection.PeerConnectionState connectionState()
public PeerConnection.IceGatheringState iceGatheringState()
public void close()
public void dispose()
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.
public long getNativePeerConnection()
public static long createNativePeerConnectionObserver(PeerConnection.Observer observer)
6.4.1