-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document and refactor PeerConnection options (#11)
- Loading branch information
Showing
4 changed files
with
42 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,43 @@ | ||
defmodule ExWebRTC.PeerConnection.Configuration do | ||
@moduledoc false | ||
|
||
@type bundle_policy() :: | ||
:balanced | ||
| :max_compat | ||
| :max_bundle | ||
@moduledoc """ | ||
PeerConnection configuration | ||
""" | ||
|
||
@type ice_server() :: %{ | ||
optional(:credential) => String.t(), | ||
optional(:username) => String.t(), | ||
:urls => [String.t()] | String.t() | ||
} | ||
|
||
# TODO implement | ||
@type certificate() :: :TODO | ||
|
||
@type ice_transport_policy() :: | ||
:all | ||
| :relay | ||
|
||
@type rtcp_mux_policy() :: | ||
:negotiate | ||
| :require | ||
|
||
@type t() :: %__MODULE__{ | ||
bundle_policy: bundle_policy(), | ||
certificates: [certificate()], | ||
ice_candidate_pool_size: non_neg_integer(), | ||
ice_servers: [ice_server()], | ||
ice_transport_policy: ice_transport_policy(), | ||
peer_identity: String.t(), | ||
rtcp_mux_policy: rtcp_mux_policy() | ||
} | ||
|
||
defstruct bundle_policy: :max_bundle, | ||
certificates: nil, | ||
ice_candidate_pool_size: 0, | ||
ice_servers: [], | ||
ice_transport_policy: :all, | ||
peer_identity: nil, | ||
rtcp_mux_policy: :require | ||
@typedoc """ | ||
Options that can be passed to `ExWebRTC.PeerConnection.start_link/1`. | ||
@spec check_support(t()) :: :ok | ||
def check_support(config) do | ||
if config.ice_transport_policy != :all do | ||
raise "#{inspect(config.ice_transport_policy)} ice transport policy is currently not supported" | ||
end | ||
Currently, ExWebRTC always uses the following config: | ||
* bundle_policy - max_bundle | ||
* ice_candidate_pool_size - 0 | ||
* ice_transport_policy - all | ||
* rtcp_mux_policy - require | ||
if config.ice_candidate_pool_size != 0 do | ||
raise "Ice candidate pool size different than 0 (pre-gathering) is currently not supported" | ||
end | ||
This config cannot be changed. | ||
""" | ||
@type options() :: [ice_servers: [ice_server()]] | ||
|
||
if config.bundle_policy != :max_bundle do | ||
raise "Bundle policy options different than :max_bundle are currently not supported" | ||
end | ||
@typedoc false | ||
@type t() :: %__MODULE__{ice_servers: [ice_server()]} | ||
|
||
if config.certificates != nil do | ||
raise "Certificates configuration option is currently not supported" | ||
end | ||
defstruct ice_servers: [] | ||
|
||
if config.peer_identity != nil do | ||
raise "Identify option is currently not supported" | ||
end | ||
@doc false | ||
@spec from_options!(options()) :: t() | ||
def from_options!(options) do | ||
config = struct!(__MODULE__, options) | ||
|
||
if config.rtcp_mux_policy != :require do | ||
raise "RTCP mux policy option :negotiate is currently not supported" | ||
end | ||
# ATM, ExICE does not support relay via TURN | ||
stun_servers = | ||
config.ice_servers | ||
|> Enum.flat_map(&List.wrap(&1.urls)) | ||
|> Enum.filter(&String.starts_with?(&1, "stun:")) | ||
|
||
:ok | ||
%__MODULE__{config | ice_servers: stun_servers} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters