-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
97 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
defmodule Mediasoup.TransportListenInfo do | ||
@moduledoc """ | ||
https://mediasoup.org/documentation/v3/mediasoup/api/#TransportListenInfo | ||
""" | ||
|
||
@typedoc "https://mediasoup.org/documentation/v3/mediasoup/api/#TransportListenIp" | ||
@type listen_ip :: %{:ip => String.t(), optional(:announcedIp) => String.t() | nil} | ||
|
||
@typedoc "https://mediasoup.org/documentation/v3/mediasoup/api/#TransportListenInfo" | ||
@type t :: %{ | ||
:ip => String.t(), | ||
:protocol => :tcp | :udp, | ||
optional(:announcedIp) => String.t() | nil, | ||
optional(:port) => integer(), | ||
optional(:sendBufferSize) => integer(), | ||
optional(:recvBufferSize) => integer() | ||
} | ||
|
||
@enforce_keys [:ip, :protocol] | ||
|
||
defstruct [:ip, :protocol, :announcedIp, :port, :sendBufferSize, :recvBufferSize] | ||
|
||
def normalize_listen_ip(ip) when is_binary(ip) do | ||
%{:ip => ip} | ||
end | ||
|
||
def normalize_listen_ip(%{ip: _} = ip) do | ||
ip | ||
end | ||
|
||
def create(ip, protocol) do | ||
listen_ip = normalize_listen_ip(ip) | ||
struct(__MODULE__, Map.merge(listen_ip, %{:protocol => protocol})) | ||
end | ||
|
||
def create(ip, protocol, port) do | ||
listen_ip = normalize_listen_ip(ip) | ||
|
||
struct( | ||
__MODULE__, | ||
Map.merge(listen_ip, %{ | ||
:protocol => protocol, | ||
:port => port | ||
}) | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Mediasoup.TransportListenInfoTest do | ||
use ExUnit.Case | ||
|
||
alias Mediasoup.TransportListenInfo | ||
|
||
test "create" do | ||
assert %Mediasoup.TransportListenInfo{announcedIp: "1.1.1.1", ip: "127.0.0.1", protocol: :udp} == | ||
TransportListenInfo.create( | ||
%{ip: "127.0.0.1", announcedIp: "1.1.1.1"}, | ||
:udp | ||
) | ||
|
||
assert %Mediasoup.TransportListenInfo{ip: "127.0.0.1", protocol: :tcp} == | ||
TransportListenInfo.create("127.0.0.1", :tcp) | ||
end | ||
end |