Skip to content

Commit

Permalink
fix plain transport listen info (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
satoren authored Apr 15, 2024
1 parent a76a878 commit c5fe013
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
13 changes: 9 additions & 4 deletions lib/plain_transport.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Mediasoup.PlainTransport do
@enforce_keys []
defstruct listen_ip: nil,
listen_info: nil,
rtcp_listen_info: nil,
port: nil,
rtcp_mux: nil,
comedia: nil,
Expand All @@ -30,6 +31,7 @@ defmodule Mediasoup.PlainTransport do

@type t :: %Options{
listen_info: TransportListenInfo.t() | nil,
rtcp_listen_info: TransportListenInfo.t() | nil,
# deprecated use listen_info instead
listen_ip: Mediasoup.transport_listen_ip() | nil,
# deprecated use listen_info instead
Expand All @@ -48,6 +50,7 @@ defmodule Mediasoup.PlainTransport do

%Options{
listen_info: map["listenInfo"],
rtcp_listen_info: map["rtcpListenInfo"],
listen_ip: map["listenIp"],
port: map["port"],
rtcp_mux: map["rtcpMux"],
Expand All @@ -62,13 +65,15 @@ defmodule Mediasoup.PlainTransport do

def normalize(%Options{listen_ip: listen_ip, port: port} = option)
when not is_nil(listen_ip) do
listen_info = TransportListenInfo.create(listen_ip, "udp", port)

normalize(%Options{
option
| listen_ip: nil,
port: nil,
listen_info: listen_info
listen_info:
Map.get(option, :listen_info) || TransportListenInfo.create(listen_ip, "udp", port),
rtcp_listen_info:
Map.get(option, :rtcp_listen_info) ||
TransportListenInfo.create(listen_ip, "udp", nil)
})
end

Expand All @@ -90,7 +95,7 @@ defmodule Mediasoup.PlainTransport do
id
end

@spec tuple(t) :: map() | {:error, :terminated}
@spec tuple(t) :: TransportTuple.t() | {:error, :terminated}
@doc """
The transport tuple. If RTCP-mux is enabled (rtcpMux is set), this tuple refers to both RTP and RTCP.
https://mediasoup.org/documentation/v3/mediasoup/api/#plainTransport-tuple
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule MediasoupElixir.MixProject do
use Mix.Project

@version "0.11.0-rc.0"
@version "0.11.0-rc.1"
@repo "https://github.com/oviceinc/mediasoup-elixir"
@description """
Elixir wrapper for mediasoup
Expand Down
2 changes: 1 addition & 1 deletion native/mediasoup_elixir/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions native/mediasoup_elixir/src/plain_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use rustler::{Atom, Env, NifResult, NifStruct, ResourceArc};
#[module = "Mediasoup.PlainTransport.Options"]
pub struct PlainTransportOptionsStruct {
pub listen_info: JsonSerdeWrap<ListenInfo>,
pub rtcp_listen_info: JsonSerdeWrap<Option<ListenInfo>>,
pub rtcp_mux: Option<bool>,
pub comedia: Option<bool>,
pub enable_sctp: Option<bool>,
Expand All @@ -30,6 +31,7 @@ impl PlainTransportOptionsStruct {
pub fn try_to_option(&self) -> Result<PlainTransportOptions, &'static str> {
let mut option = PlainTransportOptions::new(self.listen_info.clone());

option.rtcp_listen_info = self.rtcp_listen_info.clone();
if let Some(rtcp_mux) = self.rtcp_mux {
option.rtcp_mux = rtcp_mux;
}
Expand Down
19 changes: 19 additions & 0 deletions test/integration/test_plain_transport.ex
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,25 @@ defmodule IntegrateTest.PlainTransportTest do
assert {:ok} == PlainTransport.connect(transport, %{ip: "127.0.0.1", port: 4000})
end

def create_with_port(worker) do
{_worker, router} = init(worker)

{:ok, transport} =
Router.create_plain_transport(router, %{
listenIp: %{
ip: "127.0.0.1"
},
port: 9999,
rtcpMux: false,
comedia: true
})

assert match?(
%{local_port: 9999, protocol: :udp, local_address: "127.0.0.1"},
PlainTransport.tuple(transport)
)
end

def close_event(worker) do
{_worker, router} = init(worker)

Expand Down
4 changes: 4 additions & 0 deletions test/plain_transport_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ defmodule MediasoupElixirPlainTransportTest do
IntegrateTest.PlainTransportTest.get_stats_succeeds(worker)
end

test "create_with_port", %{worker: worker} do
IntegrateTest.PlainTransportTest.create_with_port(worker)
end

test "connect_succeeds", %{worker: worker} do
IntegrateTest.PlainTransportTest.connect_succeeds(worker)
end
Expand Down

0 comments on commit c5fe013

Please sign in to comment.