Unverified 提交 ba2811d0 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Add localIP option for RtpStreamer and RTP mirroring (fixes #198) (#199)

上级 df2d5dd1
...@@ -299,13 +299,15 @@ class Room extends EnhancedEventEmitter ...@@ -299,13 +299,15 @@ class Room extends EnhancedEventEmitter
return rtpStreamer; return rtpStreamer;
}) })
.catch(() => .catch((error) =>
{ {
if (plainRtpTransport) if (plainRtpTransport)
plainRtpTransport.close(); plainRtpTransport.close();
if (consumer) if (consumer)
consumer.close(); consumer.close();
throw error;
}); });
} }
......
...@@ -16,6 +16,7 @@ namespace RTC ...@@ -16,6 +16,7 @@ namespace RTC
{ {
std::string remoteIP; std::string remoteIP;
uint16_t remotePort; uint16_t remotePort;
std::string localIP;
}; };
public: public:
......
...@@ -59,6 +59,7 @@ namespace RTC ...@@ -59,6 +59,7 @@ namespace RTC
{ {
std::string remoteIP; std::string remoteIP;
uint16_t remotePort; uint16_t remotePort;
std::string localIP;
bool sendRtp{ true }; bool sendRtp{ true };
bool sendRtcp{ true }; bool sendRtcp{ true };
bool recvRtp{ true }; bool recvRtp{ true };
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "common.hpp" #include "common.hpp"
#include "handles/UdpSocket.hpp" #include "handles/UdpSocket.hpp"
#include <uv.h> #include <uv.h>
#include <string>
#include <unordered_map> #include <unordered_map>
namespace RTC namespace RTC
...@@ -37,6 +38,7 @@ namespace RTC ...@@ -37,6 +38,7 @@ namespace RTC
public: public:
UdpSocket(Listener* listener, int addressFamily); UdpSocket(Listener* listener, int addressFamily);
UdpSocket(Listener* listener, const std::string& ip);
private: private:
~UdpSocket() override = default; ~UdpSocket() override = default;
......
...@@ -29,7 +29,7 @@ namespace RTC ...@@ -29,7 +29,7 @@ namespace RTC
{ {
case AF_INET: case AF_INET:
{ {
if (!Settings::configuration.hasIPv4) if (!Settings::configuration.hasIPv4 && options.localIP.empty())
MS_THROW_ERROR("IPv4 disabled"); MS_THROW_ERROR("IPv4 disabled");
err = uv_ip4_addr( err = uv_ip4_addr(
...@@ -39,14 +39,17 @@ namespace RTC ...@@ -39,14 +39,17 @@ namespace RTC
if (err != 0) if (err != 0)
MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err)); MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err));
if (options.localIP.empty())
this->udpSocket = new RTC::UdpSocket(this, AF_INET); this->udpSocket = new RTC::UdpSocket(this, AF_INET);
else
this->udpSocket = new RTC::UdpSocket(this, options.localIP);
break; break;
} }
case AF_INET6: case AF_INET6:
{ {
if (!Settings::configuration.hasIPv6) if (!Settings::configuration.hasIPv6 && options.localIP.empty())
MS_THROW_ERROR("IPv6 disabled"); MS_THROW_ERROR("IPv6 disabled");
err = uv_ip6_addr( err = uv_ip6_addr(
...@@ -56,7 +59,10 @@ namespace RTC ...@@ -56,7 +59,10 @@ namespace RTC
if (err != 0) if (err != 0)
MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err)); MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err));
if (options.localIP.empty())
this->udpSocket = new RTC::UdpSocket(this, AF_INET6); this->udpSocket = new RTC::UdpSocket(this, AF_INET6);
else
this->udpSocket = new RTC::UdpSocket(this, options.localIP);
break; break;
} }
......
...@@ -240,6 +240,7 @@ namespace RTC ...@@ -240,6 +240,7 @@ namespace RTC
{ {
static const Json::StaticString JsonStringRemoteIP{ "remoteIP" }; static const Json::StaticString JsonStringRemoteIP{ "remoteIP" };
static const Json::StaticString JsonStringRemotePort{ "remotePort" }; static const Json::StaticString JsonStringRemotePort{ "remotePort" };
static const Json::StaticString JsonStringLocalIP{ "localIP" };
uint32_t transportId; uint32_t transportId;
...@@ -274,6 +275,9 @@ namespace RTC ...@@ -274,6 +275,9 @@ namespace RTC
options.remotePort = request->data[JsonStringRemotePort].asUInt(); options.remotePort = request->data[JsonStringRemotePort].asUInt();
if (request->data[JsonStringLocalIP].isString())
options.localIP = request->data[JsonStringLocalIP].asString();
RTC::PlainRtpTransport* plainRtpTransport; RTC::PlainRtpTransport* plainRtpTransport;
try try
...@@ -837,6 +841,7 @@ namespace RTC ...@@ -837,6 +841,7 @@ namespace RTC
{ {
static const Json::StaticString JsonStringRemoteIP{ "remoteIP" }; static const Json::StaticString JsonStringRemoteIP{ "remoteIP" };
static const Json::StaticString JsonStringRemotePort{ "remotePort" }; static const Json::StaticString JsonStringRemotePort{ "remotePort" };
static const Json::StaticString JsonStringLocalIP{ "localIP" };
static const Json::StaticString JsonStringSendRtp{ "sendRtp" }; static const Json::StaticString JsonStringSendRtp{ "sendRtp" };
static const Json::StaticString JsonStringSendRtcp{ "sendRtcp" }; static const Json::StaticString JsonStringSendRtcp{ "sendRtcp" };
static const Json::StaticString JsonStringRecvRtp{ "recvRtp" }; static const Json::StaticString JsonStringRecvRtp{ "recvRtp" };
...@@ -875,6 +880,9 @@ namespace RTC ...@@ -875,6 +880,9 @@ namespace RTC
options.remotePort = request->data[JsonStringRemotePort].asUInt(); options.remotePort = request->data[JsonStringRemotePort].asUInt();
if (request->data[JsonStringLocalIP].isString())
options.localIP = request->data[JsonStringLocalIP].asString();
if (request->data[JsonStringSendRtp].isBool()) if (request->data[JsonStringSendRtp].isBool())
options.sendRtp = request->data[JsonStringSendRtp].asBool(); options.sendRtp = request->data[JsonStringSendRtp].asBool();
if (request->data[JsonStringSendRtcp].isBool()) if (request->data[JsonStringSendRtcp].isBool())
......
...@@ -215,7 +215,7 @@ namespace RTC ...@@ -215,7 +215,7 @@ namespace RTC
: // Provide the parent class constructor with a UDP uv handle. : // Provide the parent class constructor with a UDP uv handle.
// NOTE: This may throw a MediaSoupError exception if the address family is not available // NOTE: This may throw a MediaSoupError exception if the address family is not available
// or there are no available ports. // or there are no available ports.
::TcpServer::TcpServer(GetRandomPort(addressFamily), 256), listener(listener), ::TcpServer::TcpServer(TcpServer::GetRandomPort(addressFamily), 256), listener(listener),
connListener(connListener) connListener(connListener)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -79,7 +79,7 @@ namespace RTC ...@@ -79,7 +79,7 @@ namespace RTC
{ {
case AF_INET: case AF_INET:
{ {
if (!Settings::configuration.hasIPv4) if (!Settings::configuration.hasIPv4 && options.localIP.empty())
MS_THROW_ERROR("IPv4 disabled"); MS_THROW_ERROR("IPv4 disabled");
err = uv_ip4_addr( err = uv_ip4_addr(
...@@ -89,14 +89,17 @@ namespace RTC ...@@ -89,14 +89,17 @@ namespace RTC
if (err != 0) if (err != 0)
MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err)); MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err));
if (options.localIP.empty())
this->mirrorSocket = new RTC::UdpSocket(this, AF_INET); this->mirrorSocket = new RTC::UdpSocket(this, AF_INET);
else
this->mirrorSocket = new RTC::UdpSocket(this, options.localIP);
break; break;
} }
case AF_INET6: case AF_INET6:
{ {
if (!Settings::configuration.hasIPv6) if (!Settings::configuration.hasIPv6 && options.localIP.empty())
MS_THROW_ERROR("IPv6 disabled"); MS_THROW_ERROR("IPv6 disabled");
err = uv_ip6_addr( err = uv_ip6_addr(
...@@ -106,7 +109,10 @@ namespace RTC ...@@ -106,7 +109,10 @@ namespace RTC
if (err != 0) if (err != 0)
MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err)); MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err));
if (options.localIP.empty())
this->mirrorSocket = new RTC::UdpSocket(this, AF_INET6); this->mirrorSocket = new RTC::UdpSocket(this, AF_INET6);
else
this->mirrorSocket = new RTC::UdpSocket(this, options.localIP);
break; break;
} }
......
...@@ -214,7 +214,15 @@ namespace RTC ...@@ -214,7 +214,15 @@ namespace RTC
: // Provide the parent class constructor with a UDP uv handle. : // Provide the parent class constructor with a UDP uv handle.
// NOTE: This may throw a MediaSoupError exception if the address family is not available // NOTE: This may throw a MediaSoupError exception if the address family is not available
// or there are no available ports. // or there are no available ports.
::UdpSocket::UdpSocket(GetRandomPort(addressFamily)), listener(listener) ::UdpSocket::UdpSocket(UdpSocket::GetRandomPort(addressFamily)), listener(listener)
{
MS_TRACE();
}
UdpSocket::UdpSocket(Listener* listener, const std::string& ip)
: // Provide the parent class constructor with an IP and port 0.
// NOTE: This may throw a MediaSoupError exception if the given IP is invalid.
::UdpSocket::UdpSocket(ip, 0), listener(listener)
{ {
MS_TRACE(); MS_TRACE();
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论