StreamPeerConnection

class StreamPeerConnection(coroutineScope: CoroutineScope, type: StreamPeerType, mediaConstraints: MediaConstraints, onStreamAdded: (MediaStream) -> Unit?, onNegotiationNeeded: (StreamPeerConnection, StreamPeerType) -> Unit?, onIceCandidate: (IceCandidate, StreamPeerType) -> Unit?, maxBitRate: Int) : PeerConnection.Observer

Wrapper around the WebRTC connection that contains tracks.

Parameters

coroutineScope

The scope used to listen to stats events.

type

The internal type of the PeerConnection. Check StreamPeerType.

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.

Constructors

Link copied to clipboard
constructor(coroutineScope: CoroutineScope, type: StreamPeerType, mediaConstraints: MediaConstraints, onStreamAdded: (MediaStream) -> Unit?, onNegotiationNeeded: (StreamPeerConnection, StreamPeerType) -> Unit?, onIceCandidate: (IceCandidate, StreamPeerType) -> Unit?, maxBitRate: Int)

Properties

Link copied to clipboard
var audioTransceiver: RtpTransceiver?

Transceiver used to send audio.

Link copied to clipboard
lateinit var connection: PeerConnection

The wrapped connection for all the WebRTC communication.

Link copied to clipboard
var videoTransceiver: RtpTransceiver?

Transceiver used to send video in different resolutions.

Functions

Link copied to clipboard
fun addAudioTransceiver(track: MediaStreamTrack, streamIds: List<String>)

Adds a local MediaStreamTrack with audio to a given connection, with its streamIds. The audio is then sent through a transceiver.

Link copied to clipboard
suspend fun addIceCandidate(iceCandidate: IceCandidate): Result<Unit>

Adds an IceCandidate to the underlying connection if it's already been set up, or stores it for later consumption.

Link copied to clipboard
fun addVideoTransceiver(track: MediaStreamTrack, streamIds: List<String>, isScreenShare: Boolean)

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.

Link copied to clipboard
suspend fun createAnswer(): Result<SessionDescription>

Used to create an answer whenever there's a subscriber offer.

Link copied to clipboard
suspend fun createOffer(): Result<SessionDescription>

Used to create an offer whenever there's a negotiation that we need to process on the publisher side.

Link copied to clipboard
suspend fun getStats(): RtcStatsReport?
Link copied to clipboard
fun initialize(peerConnection: PeerConnection)

Initialize a StreamPeerConnection using a WebRTC PeerConnection.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun onAddStream(stream: MediaStream?)

Triggered whenever there's a new MediaStream that was added to the connection.

Link copied to clipboard
open override fun onAddTrack(receiver: RtpReceiver?, mediaStreams: Array<out MediaStream>?)

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.

Link copied to clipboard
open override fun onConnectionChange(newState: PeerConnection.PeerConnectionState)

Triggered when the connection state changes. Used to start and stop the stats observing.

Link copied to clipboard
open override fun onDataChannel(channel: DataChannel?)
Link copied to clipboard
open override fun onIceCandidate(candidate: IceCandidate?)

Triggered whenever there's a new RtcIceCandidate for the call. Used to update our tracks and subscriptions.

Link copied to clipboard
open override fun onIceCandidateError(event: IceCandidateErrorEvent?)
Link copied to clipboard
open override fun onIceCandidatesRemoved(iceCandidates: Array<out IceCandidate>?)
Link copied to clipboard
open override fun onIceConnectionChange(newState: PeerConnection.IceConnectionState?)
Link copied to clipboard
open override fun onIceConnectionReceivingChange(receiving: Boolean)
Link copied to clipboard
open override fun onIceGatheringChange(newState: PeerConnection.IceGatheringState?)
Link copied to clipboard
open override fun onRemoveStream(stream: MediaStream?)

Triggered whenever a MediaStream was removed.

Link copied to clipboard
open override fun onRemoveTrack(receiver: RtpReceiver?)

Domain - PeerConnection and PeerConnection.Observer related callbacks.

Link copied to clipboard
open override fun onRenegotiationNeeded()

Triggered whenever there's a new negotiation needed for the active PeerConnection.

Link copied to clipboard
open override fun onSelectedCandidatePairChanged(event: CandidatePairChangeEvent?)
Link copied to clipboard
open override fun onSignalingChange(newState: PeerConnection.SignalingState?)
Link copied to clipboard
open override fun onTrack(transceiver: RtpTransceiver?)
Link copied to clipboard
suspend fun setLocalDescription(sessionDescription: SessionDescription): Result<Unit>

Sets the local description for a connection either for the subscriber or publisher based on the flow.

Link copied to clipboard
suspend fun setRemoteDescription(sessionDescription: SessionDescription): Result<Unit>

Used to set up the SDP on underlying connections and to add pendingIceCandidates to the connection for listening.

Link copied to clipboard
open override fun toString(): String

Inherited functions

Link copied to clipboard
open fun onStandardizedIceConnectionChange(p0: PeerConnection.IceConnectionState)