Skip to content

Commit 3d98186

Browse files
authored
Add functions to obtain ICE candidates (#26)
1 parent 49b87c3 commit 3d98186

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/ex_ice/ice_agent.ex

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule ExICE.ICEAgent do
4040
gathering_state_change()
4141
| connection_state_change()
4242
| {:data, binary()}
43-
| {:new_candidate, binary()}}
43+
| {:new_candidate, String.t()}}
4444

4545
@typedoc """
4646
ICE Agent configuration options.
@@ -119,6 +119,25 @@ defmodule ExICE.ICEAgent do
119119
GenServer.call(ice_agent, :get_local_credentials)
120120
end
121121

122+
@doc """
123+
Gets all local candidates that have already been gathered.
124+
"""
125+
@spec get_local_candidates(pid()) :: [String.t()]
126+
def get_local_candidates(ice_agent) do
127+
GenServer.call(ice_agent, :get_local_candidates)
128+
end
129+
130+
@doc """
131+
Gets all remote candidates.
132+
133+
This includes candidates supplied by `add_remote_candidate/2` and candidates
134+
discovered during ICE connection establishment process (so called `prflx` candidates).
135+
"""
136+
@spec get_remote_candidates(pid()) :: [String.t()]
137+
def get_remote_candidates(ice_agent) do
138+
GenServer.call(ice_agent, :get_remote_candidates)
139+
end
140+
122141
@doc """
123142
Sets remote credentials.
124143
@@ -256,6 +275,18 @@ defmodule ExICE.ICEAgent do
256275
{:reply, {:ok, local_ufrag, local_pwd}, state}
257276
end
258277

278+
@impl true
279+
def handle_call(:get_local_candidates, _from, state) do
280+
candidates = ICEAgent.Impl.get_local_candidates(state.ice_agent)
281+
{:reply, candidates, state}
282+
end
283+
284+
@impl true
285+
def handle_call(:get_remote_candidates, _from, state) do
286+
candidates = ICEAgent.Impl.get_remote_candidates(state.ice_agent)
287+
{:reply, candidates, state}
288+
end
289+
259290
@impl true
260291
def handle_call(:get_stats, _from, state) do
261292
stats = ICEAgent.Impl.get_stats(state.ice_agent)

lib/ex_ice/ice_agent/impl.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ defmodule ExICE.ICEAgent.Impl do
127127
{ice_agent.local_ufrag, ice_agent.local_pwd}
128128
end
129129

130+
@spec get_local_candidates(t()) :: [binary()]
131+
def get_local_candidates(ice_agent) do
132+
Enum.map(ice_agent.local_cands, &Candidate.marshal/1)
133+
end
134+
135+
@spec get_remote_candidates(t()) :: [binary()]
136+
def get_remote_candidates(ice_agent) do
137+
Enum.map(ice_agent.remote_cands, &Candidate.marshal/1)
138+
end
139+
130140
@spec get_stats(t()) :: map()
131141
def get_stats(ice_agent) do
132142
%{

0 commit comments

Comments
 (0)