View Source Membrane.WebRTC.Signaling (Membrane WebRTC plugin v0.24.0)

Signaling channel for sending WebRTC signaling messages between Membrane elements and other WebRTC peers.

The flow of using the signaling channel is the following:

Summary

Types

Messages sent and received if message_format is ex_webrtc.

Messages sent and received if message_format is json_data.

Messages sent by the signaling channel to the peer.

Messages that the peer sends with signal/2 and receives in message/0.

t()

Functions

Returns a specification to start this module under a supervisor.

Registers a process as a peer, so that it can send and receive signaling messages.

Sends a signaling message to the signaling channel.

Types

ex_webrtc_message()

@type ex_webrtc_message() ::
  ExWebRTC.ICECandidate.t() | ExWebRTC.SessionDescription.t()

Messages sent and received if message_format is ex_webrtc.

json_data_message()

@type json_data_message() :: %{required(String.t()) => term()}

Messages sent and received if message_format is json_data.

The keys and values are the following

  • %{"type" => "sdp_offer", "data" => data}, where data is the return value of ExWebRTC.SessionDescription.to_json/1 or RTCPeerConnection.create_offer in the JavaScript API
  • %{"type" => "sdp_answer", "data" => data}, where data is the return value of ExWebRTC.SessionDescription.to_json/1 or RTCPeerConnection.create_answer in the JavaScript API
  • %{"type" => "ice_candidate", "data" => data}, where data is the return value of ExWebRTC.ICECandidate.to_json/1 or event.candidate from the RTCPeerConnection.onicecandidate callback in the JavaScript API.

message()

@type message() ::
  {Membrane.WebRTC.Signaling, pid(), message_content(), metadata :: map()}

Messages sent by the signaling channel to the peer.

message_content()

@type message_content() :: ex_webrtc_message() | json_data_message()

Messages that the peer sends with signal/2 and receives in message/0.

If the message_format of the peer is ex_webrtc (default), they should be ex_webrtc_message/0. If the message_format is json_data, they should be json_data_message/0.

The message_format of the peer can be set in register_peer/2.

t()

@type t() :: %Membrane.WebRTC.Signaling{pid: pid()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(signaling)

@spec close(t()) :: :ok

new()

@spec new() :: t()

register_peer(signaling, opts \\ [])

@spec register_peer(t(), message_format: :ex_webrtc | :json_data, pid: pid()) :: :ok

Registers a process as a peer, so that it can send and receive signaling messages.

Options:

  • pid - pid of the peer, self() by default
  • message_format - :ex_webrtc by default, see message_content/0

See the moduledoc for details.

signal(signaling, message, metadata \\ %{})

@spec signal(t(), message_content(), metadata :: map()) :: :ok

Sends a signaling message to the signaling channel.

The calling process must be previously registered with register_peer/2. See the moduledoc for details.