Skip to content

Commit dba5345

Browse files
committed
Add host_to_srflx_ip_mapper
1 parent 83c99c8 commit dba5345

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

lib/ex_webrtc/peer_connection.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ defmodule ExWebRTC.PeerConnection do
612612
ice_transport_policy: config.ice_transport_policy,
613613
ip_filter: config.ice_ip_filter,
614614
aggressive_nomination: config.ice_aggressive_nomination,
615+
host_to_srflx_ip_mapper: config.host_to_srflx_ip_mapper,
615616
ports: config.ice_port_range,
616617
on_data: nil
617618
]

lib/ex_webrtc/peer_connection/configuration.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ defmodule ExWebRTC.PeerConnection.Configuration do
164164
at the very end of the whole connection establishment process. To mitigate this issue, you can eitehr add an empty
165165
ICE candidate (this will indicate that there won't be further remote candidates and once all connectivity checks pass,
166166
ICE will nominate the pair), or use aggressive nomination. Defaults to false.
167+
* `host_to_srflx_ip_mapper` - function called for each host candidate to derive a new "fabricated" srflx candidate from it.
168+
This function takes host's ip as an argument and should return srflx's ip as a result or nil if for given host candidate
169+
there should be no srflx one.
170+
171+
Note that each returned IP address must be unique.
172+
If the mapping function repeatedly returns the same address,
173+
it will be ignored, and only one server reflexive candidate will be created.
174+
175+
This function is meant to be used for server implementations where the public addresses are well known.
176+
NAT uses 1 to 1 port mapping and using STUN server for discovering public IP is undesirable
177+
(e.g. because of unknown response time).
167178
* `audio_codecs` and `video_codecs` - lists of audio and video codecs to negotiate. By default these are equal to
168179
`default_audio_codecs/0` and `default_video_codecs/0`. To extend the list with your own codecs, do
169180
`audio_codecs: Configuration.default_audio_codecs() ++ my_codecs`.
@@ -189,6 +200,7 @@ defmodule ExWebRTC.PeerConnection.Configuration do
189200
ice_ip_filter: ICEAgent.ip_filter(),
190201
ice_port_range: Enumerable.t(non_neg_integer()),
191202
ice_aggressive_nomination: boolean(),
203+
host_to_srflx_ip_mapper: ICEAgent.host_to_srflx_ip_mapper(),
192204
audio_codecs: [RTPCodecParameters.t()] | [audio_codec_name()],
193205
video_codecs: [RTPCodecParameters.t()] | [video_codec_name()],
194206
features: [feature()],
@@ -209,6 +221,7 @@ defmodule ExWebRTC.PeerConnection.Configuration do
209221
ice_ip_filter: (:inet.ip_address() -> boolean()) | nil,
210222
ice_port_range: Enumerable.t(non_neg_integer()),
211223
ice_aggressive_nomination: boolean(),
224+
host_to_srflx_ip_mapper: ICEAgent.host_to_srflx_ip_mapper() | nil,
212225
audio_codecs: [RTPCodecParameters.t()],
213226
video_codecs: [RTPCodecParameters.t()],
214227
audio_extensions: [Extmap.t()],
@@ -228,6 +241,7 @@ defmodule ExWebRTC.PeerConnection.Configuration do
228241
ice_transport_policy: :all,
229242
ice_port_range: [0],
230243
ice_aggressive_nomination: false,
244+
host_to_srflx_ip_mapper: nil,
231245
audio_codecs: @default_audio_codecs,
232246
video_codecs: @default_video_codecs,
233247
features: @default_features

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ defmodule ExWebRTC.MixProject do
5757
defp deps do
5858
[
5959
{:ex_sdp, "~> 1.0"},
60-
{:ex_ice, "~> 0.13.0"},
60+
{:ex_ice, github: "elixir-webrtc/ex_ice", ref: "a4f930b19a1e92c5bbaf64e24e0035942f6ff280"},
6161
{:ex_dtls, "~> 0.18.0"},
6262
{:ex_libsrtp, "~> 0.7.1"},
6363
{:ex_rtp, "~> 0.4.0"},

mix.lock

Lines changed: 1 addition & 1 deletion
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.38.2", "504d25eef296b4dec3b8e33e810bc8b5344d565998cd83914ffe1b8503737c02", [:mix], [{:earmark_parser, "~> 1.4.44", [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", "732f2d972e42c116a70802f9898c51b54916e542cc50968ac6980512ec90f42b"},
1414
"ex_dtls": {:hex, :ex_dtls, "0.18.0", "0815e3384bb0c1e6c06559012479cf9a94a501ddf46c3df54dc2d1b169e29d5c", [:mix], [{:bundlex, "~> 1.5.3", [hex: :bundlex, repo: "hexpm", optional: false]}, {:unifex, "~> 1.0", [hex: :unifex, repo: "hexpm", optional: false]}], "hexpm", "562eda1815eeaed8360b2b5c34d4db5b453794bc096404a4c64f193fa7b18bf2"},
15-
"ex_ice": {:hex, :ex_ice, "0.13.0", "13a6ae106b26bb5f2957a586bf20d4031299e5b968533828e637bb4ac7645d31", [: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", "0d65afa15e36b5610d0f51e72e4c25b22346caa9a6d7d2f6f1cfd8db94bd494e"},
15+
"ex_ice": {:git, "https://github.com/elixir-webrtc/ex_ice.git", "a4f930b19a1e92c5bbaf64e24e0035942f6ff280", [ref: "a4f930b19a1e92c5bbaf64e24e0035942f6ff280"]},
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"},

0 commit comments

Comments
 (0)