MobWebrtc.Engine behaviour (mob_webrtc v0.1.0)

Copy Markdown View Source

What a WebRTC implementation provides to MobWebrtc.Peer.

An engine owns one peer connection per start_link/1 and reports to the process that called it with messages of its own shape; event/1 turns each into the engine-neutral events MobWebrtc documents, so a screen never sees which engine is underneath. Descriptions and ICE candidates are JSON-shaped maps with string keys (RTCSessionDescriptionInit, RTCIceCandidateInit), ready to send over signaling as they are.

Engines:

Summary

Callbacks

Opens a data channel. Options: :ordered (boolean, default true), :max_retransmits or :max_packet_life_time (ms; neither means reliable), :protocol.

Turns a message the engine sent its caller into MobWebrtc events, or :ignore.

The local description with every local candidate gathered so far in it (RTCPeerConnection.localDescription), or nil before one is set.

Asks the remote sender of track_id (a receive track) for a keyframe (RTCP PLI).

Sends one message on an open data channel.

Types

candidate()

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

channel_ref()

@type channel_ref() :: reference()

data_type()

@type data_type() :: :string | :binary

description()

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

kind()

@type kind() :: :audio | :video

pc()

@type pc() :: pid()

track_id()

@type track_id() :: term()

Callbacks

add_ice_candidate(pc, candidate)

@callback add_ice_candidate(pc(), candidate()) :: :ok | {:error, term()}

add_track(pc, kind)

@callback add_track(pc(), kind()) :: {:ok, track_id()} | {:error, term()}

close(pc)

@callback close(pc()) :: :ok

create_answer(pc)

@callback create_answer(pc()) :: {:ok, description()} | {:error, term()}

create_data_channel(pc, label, opts)

@callback create_data_channel(pc(), label :: String.t(), opts :: keyword()) ::
  {:ok, channel_ref()} | {:error, term()}

Opens a data channel. Options: :ordered (boolean, default true), :max_retransmits or :max_packet_life_time (ms; neither means reliable), :protocol.

create_offer(pc)

@callback create_offer(pc()) :: {:ok, description()} | {:error, term()}

event(message)

@callback event(message :: term()) :: {:ok, [MobWebrtc.event()]} | :ignore

Turns a message the engine sent its caller into MobWebrtc events, or :ignore.

get_stats(pc)

@callback get_stats(pc()) :: map()

local_description(pc)

@callback local_description(pc()) :: description() | nil

The local description with every local candidate gathered so far in it (RTCPeerConnection.localDescription), or nil before one is set.

request_keyframe(pc, track_id)

@callback request_keyframe(pc(), track_id()) :: :ok

Asks the remote sender of track_id (a receive track) for a keyframe (RTCP PLI).

send_data(pc, channel_ref, binary, data_type)

@callback send_data(pc(), channel_ref(), binary(), data_type()) :: :ok

Sends one message on an open data channel.

send_rtp(pc, track_id, t)

@callback send_rtp(pc(), track_id(), ExRTP.Packet.t()) :: :ok

set_local_description(pc, description)

@callback set_local_description(pc(), description()) :: :ok | {:error, term()}

set_remote_description(pc, description)

@callback set_remote_description(pc(), description()) :: :ok | {:error, term()}

start_link(opts)

@callback start_link(opts :: keyword()) :: {:ok, pc()} | {:error, term()}