Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion lib/ex_ice/ice_agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule ExICE.ICEAgent do
gathering_state_change()
| connection_state_change()
| {:data, binary()}
| {:new_candidate, binary()}}
| {:new_candidate, String.t()}}

@typedoc """
ICE Agent configuration options.
Expand Down Expand Up @@ -119,6 +119,25 @@ defmodule ExICE.ICEAgent do
GenServer.call(ice_agent, :get_local_credentials)
end

@doc """
Gets all local candidates that have already been gathered.
"""
@spec get_local_candidates(pid()) :: [String.t()]
def get_local_candidates(ice_agent) do
GenServer.call(ice_agent, :get_local_candidates)
end

@doc """
Gets all remote candidates.

This includes candidates supplied by `add_remote_candidate/2` and candidates
discovered during ICE connection establishment process (so called `prflx` candidates).
"""
@spec get_remote_candidates(pid()) :: [String.t()]
def get_remote_candidates(ice_agent) do
GenServer.call(ice_agent, :get_remote_candidates)
end

@doc """
Sets remote credentials.

Expand Down Expand Up @@ -256,6 +275,18 @@ defmodule ExICE.ICEAgent do
{:reply, {:ok, local_ufrag, local_pwd}, state}
end

@impl true
def handle_call(:get_local_candidates, _from, state) do
candidates = ICEAgent.Impl.get_local_candidates(state.ice_agent)
{:reply, candidates, state}
end

@impl true
def handle_call(:get_remote_candidates, _from, state) do
candidates = ICEAgent.Impl.get_remote_candidates(state.ice_agent)
{:reply, candidates, state}
end

@impl true
def handle_call(:get_stats, _from, state) do
stats = ICEAgent.Impl.get_stats(state.ice_agent)
Expand Down
10 changes: 10 additions & 0 deletions lib/ex_ice/ice_agent/impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ defmodule ExICE.ICEAgent.Impl do
{ice_agent.local_ufrag, ice_agent.local_pwd}
end

@spec get_local_candidates(t()) :: [binary()]
def get_local_candidates(ice_agent) do
Enum.map(ice_agent.local_cands, &Candidate.marshal/1)
end

@spec get_remote_candidates(t()) :: [binary()]
def get_remote_candidates(ice_agent) do
Enum.map(ice_agent.remote_cands, &Candidate.marshal/1)
end

@spec get_stats(t()) :: map()
def get_stats(ice_agent) do
%{
Expand Down