PeerConnection

tee3.webrtc

## 类 PeerConnection

- java.lang.Object
- - tee3.webrtc.PeerConnection

-     public class PeerConnection
      extends java.lang.Object

  Java-land version of the PeerConnection APIs; wraps the C++ API http://www.webrtc.org/reference/native-apis, which in turn is inspired by the JS APIs: http://dev.w3.org/2011/webrtc/editor/webrtc.html and http://www.w3.org/TR/mediacapture-streams/

- - ### 嵌套类概要

    嵌套类
    限定符和类型 | 类和说明
    --- | ---
    `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.IntervalRange` Java version of rtc::IntervalRange
    `static class` | `PeerConnection.KeyType` Java version of rtc::KeyType
    `static interface` | `PeerConnection.Observer` Java version of PeerConnectionObserver.
    `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

  - ### 构造器概要

    构造器
    构造器和说明
    `PeerConnection(NativePeerConnectionFactory factory)` Wraps a PeerConnection created by the factory.

  - ### 方法概要

    所有方法 静态方法 实例方法 具体方法 已过时的方法
    限定符和类型 | 方法和说明
    --- | ---
    `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()`
    `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.
    `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)` 已过时。
    `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.

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 构造器详细资料

    - #### PeerConnection

          public PeerConnection(NativePeerConnectionFactory factory)

      Wraps a PeerConnection created by the factory. Can be used by clients that want to implement their PeerConnection creation in JNI.

  - ### 方法详细资料

    - #### getLocalDescription

          public SessionDescription getLocalDescription()

    - #### getRemoteDescription

          public SessionDescription getRemoteDescription()

    - #### createDataChannel

          public DataChannel createDataChannel(java.lang.String label,
                                               DataChannel.Init init)

    - #### createOffer

          public void createOffer(SdpObserver observer,
                                  MediaConstraints constraints)

    - #### createAnswer

          public void createAnswer(SdpObserver observer,
                                   MediaConstraints constraints)

    - #### setLocalDescription

          public void setLocalDescription(SdpObserver observer,
                                          SessionDescription sdp)

    - #### setRemoteDescription

          public void setRemoteDescription(SdpObserver observer,
                                           SessionDescription sdp)

    - #### 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

          public boolean setConfiguration(PeerConnection.RTCConfiguration config)

    - #### addIceCandidate

          public boolean addIceCandidate(IceCandidate candidate)

    - #### removeIceCandidates

          public boolean removeIceCandidates(IceCandidate[] candidates)

    - #### addStream

          public boolean addStream(MediaStream stream)

      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

          public void removeStream(MediaStream stream)

      Removes the given media stream from this peer connection. This method is not supported with SdpSemantics.UNIFIED_PLAN. Please use removeTrack instead.

    - #### createSender

          public RtpSender createSender(java.lang.String kind,
                                        java.lang.String stream_id)

      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.

      参数:
        `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.
      返回:
        A new RtpSender object if successful, or null otherwise.

    - #### getSenders

          public java.util.List<RtpSender> getSenders()

      Gets all RtpSenders associated with this peer connection. Note that calling getSenders will dispose of the senders previously returned.

    - #### getReceivers

          public java.util.List<RtpReceiver> getReceivers()

      Gets all RtpReceivers associated with this peer connection. Note that calling getReceivers will dispose of the receivers previously returned.

    - #### getTransceivers

          public java.util.List<RtpTransceiver> 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

          public RtpSender addTrack(MediaStreamTrack track)

      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.
      抛出:
        `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.

    - #### addTrack

          public RtpSender addTrack(MediaStreamTrack track,
                                    java.util.List<java.lang.String> streamIds)

    - #### removeTrack

          public boolean removeTrack(RtpSender sender)

      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

          public RtpTransceiver addTransceiver(MediaStreamTrack track)

      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.

      抛出:
        `java.lang.IllegalStateException` - if an error accors in C++ addTransceiver

    - #### addTransceiver

          public RtpTransceiver addTransceiver(MediaStreamTrack track,
                                               @Nullable
                                               RtpTransceiver.RtpTransceiverInit init)

    - #### addTransceiver

          public RtpTransceiver addTransceiver(MediaStreamTrack.MediaType mediaType)

    - #### addTransceiver

          public RtpTransceiver addTransceiver(MediaStreamTrack.MediaType mediaType,
                                               @Nullable
                                               RtpTransceiver.RtpTransceiverInit init)

    - #### getStats

          @Deprecated
          public boolean getStats(StatsObserver observer,
                                               @Nullable
                                               MediaStreamTrack track)

      已过时。

    - #### getStats

          public void getStats(RTCStatsCollectorCallback callback)

      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

          public 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. 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_portrait 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

          public PeerConnection.SignalingState signalingState()

    - #### iceConnectionState

          public PeerConnection.IceConnectionState iceConnectionState()

    - #### iceGatheringState

          public PeerConnection.IceGatheringState 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

          public static long createNativePeerConnectionObserver(PeerConnection.Observer observer)