Class StreamPeerConnection
-
- All Implemented Interfaces:
-
org.webrtc.PeerConnection.Observer
public final class StreamPeerConnection implements PeerConnection.ObserverWrapper around the WebRTC connection that contains tracks.
-
-
Field Summary
Fields Modifier and Type Field Description private final PeerConnectionconnectionprivate final RtpTransceivervideoTransceiverprivate final RtpTransceiveraudioTransceiver
-
Constructor Summary
Constructors Constructor Description StreamPeerConnection(CoroutineScope coroutineScope, StreamPeerType type, MediaConstraints mediaConstraints, Function1<MediaStream, Unit> onStreamAdded, Function2<StreamPeerConnection, StreamPeerType, Unit> onNegotiationNeeded, Function2<IceCandidate, StreamPeerType, Unit> onIceCandidate, Integer maxBitRate)
-
Method Summary
Modifier and Type Method Description final PeerConnectiongetConnection()The wrapped connection for all the WebRTC communication. final RtpTransceivergetVideoTransceiver()Transceiver used to send video in different resolutions. final RtpTransceivergetAudioTransceiver()Transceiver used to send audio. final BooleanisHealthy()final Unitinitialize(PeerConnection peerConnection)Initialize a StreamPeerConnection using a WebRTC PeerConnection. final Result<SessionDescription>createOffer()Used to create an offer whenever there's a negotiation that we need to process on the publisher side. final Result<SessionDescription>createAnswer()Used to create an answer whenever there's a subscriber offer. final Result<Unit>setRemoteDescription(SessionDescription sessionDescription)Used to set up the SDP on underlying connections and to add pendingIceCandidates to the connection for listening. final Result<Unit>setLocalDescription(SessionDescription sessionDescription)Sets the local description for a connection either for the subscriber or publisher based on the flow. final Result<Unit>addIceCandidate(IceCandidate iceCandidate)Adds an IceCandidate to the underlying connection if it's already been set up, or stores it for later consumption. final UnitaddAudioTransceiver(MediaStreamTrack track, List<String> streamIds)Adds a local MediaStreamTrack with audio to a given connection, with its streamIds. final UnitaddVideoTransceiver(MediaStreamTrack track, List<String> streamIds, Boolean isScreenShare)Adds a local MediaStreamTrack with video to a given connection, with its streamIds. UnitonIceCandidate(IceCandidate candidate)Triggered whenever there's a new RtcIceCandidate for the call. UnitonAddStream(MediaStream stream)Triggered whenever there's a new MediaStream that was added to the connection. UnitonAddTrack(RtpReceiver receiver, Array<out MediaStream> mediaStreams)Triggered whenever there's a new MediaStream or MediaStreamTrack that's been added to the call. UnitonRenegotiationNeeded()Triggered whenever there's a new negotiation needed for the active PeerConnection. UnitonRemoveStream(MediaStream stream)Triggered whenever a MediaStream was removed. UnitonConnectionChange(PeerConnection.PeerConnectionState newState)Triggered when the connection state changes. UnitonIceConnectionChange(PeerConnection.IceConnectionState newState)final RtcStatsReportgetStats()UnitonRemoveTrack(RtpReceiver receiver)Domain - PeerConnection and PeerConnection.Observer related callbacks. UnitonSignalingChange(PeerConnection.SignalingState newState)UnitonIceConnectionReceivingChange(Boolean receiving)UnitonIceGatheringChange(PeerConnection.IceGatheringState newState)UnitonIceCandidatesRemoved(Array<out IceCandidate> iceCandidates)UnitonIceCandidateError(IceCandidateErrorEvent event)UnitonSelectedCandidatePairChanged(CandidatePairChangeEvent event)UnitonTrack(RtpTransceiver transceiver)UnitonDataChannel(DataChannel channel)StringtoString()-
-
Constructor Detail
-
StreamPeerConnection
StreamPeerConnection(CoroutineScope coroutineScope, StreamPeerType type, MediaConstraints mediaConstraints, Function1<MediaStream, Unit> onStreamAdded, Function2<StreamPeerConnection, StreamPeerType, Unit> onNegotiationNeeded, Function2<IceCandidate, StreamPeerType, Unit> onIceCandidate, Integer maxBitRate)
- Parameters:
coroutineScope- The scope used to listen to stats events.type- The internal type of the PeerConnection.mediaConstraints- Constraints used for the connections.onStreamAdded- Handler when a new MediaStream gets added.onNegotiationNeeded- Handler when there's a new negotiation.onIceCandidate- Handler whenever we receive IceCandidates.
-
-
Method Detail
-
getConnection
final PeerConnection getConnection()
The wrapped connection for all the WebRTC communication.
-
getVideoTransceiver
final RtpTransceiver getVideoTransceiver()
Transceiver used to send video in different resolutions.
-
getAudioTransceiver
final RtpTransceiver getAudioTransceiver()
Transceiver used to send audio.
-
initialize
final Unit initialize(PeerConnection peerConnection)
Initialize a StreamPeerConnection using a WebRTC PeerConnection.
- Parameters:
peerConnection- The connection that holds audio and video tracks.
-
createOffer
final Result<SessionDescription> createOffer()
Used to create an offer whenever there's a negotiation that we need to process on the publisher side.
- Returns:
Result wrapper of the SessionDescription for the publisher.
-
createAnswer
final Result<SessionDescription> createAnswer()
Used to create an answer whenever there's a subscriber offer.
- Returns:
Result wrapper of the SessionDescription for the subscriber.
-
setRemoteDescription
final Result<Unit> setRemoteDescription(SessionDescription sessionDescription)
Used to set up the SDP on underlying connections and to add pendingIceCandidates to the connection for listening.
- Parameters:
sessionDescription- That contains the remote SDP.- Returns:
An empty Result, if the operation has been successful or not.
-
setLocalDescription
final Result<Unit> setLocalDescription(SessionDescription sessionDescription)
Sets the local description for a connection either for the subscriber or publisher based on the flow.
- Parameters:
sessionDescription- That contains the subscriber or publisher SDP.- Returns:
An empty Result, if the operation has been successful or not.
-
addIceCandidate
final Result<Unit> addIceCandidate(IceCandidate iceCandidate)
Adds an IceCandidate to the underlying connection if it's already been set up, or stores it for later consumption.
- Parameters:
iceCandidate- To process and add to the connection.- Returns:
An empty Result, if the operation has been successful or not.
-
addAudioTransceiver
final Unit addAudioTransceiver(MediaStreamTrack track, List<String> streamIds)
Adds a local MediaStreamTrack with audio to a given connection, with its streamIds. The audio is then sent through a transceiver.
- Parameters:
track- The track that contains audio.streamIds- The IDs that represent the stream tracks.
-
addVideoTransceiver
final Unit addVideoTransceiver(MediaStreamTrack track, List<String> streamIds, Boolean isScreenShare)
Adds a local MediaStreamTrack with video to a given connection, with its streamIds. The video is then sent in a few different resolutions using simulcast.
- Parameters:
track- The track that contains video.streamIds- The IDs that represent the stream tracks.
-
onIceCandidate
Unit onIceCandidate(IceCandidate candidate)
Triggered whenever there's a new RtcIceCandidate for the call. Used to update our tracks and subscriptions.
- Parameters:
candidate- The new candidate.
-
onAddStream
Unit onAddStream(MediaStream stream)
Triggered whenever there's a new MediaStream that was added to the connection.
- Parameters:
stream- The stream that contains audio or video.
-
onAddTrack
Unit onAddTrack(RtpReceiver receiver, Array<out MediaStream> mediaStreams)
Triggered whenever there's a new MediaStream or MediaStreamTrack that's been added to the call. It contains all audio and video tracks for a given session.
- Parameters:
receiver- The receiver of tracks.mediaStreams- The streams that were added containing their appropriate tracks.
-
onRenegotiationNeeded
Unit onRenegotiationNeeded()
Triggered whenever there's a new negotiation needed for the active PeerConnection.
-
onRemoveStream
Unit onRemoveStream(MediaStream stream)
Triggered whenever a MediaStream was removed.
- Parameters:
stream- The stream that was removed from the connection.
-
onConnectionChange
Unit onConnectionChange(PeerConnection.PeerConnectionState newState)
Triggered when the connection state changes. Used to start and stop the stats observing.
- Parameters:
newState- The new state of the PeerConnection.
-
onIceConnectionChange
Unit onIceConnectionChange(PeerConnection.IceConnectionState newState)
-
getStats
final RtcStatsReport getStats()
- Returns:
The RtcStatsReport for the active connection.
-
onRemoveTrack
Unit onRemoveTrack(RtpReceiver receiver)
Domain - PeerConnection and PeerConnection.Observer related callbacks.
-
onSignalingChange
Unit onSignalingChange(PeerConnection.SignalingState newState)
-
onIceConnectionReceivingChange
Unit onIceConnectionReceivingChange(Boolean receiving)
-
onIceGatheringChange
Unit onIceGatheringChange(PeerConnection.IceGatheringState newState)
-
onIceCandidatesRemoved
Unit onIceCandidatesRemoved(Array<out IceCandidate> iceCandidates)
-
onIceCandidateError
Unit onIceCandidateError(IceCandidateErrorEvent event)
-
onSelectedCandidatePairChanged
Unit onSelectedCandidatePairChanged(CandidatePairChangeEvent event)
-
onDataChannel
Unit onDataChannel(DataChannel channel)
-
-
-
-