View Source Membrane.RTC.Engine.Endpoint.WebRTC (Membrane RTC Engine v0.11.0)

An Endpoint responsible for communicatiing with WebRTC peer.

It is responsible for sending and receiving media tracks from other WebRTC peer (e.g. web browser).



In order to operate correctly, this endpoint requires that the business logic implements the signalling channel to the peer it represents. Implementation details are not important to endpoint.

Signalling in WebRTC is used to eg. facilitate SDP negotiation or send notifications regarding the session. This endpoint uses an abstraction of Media Events to achieve this. A Media Event is a black box message sent between the Client Library and this endpoint.

The business logic will receive an encoded media event in binary form from both the endpoint and the client library. It's only responsibility is to feed the binary to either the endpoint or the client library.


Message Protocol Definition

The business logic must receive media_event_message_t/0 message from the endpoint and forward it to the client over the implemented signalling channel. Mind you, this message will be wrapped with Membrane.RTC.Engine.Message.EndpointMessage.t/0


@impl GenServer
def handle_info(%Membrane.RTC.Engine.Message.EndpointMessage{endpoint_id: endpoint, message: {:media_event, _event} = message}, state) do
  send state.channels[endpoint], message
  {:noreply, state}

Simmilarily, it must forward all media events it receives over the signalling channel to the endpoint by sending a media_event_message_t/0 to it.


@impl GenServer
def handle_info({:media_event, origin, event}, state) do
  endpoint_id = state.peer_channel_to_endpoint_id[origin]
  Engine.message_endpoint(endpoint_id, {:media_event, event})
  {:noreply, state}


Client libraries

The following client libraries for handling signalling messages are available:


Monitoring track activity

WebRTC Endpoint only monitors simulcast tracks activity, meaning that it never emits Membrane.RTC.Engine.Event.TrackVariantPaused event for non-simulcast tracks. The main reason is that it's impossible to tell if the screensharing track is inactive or not sending any packets because it contains static content.


Bin options

Passed via struct Membrane.RTC.Engine.Endpoint.WebRTC.t/0

  • rtc_engine


    Pid of parent Engine

  • direction


    Default value: :sendrecv
    Direction of WebRTC Endpoint. Determines whether EndpointBin can send, receive or both send and receive media. For more information refer to t:EndpointBin.direction/0.

  • ice_name


    Ice name is used in creating credentials for ice connnection

  • handshake_opts


    Default value: []
    Keyword list with options for handshake module. For more information please refer to Membrane.ICE.Bin

  • filter_codecs

    ({RTPMapping.t(), FMTP.t() | nil} -> boolean())

    Default value: &Membrane.WebRTC.SDP.filter_encodings/1
    Defines function which will filter SDP m-line by codecs

  • log_metadata


    Default value: []
    Logger metadata used for endpoint bin and all its descendants

  • webrtc_extensions


    Default value: []
    List of WebRTC extensions to use.

    Each module has to implement Membrane.WebRTC.Extension.t(). See membrane_webrtc_plugin documentation for a list of possible extensions.

  • extensions

    %{(encoding_name :: atom() | :any) => [Membrane.RTP.SessionBin.extension_t()]}

    Default value: %{}
    A map pointing from encoding names to lists of extensions that should be used for given encodings. Encoding ":any" indicates that extensions should be applied regardless of encoding.

    A sample usage would be to add silence discarder to OPUS tracks when VAD extension is enabled. It can greatly reduce CPU usage in rooms when there are a lot of people but only a few of them are actively speaking.

  • integrated_turn_domain

    binary() | nil

    Default value: nil
    Domain address of integrated TURN Servers. Required for TLS TURN

  • integrated_turn_options


    Default value: []

  • owner


    Pid of parent all notifications will be send to.

    To see possible notifications please refer to module docs.

  • trace_context


    Default value: []
    Trace context for otel propagation

  • parent_span

    :opentelemetry.span_ctx() | nil

    Default value: nil
    Parent span of webrtc_endpoint.life_span

  • video_tracks_limit

    integer() | nil

    Default value: nil
    Maximal number of video tracks that will be sent to the the browser at the same time.

    This variable indicates how many video tracks should be sent to the browser at the same time. If nil all video tracks this Membrane.RTC.Engine.Endpoint.WebRTC receives will be sent.

  • rtcp_receiver_report_interval

    Membrane.Time.t() | nil

    Default value: nil
    Receiver reports's generation interval, set to nil to avoid reports generation

  • rtcp_sender_report_interval

    Membrane.Time.t() | nil

    Default value: nil
    Sender reports's generation interval, set to nil to avoid reports generation

  • simulcast_config


    Default value: %Membrane.RTC.Engine.Endpoint.WebRTC.SimulcastConfig{enabled: false, initial_target_variant: &Membrane.RTC.Engine.Endpoint.WebRTC.SimulcastConfig.initial_target_variant/1}
    Simulcast configuration

  • peer_metadata


    Default value: nil
    Peer metadata

  • telemetry_label


    Default value: []
    Label passed to Membrane.TelemetryMetrics functions

  • toilet_capacity


    Default value: 200
    TrackReceiver toilet capacity





Accepted formats:

Demand unit::buffers



Accepted formats:

Demand unit::buffers

Link to this section Summary


Type describing message format used to send media events both to the business logic and by the business logic to this endpoint.


Struct containing options for Membrane.RTC.Engine.Endpoint.WebRTC


Returns description of options available for this module

Link to this section Types

@type encoding_t() :: String.t()
Link to this type


View Source
@type media_event_message_t() :: {:media_event, binary()}

Type describing message format used to send media events both to the business logic and by the business logic to this endpoint.

@type t() :: %Membrane.RTC.Engine.Endpoint.WebRTC{
  direction: Membrane.WebRTC.EndpointBin.direction(),
  extensions: %{
    required(encoding_name :: atom() | :any) => [
    ({ExSDP.Attribute.RTPMapping.t(), ExSDP.Attribute.FMTP.t() | nil} ->
  handshake_opts: Keyword.t(),
  ice_name: String.t(),
  integrated_turn_domain: binary() | nil,
  integrated_turn_options: Membrane.ICE.Endpoint.integrated_turn_options_t(),
  log_metadata: :list,
  owner: pid(),
  parent_span: :opentelemetry.span_ctx() | nil,
  peer_metadata: any(),
  rtc_engine: pid(),
  rtcp_receiver_report_interval: Membrane.Time.t() | nil,
  rtcp_sender_report_interval: Membrane.Time.t() | nil,
  simulcast_config: Membrane.RTC.Engine.Endpoint.WebRTC.SimulcastConfig.t(),
  telemetry_label: Membrane.TelemetryMetrics.label(),
  toilet_capacity: pos_integer(),
  trace_context: :list,
  video_tracks_limit: integer() | nil,
  webrtc_extensions: [module()]

Struct containing options for Membrane.RTC.Engine.Endpoint.WebRTC

Link to this section Functions

@spec options() :: keyword()

Returns description of options available for this module