Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,15 @@ class Room extends EnhancedEventEmitter

return rtpStreamer;
})
.catch(() =>
.catch((error) =>
{
if (plainRtpTransport)
plainRtpTransport.close();

if (consumer)
consumer.close();

throw error;
});
}

Expand Down
1 change: 1 addition & 0 deletions worker/include/RTC/PlainRtpTransport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace RTC
{
std::string remoteIP;
uint16_t remotePort;
std::string localIP;
};

public:
Expand Down
1 change: 1 addition & 0 deletions worker/include/RTC/Transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace RTC
{
std::string remoteIP;
uint16_t remotePort;
std::string localIP;
bool sendRtp{ true };
bool sendRtcp{ true };
bool recvRtp{ true };
Expand Down
2 changes: 2 additions & 0 deletions worker/include/RTC/UdpSocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "common.hpp"
#include "handles/UdpSocket.hpp"
#include <uv.h>
#include <string>
#include <unordered_map>

namespace RTC
Expand Down Expand Up @@ -37,6 +38,7 @@ namespace RTC

public:
UdpSocket(Listener* listener, int addressFamily);
UdpSocket(Listener* listener, const std::string& ip);

private:
~UdpSocket() override = default;
Expand Down
14 changes: 10 additions & 4 deletions worker/src/RTC/PlainRtpTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions worker/src/RTC/Router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" };
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/TcpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 10 additions & 4 deletions worker/src/RTC/Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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;
}
Expand Down
10 changes: 9 additions & 1 deletion worker/src/RTC/UdpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down