Skip to content

Commit 36c8828

Browse files
authored
Wrap connection state change message into a tuple (#13)
1 parent 99d4e94 commit 36c8828

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ as WebRTC multiplexes traffic on a single socket but PRs are welcomed
2727
```elixir
2828
def deps do
2929
[
30-
{:ex_ice, "~> 0.1.0"}
30+
{:ex_ice, "~> 0.2.0"}
3131
]
3232
end
3333
```

example/peer.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ defmodule Peer do
141141
state
142142
end
143143

144-
def handle_ice_msg(:completed, state) do
144+
def handle_ice_msg({:connection_state_change, :completed}, state) do
145145
Logger.info("ICE: :completed")
146146
Logger.info("Starting sending...")
147147
ref = Process.send_after(self(), :send_ping, 1000)

lib/ice_agent.ex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,23 @@ defmodule ExICE.ICEAgent do
4444
4545
For exact meaning refer to the W3C WebRTC standard, sec 5.6.3.
4646
"""
47-
@type gathering_state_changed() :: {:gathering_state_change, :new | :gathering | :complete}
47+
@type gathering_state_change() :: {:gathering_state_change, :new | :gathering | :complete}
4848

4949
@typedoc """
5050
Emitted when connection state has changed.
5151
5252
For exact meaning refer to the W3C WebRTC standard, sec. 5.6.4.
5353
"""
54-
@type connection_state_changed() :: :checking | :connected | :completed | :failed
54+
@type connection_state_change() ::
55+
{:connection_state_change, :checking | :connected | :completed | :failed}
5556

5657
@typedoc """
5758
Messages sent by the ExICE.
5859
"""
5960
@type signal() ::
6061
{:ex_ice, pid(),
61-
gathering_state_changed()
62-
| connection_state_changed
62+
gathering_state_change()
63+
| connection_state_change()
6364
| {:data, binary()}
6465
| {:new_candidate, binary()}}
6566

@@ -1403,7 +1404,7 @@ defmodule ExICE.ICEAgent do
14031404
@spec change_connection_state(atom(), map()) :: map()
14041405
def change_connection_state(new_conn_state, state) do
14051406
Logger.debug("Connection state change: #{state.state} -> #{new_conn_state}")
1406-
send(state.controlling_process, {:ex_ice, self(), new_conn_state})
1407+
send(state.controlling_process, {:ex_ice, self(), {:connection_state_change, new_conn_state}})
14071408
%{state | state: new_conn_state}
14081409
end
14091410

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
defmodule ExICE.MixProject do
22
use Mix.Project
33

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

77
def project do
88
[
99
app: :ex_ice,
10-
version: "0.1.0",
10+
version: "0.2.0",
1111
elixir: "~> 1.13",
1212
start_permanent: Mix.env() == :prod,
1313
description: "Implementation of trickle ICE protocol",

test/integration/p2p_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ defmodule ExICE.Integration.P2PTest do
131131
ICEAgent.end_of_candidates(agent2)
132132
p2p(agent1, agent2, a1_status, a2_status)
133133

134-
{:ex_ice, ^agent1, :connected} ->
134+
{:ex_ice, ^agent1, {:connection_state_change, :connected}} ->
135135
Logger.info("Connected, sending file...")
136136

137137
Task.start(fn ->
@@ -151,7 +151,7 @@ defmodule ExICE.Integration.P2PTest do
151151
:ok = IO.binwrite(a1_status.fd, data)
152152
p2p(agent1, agent2, a1_status, a2_status)
153153

154-
{:ex_ice, ^agent1, :completed} ->
154+
{:ex_ice, ^agent1, {:connection_state_change, :completed}} ->
155155
Logger.info("Completed")
156156
a1_status = %{a1_status | completed: true}
157157
p2p(agent1, agent2, a1_status, a2_status)
@@ -164,12 +164,12 @@ defmodule ExICE.Integration.P2PTest do
164164
ICEAgent.end_of_candidates(agent1)
165165
p2p(agent1, agent2, a1_status, a2_status)
166166

167-
{:ex_ice, ^agent2, :completed} ->
167+
{:ex_ice, ^agent2, {:connection_state_change, :completed}} ->
168168
Logger.info("Completed")
169169
a2_status = %{a2_status | completed: true}
170170
p2p(agent1, agent2, a1_status, a2_status)
171171

172-
{:ex_ice, ^agent2, :connected} ->
172+
{:ex_ice, ^agent2, {:connection_state_change, :connected}} ->
173173
Logger.info("Connected, sending file...")
174174

175175
Task.start(fn ->

0 commit comments

Comments
 (0)