Skip to content

Commit 75a378c

Browse files
authored
Add candidate pairs stats (#203)
1 parent 13e9aae commit 75a378c

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

lib/ex_webrtc/peer_connection.ex

+24
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,23 @@ defmodule ExWebRTC.PeerConnection do
11191119
}
11201120
end
11211121

1122+
to_stats_pair = fn pair, timestamp ->
1123+
%{
1124+
id: pair.id,
1125+
timestamp: timestamp,
1126+
type: :candidate_pair,
1127+
local_candidate_id: pair.local_cand_id,
1128+
remote_candidate_id: pair.remote_cand_id,
1129+
state: pair.state,
1130+
nominated: pair.nominated?,
1131+
requests_received: pair.requests_received,
1132+
requests_sent: pair.requests_sent,
1133+
responses_received: pair.responses_received,
1134+
non_symmetric_responses_received: pair.non_symmetric_responses_received,
1135+
responses_sent: pair.responses_sent
1136+
}
1137+
end
1138+
11221139
local_cands =
11231140
Map.new(ice_stats.local_candidates, fn local_cand ->
11241141
cand = to_stats_candidate.(local_cand, :local_candidate, timestamp)
@@ -1131,6 +1148,12 @@ defmodule ExWebRTC.PeerConnection do
11311148
{cand.id, cand}
11321149
end)
11331150

1151+
candidate_pairs =
1152+
Map.new(ice_stats.candidate_pairs, fn pair ->
1153+
pair = to_stats_pair.(pair, timestamp)
1154+
{pair.id, pair}
1155+
end)
1156+
11341157
rtp_stats =
11351158
state.transceivers
11361159
|> Enum.flat_map(&RTPTransceiver.get_stats(&1, timestamp))
@@ -1179,6 +1202,7 @@ defmodule ExWebRTC.PeerConnection do
11791202
stats
11801203
|> Map.merge(local_cands)
11811204
|> Map.merge(remote_cands)
1205+
|> Map.merge(candidate_pairs)
11821206
|> Map.merge(rtp_stats)
11831207
|> Map.merge(data_channel_stats)
11841208

mix.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ defmodule ExWebRTC.MixProject do
5757
defp deps do
5858
[
5959
{:ex_sdp, "~> 1.0"},
60-
{:ex_ice, "~> 0.9.0"},
60+
# {:ex_ice, "~> 0.9.0"},
61+
{:ex_ice, github: "elixir-webrtc/ex_ice"},
6162
{:ex_dtls, "~> 0.16.0"},
6263
{:ex_libsrtp, "~> 0.7.1"},
6364
{:ex_rtp, "~> 0.4.0"},

mix.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
1313
"ex_doc": {:hex, :ex_doc, "0.37.0", "970f92b39e62c460aa8a367508e938f5e4da6e2ff3eaed3f8530b25870f45471", [:mix], [{:earmark_parser, "~> 1.4.42", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "b0ee7f17373948e0cf471e59c3a0ee42f3bd1171c67d91eb3626456ef9c6202c"},
1414
"ex_dtls": {:hex, :ex_dtls, "0.16.0", "3ae38025ccc77f6db573e2e391602fa9bbc02253c137d8d2d59469a66cbe806b", [:mix], [{:bundlex, "~> 1.5.3", [hex: :bundlex, repo: "hexpm", optional: false]}, {:unifex, "~> 1.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "2a4e30d74c6ddf95cc5b796423293c06a0da295454c3823819808ff031b4b361"},
15-
"ex_ice": {:hex, :ex_ice, "0.9.3", "46700963acaba72737032500b6ee298a4effa7ad7189ab48887be5e9f4fe2107", [:mix], [{:elixir_uuid, "~> 1.0", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:ex_stun, "~> 0.2.0", [hex: :ex_stun, repo: "hexpm", optional: false]}, {:ex_turn, "~> 0.2.0", [hex: :ex_turn, repo: "hexpm", optional: false]}], "hexpm", "4fd98d20a39ab70a62dd301c44e87437d479292c528ec7f21522ebfe0654b9cb"},
15+
"ex_ice": {:git, "https://github.com/elixir-webrtc/ex_ice.git", "41f5c8aa8d9446f5833449f23ed22cd598da6fb7", []},
1616
"ex_libsrtp": {:hex, :ex_libsrtp, "0.7.2", "211bd89c08026943ce71f3e2c0231795b99cee748808ed3ae7b97cd8d2450b6b", [:mix], [{:bunch, "~> 1.6", [hex: :bunch, repo: "hexpm", optional: false]}, {:bundlex, "~> 1.3", [hex: :bundlex, repo: "hexpm", optional: false]}, {:membrane_precompiled_dependency_provider, "~> 0.1.0", [hex: :membrane_precompiled_dependency_provider, repo: "hexpm", optional: false]}, {:unifex, "~> 1.1", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "2e20645d0d739a4ecdcf8d4810a0c198120c8a2f617f2b75b2e2e704d59f492a"},
1717
"ex_rtcp": {:hex, :ex_rtcp, "0.4.0", "f9e515462a9581798ff6413583a25174cfd2101c94a2ebee871cca7639886f0a", [:mix], [], "hexpm", "28956602cf210d692fcdaf3f60ca49681634e1deb28ace41246aee61ee22dc3b"},
1818
"ex_rtp": {:hex, :ex_rtp, "0.4.0", "1f1b5c1440a904706011e3afbb41741f5da309ce251cb986690ce9fd82636658", [:mix], [], "hexpm", "0f72d80d5953a62057270040f0f1ee6f955c08eeae82ac659c038001d7d5a790"},

test/ex_webrtc/peer_connection_test.exs

+3
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,7 @@ defmodule ExWebRTC.PeerConnectionTest do
979979
assert Map.get(groups, :outbound_rtp) == nil
980980
assert Map.get(groups, :local_candidate) == nil
981981
assert Map.get(groups, :remote_candidate) == nil
982+
assert Map.get(groups, :candidate_pair) == nil
982983

983984
# negotiate tracks
984985
{:ok, pc2} = PeerConnection.start_link()
@@ -1025,6 +1026,7 @@ defmodule ExWebRTC.PeerConnectionTest do
10251026
assert length(Map.get(groups, :outbound_rtp, [])) == 1
10261027
assert length(Map.get(groups, :local_candidate, [])) > 0
10271028
assert length(Map.get(groups, :remote_candidate, [])) > 0
1029+
assert length(Map.get(groups, :candidate_pair, [])) > 0
10281030

10291031
assert %{
10301032
peer_connection: %{
@@ -1056,6 +1058,7 @@ defmodule ExWebRTC.PeerConnectionTest do
10561058
assert length(Map.get(groups, :outbound_rtp, [])) == 1
10571059
assert length(Map.get(groups, :local_candidate, [])) > 0
10581060
assert length(Map.get(groups, :remote_candidate, [])) > 0
1061+
assert length(Map.get(groups, :candidate_pair, [])) > 0
10591062
end
10601063

10611064
test "close/1" do

0 commit comments

Comments
 (0)