Skip to content

Commit fdbe0e2

Browse files
authored
Pair newly gathered host candidates with existing remote candidates (#67)
1 parent c4bef11 commit fdbe0e2

File tree

4 files changed

+90
-69
lines changed

4 files changed

+90
-69
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ as WebRTC multiplexes traffic on a single socket but PRs are welcomed
3030
```elixir
3131
def deps do
3232
[
33-
{:ex_ice, "~> 0.9.2"}
33+
{:ex_ice, "~> 0.9.3"}
3434
]
3535
end
3636
```

lib/ex_ice/priv/ice_agent.ex

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ defmodule ExICE.Priv.ICEAgent do
285285
{:ok, sockets} = Gatherer.open_sockets(ice_agent.gatherer)
286286
host_cands = Gatherer.gather_host_candidates(ice_agent.gatherer, sockets)
287287

288+
ice_agent =
289+
Enum.reduce(host_cands, ice_agent, fn host_cand, ice_agent ->
290+
add_local_cand(ice_agent, host_cand)
291+
end)
292+
288293
for %cand_mod{} = cand <- host_cands do
289294
notify(ice_agent.on_new_candidate, {:new_candidate, cand_mod.marshal(cand)})
290295
end
@@ -297,12 +302,9 @@ defmodule ExICE.Priv.ICEAgent do
297302

298303
gathering_transactions = Map.merge(srflx_gathering_transactions, relay_gathering_transactions)
299304

300-
local_cands = Map.new(host_cands, fn cand -> {cand.base.id, cand} end)
301-
302305
%{
303306
ice_agent
304307
| sockets: sockets,
305-
local_cands: local_cands,
306308
gathering_transactions: gathering_transactions
307309
}
308310
|> update_gathering_state()
@@ -787,7 +789,7 @@ defmodule ExICE.Priv.ICEAgent do
787789
Logger.debug("""
788790
Couldn't find #{type} candidate for:
789791
socket: #{inspect(socket)}
790-
src address: #{inspect({src_ip, src_port})}.
792+
src address: #{inspect({src_ip, src_port})}.
791793
And this is not a STUN message. Ignoring.
792794
""")
793795

@@ -1091,7 +1093,7 @@ defmodule ExICE.Priv.ICEAgent do
10911093
{:new_candidate, Candidate.Relay.marshal(relay_cand)}
10921094
)
10931095

1094-
add_relay_cand(ice_agent, relay_cand)
1096+
add_local_cand(ice_agent, relay_cand)
10951097

10961098
{:send, turn_addr, data, client} ->
10971099
tr = %{tr | client: client}
@@ -1186,17 +1188,17 @@ defmodule ExICE.Priv.ICEAgent do
11861188
}
11871189
end
11881190

1189-
defp add_relay_cand(ice_agent, relay_cand) do
1190-
ice_agent = put_in(ice_agent.local_cands[relay_cand.base.id], relay_cand)
1191+
defp add_local_cand(ice_agent, local_cand) do
1192+
ice_agent = put_in(ice_agent.local_cands[local_cand.base.id], local_cand)
11911193

1192-
remote_cands = get_matching_candidates_local(Map.values(ice_agent.remote_cands), relay_cand)
1194+
remote_cands = get_matching_candidates_local(Map.values(ice_agent.remote_cands), local_cand)
11931195

11941196
checklist_foundations = get_foundations(ice_agent)
11951197

11961198
new_pairs =
11971199
for remote_cand <- remote_cands, into: %{} do
1198-
pair_state = get_pair_state(relay_cand, remote_cand, checklist_foundations)
1199-
pair = CandidatePair.new(relay_cand, remote_cand, ice_agent.role, pair_state)
1200+
pair_state = get_pair_state(local_cand, remote_cand, checklist_foundations)
1201+
pair = CandidatePair.new(local_cand, remote_cand, ice_agent.role, pair_state)
12001202
{pair.id, pair}
12011203
end
12021204

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule ExICE.MixProject do
22
use Mix.Project
33

4-
@version "0.9.2"
4+
@version "0.9.3"
55
@source_url "https://github.com/elixir-webrtc/ex_ice"
66

77
def project do

0 commit comments

Comments
 (0)