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