Skip to content

Wrap connection state change message into a tuple #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2023
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ as WebRTC multiplexes traffic on a single socket but PRs are welcomed
```elixir
def deps do
[
{:ex_ice, "~> 0.1.0"}
{:ex_ice, "~> 0.2.0"}
]
end
```
Expand Down
2 changes: 1 addition & 1 deletion example/peer.exs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ defmodule Peer do
state
end

def handle_ice_msg(:completed, state) do
def handle_ice_msg({:connection_state_change, :completed}, state) do
Logger.info("ICE: :completed")
Logger.info("Starting sending...")
ref = Process.send_after(self(), :send_ping, 1000)
Expand Down
11 changes: 6 additions & 5 deletions lib/ice_agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,23 @@ defmodule ExICE.ICEAgent do

For exact meaning refer to the W3C WebRTC standard, sec 5.6.3.
"""
@type gathering_state_changed() :: {:gathering_state_change, :new | :gathering | :complete}
@type gathering_state_change() :: {:gathering_state_change, :new | :gathering | :complete}

@typedoc """
Emitted when connection state has changed.

For exact meaning refer to the W3C WebRTC standard, sec. 5.6.4.
"""
@type connection_state_changed() :: :checking | :connected | :completed | :failed
@type connection_state_change() ::
{:connection_state_change, :checking | :connected | :completed | :failed}

@typedoc """
Messages sent by the ExICE.
"""
@type signal() ::
{:ex_ice, pid(),
gathering_state_changed()
| connection_state_changed
gathering_state_change()
| connection_state_change()
| {:data, binary()}
| {:new_candidate, binary()}}

Expand Down Expand Up @@ -1403,7 +1404,7 @@ defmodule ExICE.ICEAgent do
@spec change_connection_state(atom(), map()) :: map()
def change_connection_state(new_conn_state, state) do
Logger.debug("Connection state change: #{state.state} -> #{new_conn_state}")
send(state.controlling_process, {:ex_ice, self(), new_conn_state})
send(state.controlling_process, {:ex_ice, self(), {:connection_state_change, new_conn_state}})
%{state | state: new_conn_state}
end

Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
defmodule ExICE.MixProject do
use Mix.Project

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

def project do
[
app: :ex_ice,
version: "0.1.0",
version: "0.2.0",
elixir: "~> 1.13",
start_permanent: Mix.env() == :prod,
description: "Implementation of trickle ICE protocol",
Expand Down
8 changes: 4 additions & 4 deletions test/integration/p2p_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule ExICE.Integration.P2PTest do
ICEAgent.end_of_candidates(agent2)
p2p(agent1, agent2, a1_status, a2_status)

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

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

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

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

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

Task.start(fn ->
Expand Down