View Source ExWebRTC.PeerConnection (ex_webrtc v0.4.0)
Implementation of the RTCPeerConnection.
Summary
Types
Possible connection states.
Possible ICE connection states.
Possible ICE gathering states.
Messages sent by the ExWebRTC.PeerConnection process to its controlling process.
Possible signaling states.
Functions
Adds a new remote ICE candidate.
Adds a new track.
Adds a new transceiver.
Returns a specification to start this module under a supervisor.
Closes the PeerConnection.
Changes the controlling process of this peer_connection process.
Creates an SDP answer.
Creates an SDP offer.
Returns a list of all running ExWebRTC.PeerConnection processes.
Returns the connection state.
Returns the current local description.
Returns the current remote description.
Returns the ICE connection state.
Returns the ICE gathering state.
Returns the local description.
Returns the pending local description.
Returns the pending remote description.
Returns the remote description.
Returns the signaling state.
Returns PeerConnection's statistics.
Returns the list of transceivers.
Removes the track assigned to the sender specified by the sender_id.
Replaces the track assigned to the sender specified by the sender_id.
Sends an RTCP PLI feedback to the remote peer using the track specified by the track_id.
Sends an RTP packet to the remote peer using the track specified by the track_id.
Sets the local description.
Sets the remote description.
Sets the direction of transceiver specified by the transceiver_id.
Starts a new ExWebRTC.PeerConnection process.
Starts a new ExWebRTC.PeerConnection process.
Stops the transceiver specified by the transceiver_id.
Types
@type connection_state() ::
:new | :connecting | :connected | :disconnected | :failed | :closed
Possible connection states.
For the exact meaning, refer to the RTCPeerConnection: connectionState property.
@type ice_connection_state() ::
:new | :checking | :connected | :completed | :failed | :disconnected | :closed
Possible ICE connection states.
For the exact meaning, refer to the RTCPeerConnection: iceConnectionState property.
@type ice_gathering_state() :: :new | :gathering | :complete
Possible ICE gathering states.
For the exact meaning, refer to the RTCPeerConnection: iceGatheringState property.
@type message() :: {:ex_webrtc, pid(), {:connection_state_change, connection_state()} | {:ice_candidate, ExWebRTC.ICECandidate.t()} | {:ice_connection_state_change, ice_connection_state()} | {:ice_gathering_state_change, ice_gathering_state()} | :negotiation_needed | {:signaling_state_change, signaling_state()} | {:track, ExWebRTC.MediaStreamTrack.t()} | {:track_muted, ExWebRTC.MediaStreamTrack.id()} | {:track_ended, ExWebRTC.MediaStreamTrack.id()} | {:rtp, ExWebRTC.MediaStreamTrack.id(), String.t() | nil, ExRTP.Packet.t()}} | {:rtcp, [{ExWebRTC.MediaStreamTrack.id() | nil, ExRTCP.Packet.packet()}]}
Messages sent by the ExWebRTC.PeerConnection process to its controlling process.
Most of the messages match the RTCPeerConnection events, except for:
:track_muted,:track_ended- these match the MediaStreamTrack events.:rtpand:rtcp- these contain packets received by the PeerConnection. The third element of:rtptuple is a simulcast RID and is set tonilif simulcast is not used.- each of the packets in
:rtcpmessage is in the form of{track_id, packet}tuple, wheretrack_idis the id of the corrsponding track. In case of PLI and NACK, this is the id of an outgoing (sender's) track id, in case of Sender and Receiver Reports - incoming (receiver's) track id. If matching to a track was not possible (like in the case of TWCC packedts),track_idis set tonil.
@type peer_connection() :: GenServer.server()
@type signaling_state() :: :stable | :have_local_offer | :have_remote_offer
Possible signaling states.
For the exact meaning, refer to the RTCPeerConnection: signalingState property.
Functions
@spec add_ice_candidate(peer_connection(), ExWebRTC.ICECandidate.t()) :: :ok | {:error, term()}
Adds a new remote ICE candidate.
For more information, refer to the RTCPeerConnection: addIceCandidate() method.
@spec add_track(peer_connection(), ExWebRTC.MediaStreamTrack.t()) :: {:ok, ExWebRTC.RTPSender.t()}
Adds a new track.
For more information, refer to the RTCPeerConnection: addTrack() method.
@spec add_transceiver( peer_connection(), ExWebRTC.RTPTransceiver.kind() | ExWebRTC.MediaStreamTrack.t(), [{:direction, ExWebRTC.RTPTransceiver.direction()}] ) :: {:ok, ExWebRTC.RTPTransceiver.t()}
Adds a new transceiver.
For more information, refer to the RTCPeerConnection: addTransceiver() method.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec close(peer_connection()) :: :ok
Closes the PeerConnection.
This function kills the peer_connection process.
For more information, refer to the RTCPeerConnection: close() method.
@spec controlling_process(peer_connection(), Process.dest()) :: :ok
Changes the controlling process of this peer_connection process.
Controlling process is a process that receives all of the messages (described
by message/0) from this PeerConnection.
@spec create_answer(peer_connection()) :: {:ok, ExWebRTC.SessionDescription.t()} | {:error, term()}
Creates an SDP answer.
For more information, refer to the RTCPeerConnection: createAnswer() method.
@spec create_offer(peer_connection(), [{:restart_ice?, boolean()}]) :: {:ok, ExWebRTC.SessionDescription.t()} | {:error, term()}
Creates an SDP offer.
For more information, refer to the RTCPeerConnection: createOffer() method.
@spec get_all_running() :: [pid()]
Returns a list of all running ExWebRTC.PeerConnection processes.
@spec get_connection_state(peer_connection()) :: connection_state()
Returns the connection state.
For more information, refer to the RTCPeerConnection: connectionState property.
@spec get_current_local_description(peer_connection()) :: ExWebRTC.SessionDescription.t() | nil
Returns the current local description.
For more information, refer to the RTCPeerConnection: currentLocalDescription property.
@spec get_current_remote_description(peer_connection()) :: ExWebRTC.SessionDescription.t() | nil
Returns the current remote description.
For more information, refer to the RTCPeerConnection: currentRemoteDescription property.
@spec get_ice_connection_state(peer_connection()) :: ice_connection_state()
Returns the ICE connection state.
For more information, refer to the RTCPeerConnection: iceConnectionState property.
@spec get_ice_gathering_state(peer_connection()) :: ice_gathering_state()
Returns the ICE gathering state.
For more information, refer to the RTCPeerConnection: iceGatheringState property.
@spec get_local_description(peer_connection()) :: ExWebRTC.SessionDescription.t() | nil
Returns the local description.
For more information, refer to the RTCPeerConnection: localDescription property.
@spec get_pending_local_description(peer_connection()) :: ExWebRTC.SessionDescription.t() | nil
Returns the pending local description.
For more information, refer to the RTCPeerConnection: pendingLocalDescription property.
@spec get_pending_remote_description(peer_connection()) :: ExWebRTC.SessionDescription.t() | nil
Returns the pending remote description.
For more information, refer to the RTCPeerConnection: pendingRemoteDescription property.
@spec get_remote_description(peer_connection()) :: ExWebRTC.SessionDescription.t() | nil
Returns the remote description.
For more information, refer to the RTCPeerConnection: remoteDescription property.
@spec get_signaling_state(peer_connection()) :: signaling_state()
Returns the signaling state.
For more information, refer to the RTCPeerConnection: signalingState property.
@spec get_stats(peer_connection()) :: %{required(atom() | integer()) => map()}
Returns PeerConnection's statistics.
For more information, refer to the RTCPeerConnection: getStats() method. See RTCStatsReport for the output structure.
@spec get_transceivers(peer_connection()) :: [ExWebRTC.RTPTransceiver.t()]
Returns the list of transceivers.
For more information, refer to the RTCPeerConnection: getTransceivers() method.
@spec remove_track(peer_connection(), ExWebRTC.RTPSender.id()) :: :ok | {:error, term()}
Removes the track assigned to the sender specified by the sender_id.
For more information, refer to the RTCPeerConnection: removeTrack() method.
@spec replace_track( peer_connection(), ExWebRTC.RTPSender.id(), ExWebRTC.MediaStreamTrack.t() ) :: :ok | {:error, term()}
Replaces the track assigned to the sender specified by the sender_id.
For more information, refer to the RTCRtpSender: replaceTrack() method.
@spec send_pli(peer_connection(), ExWebRTC.MediaStreamTrack.id(), String.t() | nil) :: :ok
Sends an RTCP PLI feedback to the remote peer using the track specified by the track_id.
Set rid to the simulcast rid for which the PLI should be sent. If simulcast is not used, rid should
be equal to nil.
@spec send_rtp( peer_connection(), ExWebRTC.MediaStreamTrack.id(), ExRTP.Packet.t(), [{:rtx?, boolean()}] ) :: :ok
Sends an RTP packet to the remote peer using the track specified by the track_id.
Options:
rtx?- send the packet as if it was retransmitted (use SSRC and payload type specific to RTX)
@spec set_local_description(peer_connection(), ExWebRTC.SessionDescription.t()) :: :ok | {:error, term()}
Sets the local description.
For more information, refer to the RTCPeerConnection: setLocalDescription() method.
@spec set_remote_description(peer_connection(), ExWebRTC.SessionDescription.t()) :: :ok | {:error, term()}
Sets the remote description.
For more information, refer to the RTCPeerConnection: setRemoteDescription() method.
set_transceiver_direction(peer_connection, transceiver_id, direction)
View Source@spec set_transceiver_direction( peer_connection(), ExWebRTC.RTPTransceiver.id(), ExWebRTC.RTPTransceiver.direction() ) :: :ok | {:error, term()}
Sets the direction of transceiver specified by the transceiver_id.
For more information, refer to the RTCRtpTransceiver: direction property.
@spec start(ExWebRTC.PeerConnection.Configuration.options(), GenServer.options()) :: GenServer.on_start()
Starts a new ExWebRTC.PeerConnection process.
ExWebRTC.PeerConnection is a GenServer under the hood, thus this function allows for
passing the generic GenServer.options/0 as an argument.
@spec start_link(ExWebRTC.PeerConnection.Configuration.options(), GenServer.options()) :: GenServer.on_start()
Starts a new ExWebRTC.PeerConnection process.
Works identically to start/2, but links to the calling process.
@spec stop_transceiver(peer_connection(), ExWebRTC.RTPTransceiver.id()) :: :ok | {:error, term()}
Stops the transceiver specified by the transceiver_id.
For more information, refer to the RTCRtpTransceiver: stop() method.