Skip to content

Commit

Permalink
fixup! Added option to automatically determine port to WebRtcServer
Browse files Browse the repository at this point in the history
  • Loading branch information
satoren committed Sep 13, 2022
1 parent 0fc914a commit 4fd4a12
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions worker/src/RTC/WebRtcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,17 @@ namespace RTC
listenInfo.announcedIp.assign(jsonAnnouncedIpIt->get<std::string>());
}

uint16_t port{ 0 };
auto jsonPortIt = jsonListenInfo.find("port");

if (jsonPortIt == jsonListenInfo.end())
listenInfo.port = 0;
else if (!(jsonPortIt->is_number() && Utils::Json::IsPositiveInteger(*jsonPortIt)))
MS_THROW_TYPE_ERROR("wrong listenInfo.port (not a positive number)");
else
listenInfo.port = jsonPortIt->get<uint16_t>();
if (jsonPortIt != jsonListenInfo.end())
{
if (!(jsonPortIt->is_number() && Utils::Json::IsPositiveInteger(*jsonPortIt)))
MS_THROW_TYPE_ERROR("wrong port (not a positive number)");

port = jsonPortIt->get<uint16_t>();
}
listenInfo.port = port;
}

try
Expand All @@ -112,6 +115,7 @@ namespace RTC
{
// This may throw.
RTC::UdpSocket* udpSocket;

if (listenInfo.port != 0)
udpSocket = new RTC::UdpSocket(this, listenInfo.ip, listenInfo.port);
else
Expand Down

0 comments on commit 4fd4a12

Please sign in to comment.