Skip to content

Commit 5de51fe

Browse files
committed
Fix expose_internal_ip in listen_info
1 parent c20719a commit 5de51fe

File tree

9 files changed

+75
-54
lines changed

9 files changed

+75
-54
lines changed

lib/pipe_transport.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ defmodule Mediasoup.PipeTransport do
5252
}
5353
def normalize(%Options{listen_ip: listen_ip, port: port} = option)
5454
when not is_nil(listen_ip) do
55-
listen_info = TransportListenInfo.create(listen_ip, "udp", port)
55+
listen_info = TransportListenInfo.create(listen_ip, "udp", false, port)
5656

5757
normalize(%Options{
5858
option

lib/plain_transport.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ defmodule Mediasoup.PlainTransport do
7979
| listen_ip: nil,
8080
port: nil,
8181
listen_info:
82-
Map.get(option, :listen_info) || TransportListenInfo.create(listen_ip, "udp", port),
82+
Map.get(option, :listen_info) ||
83+
TransportListenInfo.create(listen_ip, "udp", false, port),
8384
rtcp_listen_info:
8485
Map.get(option, :rtcp_listen_info) ||
85-
TransportListenInfo.create(listen_ip, "udp", nil)
86+
TransportListenInfo.create(listen_ip, "udp", false, nil)
8687
})
8788
end
8889

lib/transport_listen_info.ex

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,27 @@ defmodule Mediasoup.TransportListenInfo do
1111
:ip => String.t(),
1212
:protocol => :tcp | :udp,
1313
optional(:announcedAddress) => String.t() | nil,
14+
optional(:exposeInternalIp) => boolean(),
1415
optional(:port) => integer(),
16+
optional(:portRange) => map(),
17+
optional(:flags) => map(),
1518
optional(:sendBufferSize) => integer(),
1619
optional(:recvBufferSize) => integer()
1720
}
1821

1922
@enforce_keys [:ip, :protocol]
2023

21-
defstruct [:ip, :protocol, :announcedAddress, :port, :sendBufferSize, :recvBufferSize]
24+
defstruct [
25+
:ip,
26+
:protocol,
27+
:announcedAddress,
28+
:exposeInternalIp,
29+
:port,
30+
:portRange,
31+
:flags,
32+
:sendBufferSize,
33+
:recvBufferSize
34+
]
2235

2336
def normalize_listen_ip(ip) when is_binary(ip) do
2437
%{:ip => ip}
@@ -40,20 +53,25 @@ defmodule Mediasoup.TransportListenInfo do
4053
info
4154
end
4255

43-
@spec create(binary() | %{:ip => any(), optional(any()) => any()}, any()) :: struct()
44-
def create(ip, protocol) do
56+
@spec create(binary() | %{:ip => any(), optional(any()) => any()}, any(), boolean()) :: struct()
57+
def create(ip, protocol, expose) do
4558
listen_ip = normalize_listen_ip(ip)
46-
struct(__MODULE__, Map.merge(listen_ip, %{:protocol => protocol}))
59+
60+
struct(
61+
__MODULE__,
62+
Map.merge(listen_ip, %{:protocol => protocol, :exposeInternalIp => expose})
63+
)
4764
end
4865

49-
def create(ip, protocol, port) do
66+
def create(ip, protocol, expose, port) do
5067
listen_ip = normalize_listen_ip(ip)
5168

5269
struct(
5370
__MODULE__,
5471
Map.merge(listen_ip, %{
5572
:protocol => protocol,
56-
:port => port
73+
:port => port,
74+
:exposeInternalIp => expose
5775
})
5876
)
5977
end

lib/webrtc_transport.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ defmodule Mediasoup.WebRtcTransport do
135135
protocol: protocol,
136136
ip: listen_ip.ip,
137137
announcedAddress: listen_ip[:announcedAddress],
138-
port: port
138+
port: port,
139+
exposeInternalIp: listen_ip[:exposeInternalIp] || false
139140
}
140141
end)
141142
end)

test/integration/test_pipe_transport.ex

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,6 @@ defmodule IntegrateTest.PipeTransportTest do
402402
] === pipe_consumer.rtp_parameters["codecs"]
403403

404404
assert [
405-
%{
406-
"encrypt" => false,
407-
"id" => 6,
408-
"uri" => "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07"
409-
},
410-
%{"encrypt" => false, "id" => 7, "uri" => "urn:ietf:params:rtp-hdrext:framemarking"},
411405
%{"encrypt" => false, "id" => 11, "uri" => "urn:3gpp:video-orientation"},
412406
%{"encrypt" => false, "id" => 12, "uri" => "urn:ietf:params:rtp-hdrext:toffset"},
413407
%{
@@ -451,12 +445,6 @@ defmodule IntegrateTest.PipeTransportTest do
451445
] === pipe_producer.rtp_parameters["codecs"]
452446

453447
assert [
454-
%{
455-
"encrypt" => false,
456-
"id" => 6,
457-
"uri" => "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07"
458-
},
459-
%{"encrypt" => false, "id" => 7, "uri" => "urn:ietf:params:rtp-hdrext:framemarking"},
460448
%{"encrypt" => false, "id" => 11, "uri" => "urn:3gpp:video-orientation"},
461449
%{"encrypt" => false, "id" => 12, "uri" => "urn:ietf:params:rtp-hdrext:toffset"},
462450
%{
@@ -565,16 +553,6 @@ defmodule IntegrateTest.PipeTransportTest do
565553
] === pipe_consumer.rtp_parameters["codecs"]
566554

567555
assert [
568-
%{
569-
"encrypt" => false,
570-
"id" => 6,
571-
"uri" => "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07"
572-
},
573-
%{
574-
"encrypt" => false,
575-
"id" => 7,
576-
"uri" => "urn:ietf:params:rtp-hdrext:framemarking"
577-
},
578556
%{"encrypt" => false, "id" => 11, "uri" => "urn:3gpp:video-orientation"},
579557
%{"encrypt" => false, "id" => 12, "uri" => "urn:ietf:params:rtp-hdrext:toffset"},
580558
%{

test/integration/test_plain_transport.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ defmodule IntegrateTest.PlainTransportTest do
217217
{_worker, router} = init(worker)
218218

219219
{:ok, transport} =
220-
Router.create_plain_transport(router, %{listenIp: %{ip: "127.0.0.1"}, comedia: false})
220+
Router.create_plain_transport(router, %{
221+
listenIp: %{ip: "127.0.0.1"},
222+
comedia: false
223+
})
221224

222225
assert transport.id == PlainTransport.id(transport)
223226

test/integration/test_webrtc_server.ex

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,29 @@ defmodule IntegrateTest.WebRtcServerTest do
6060
ip: "127.0.0.1",
6161
announcedIp: "9.9.9.1",
6262
port: 10111,
63-
protocol: :tcp
63+
protocol: :tcp,
64+
exposeInternalIp: false
6465
},
6566
%{
6667
ip: "0.0.0.0",
6768
announcedIp: "9.9.9.2",
6869
port: 10112,
69-
protocol: :tcp
70+
protocol: :tcp,
71+
exposeInternalIp: false
7072
},
7173
%{
7274
ip: "127.0.0.1",
7375
announcedIp: "9.9.9.1",
7476
port: 10111,
75-
protocol: :udp
77+
protocol: :udp,
78+
exposeInternalIp: false
7679
},
7780
%{
7881
ip: "0.0.0.0",
7982
announcedIp: "9.9.9.2",
8083
port: 10112,
81-
protocol: :udp
84+
protocol: :udp,
85+
exposeInternalIp: false
8286
}
8387
]
8488
})
@@ -147,25 +151,29 @@ defmodule IntegrateTest.WebRtcServerTest do
147151
ip: "127.0.0.1",
148152
announcedIp: "9.9.9.1",
149153
port: 10111,
150-
protocol: :tcp
154+
protocol: :tcp,
155+
exposeInternalIp: false
151156
},
152157
%{
153158
ip: "0.0.0.0",
154159
announcedIp: "9.9.9.2",
155160
port: 10112,
156-
protocol: :tcp
161+
protocol: :tcp,
162+
exposeInternalIp: false
157163
},
158164
%{
159165
ip: "127.0.0.1",
160166
announcedIp: "9.9.9.1",
161167
port: 10111,
162-
protocol: :udp
168+
protocol: :udp,
169+
exposeInternalIp: false
163170
},
164171
%{
165172
ip: "0.0.0.0",
166173
announcedIp: "9.9.9.2",
167174
port: 10112,
168-
protocol: :udp
175+
protocol: :udp,
176+
exposeInternalIp: false
169177
}
170178
]
171179
})
@@ -184,12 +192,14 @@ defmodule IntegrateTest.WebRtcServerTest do
184192
%{
185193
ip: "127.0.0.1",
186194
announcedIp: "9.9.9.1",
187-
protocol: :udp
195+
protocol: :udp,
196+
exposeInternalIp: false
188197
},
189198
%{
190199
ip: "127.0.0.1",
191200
announcedIp: "9.9.9.2",
192-
protocol: :tcp
201+
protocol: :tcp,
202+
exposeInternalIp: false
193203
}
194204
]
195205
})
@@ -217,7 +227,8 @@ defmodule IntegrateTest.WebRtcServerTest do
217227
listen_infos: [
218228
%{
219229
ip: "1.2.3.4",
220-
protocol: :udp
230+
protocol: :udp,
231+
exposeInternalIp: false
221232
}
222233
]
223234
})
@@ -229,12 +240,14 @@ defmodule IntegrateTest.WebRtcServerTest do
229240
%{
230241
ip: "127.0.0.1",
231242
protocol: :udp,
232-
port: 10111
243+
port: 10111,
244+
exposeInternalIp: false
233245
},
234246
%{
235247
ip: "127.0.0.1",
236248
protocol: :udp,
237-
port: 10111
249+
port: 10111,
250+
exposeInternalIp: false
238251
}
239252
]
240253
})
@@ -246,7 +259,8 @@ defmodule IntegrateTest.WebRtcServerTest do
246259
%{
247260
ip: "127.0.0.1",
248261
protocol: :udp,
249-
port: 12348
262+
port: 12348,
263+
exposeInternalIp: false
250264
}
251265
]
252266
})
@@ -257,7 +271,8 @@ defmodule IntegrateTest.WebRtcServerTest do
257271
%{
258272
ip: "127.0.0.1",
259273
protocol: :udp,
260-
port: 12348
274+
port: 12348,
275+
exposeInternalIp: false
261276
}
262277
]
263278
})

test/integration/test_webrtc_transport.ex

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,25 +459,29 @@ defmodule IntegrateTest.WebRtcTransportTest do
459459
ip: "127.0.0.1",
460460
announcedIp: "9.9.9.1",
461461
port: 10111,
462-
protocol: :tcp
462+
protocol: :tcp,
463+
exposeInternalIp: false
463464
},
464465
%{
465466
ip: "0.0.0.0",
466467
announcedIp: "9.9.9.2",
467468
port: 10112,
468-
protocol: :tcp
469+
protocol: :tcp,
470+
exposeInternalIp: false
469471
},
470472
%{
471473
ip: "127.0.0.1",
472474
announcedIp: "9.9.9.1",
473475
port: 10111,
474-
protocol: :udp
476+
protocol: :udp,
477+
exposeInternalIp: false
475478
},
476479
%{
477480
ip: "0.0.0.0",
478481
announcedIp: "9.9.9.2",
479482
port: 10112,
480-
protocol: :udp
483+
protocol: :udp,
484+
exposeInternalIp: false
481485
}
482486
]
483487
})

test/transport_listen_info_test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ defmodule Mediasoup.TransportListenInfoTest do
1111
} ==
1212
TransportListenInfo.create(
1313
%{ip: "127.0.0.1", announcedAddress: "1.1.1.1"},
14-
:udp
14+
:udp,
15+
false
1516
)
1617

1718
assert %Mediasoup.TransportListenInfo{ip: "127.0.0.1", protocol: :tcp} ==
18-
TransportListenInfo.create("127.0.0.1", :tcp)
19+
TransportListenInfo.create("127.0.0.1", :tcp, false)
1920
end
2021
end

0 commit comments

Comments
 (0)