The Cloudflare Realtime SFU operations Octoroom uses, as a behaviour.
Octoroom.Cloudflare.HTTP calls the real API; tests use an in-memory fake.
config is a map with at least :client (the implementing module); the
HTTP client also needs :app_id and :app_secret.
Summary
Types
One track of a pull: added (with its mid) or refused (with Cloudflare's error code).
A track as Cloudflare reports it in a session: pushed (:local) or pulled
(:remote, with the session it's pulled from).
Callbacks
Closes tracks in a session. With the client's offer (made after stopping
the transceivers) it returns Cloudflare's answer; with nil the close is
forced and no answer comes back.
Creates an empty session (one peer connection).
Pulls remote tracks into a session in one call. Per-track failures (such as
empty_track_error) come back in tracks; the offer covers the tracks that
were added. When renegotiate is true, the client's answer goes to
renegotiate/3.
Publishes local tracks from the client's offer. Returns Cloudflare's answer.
Completes a Cloudflare-initiated renegotiation with the client's answer.
Reads back a session's tracks. {:error, :disconnected} when the
session's peer connection is gone.
Functions
The config from config :octoroom, cloudflare: [...], with the HTTP client by default.
Types
@type mid() :: String.t()
@type pulled() :: %{session_id: session_id(), track_name: String.t(), mid: mid()} | %{session_id: session_id(), track_name: String.t(), error: String.t()}
One track of a pull: added (with its mid) or refused (with Cloudflare's error code).
@type sdp() :: String.t()
@type session_id() :: String.t()
@type session_track() :: %{ location: :local | :remote, track_name: String.t(), mid: mid(), session_id: session_id() | nil, status: :active | :inactive | term() }
A track as Cloudflare reports it in a session: pushed (:local) or pulled
(:remote, with the session it's pulled from).
Callbacks
@callback close_tracks(config(), session_id(), [mid()], offer :: sdp() | nil) :: {:ok, %{sdp: sdp() | nil}} | {:error, term()}
Closes tracks in a session. With the client's offer (made after stopping
the transceivers) it returns Cloudflare's answer; with nil the close is
forced and no answer comes back.
@callback new_session(config()) :: {:ok, session_id()} | {:error, term()}
Creates an empty session (one peer connection).
@callback pull_tracks(config(), session_id(), [ %{session_id: session_id(), track_name: String.t()} ]) :: {:ok, %{sdp: sdp() | nil, renegotiate: boolean(), tracks: [pulled()]}} | {:error, term()}
Pulls remote tracks into a session in one call. Per-track failures (such as
empty_track_error) come back in tracks; the offer covers the tracks that
were added. When renegotiate is true, the client's answer goes to
renegotiate/3.
@callback push_tracks(config(), session_id(), offer :: sdp(), [ %{mid: mid(), track_name: String.t()} ]) :: {:ok, %{sdp: sdp()}} | {:error, term()}
Publishes local tracks from the client's offer. Returns Cloudflare's answer.
@callback renegotiate(config(), session_id(), answer :: sdp()) :: :ok | {:error, term()}
Completes a Cloudflare-initiated renegotiation with the client's answer.
@callback session_state(config(), session_id()) :: {:ok, %{tracks: [session_track()]}} | {:error, :disconnected | term()}
Reads back a session's tracks. {:error, :disconnected} when the
session's peer connection is gone.
Functions
The config from config :octoroom, cloudflare: [...], with the HTTP client by default.