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

Fix UpdateIceServers method parameters format #167

Open
wants to merge 3 commits into
base: v3
Choose a base branch
from
Open
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
22 changes: 18 additions & 4 deletions src/Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,33 @@ namespace mediasoupclient
return this->pc->GetStats();
}

void Handler::UpdateIceServers(const json& iceServerUris)
void Handler::UpdateIceServers(const json& iceServersDescription)
{
MSC_TRACE();

auto configuration = this->pc->GetConfiguration();

configuration.servers.clear();

for (const auto& iceServerUri : iceServerUris)
for (const auto& iceServerDescription : iceServersDescription)
{
if (!iceServerDescription.contains("urls")) {
continue;
}
webrtc::PeerConnectionInterface::IceServer iceServer;

iceServer.uri = iceServerUri.get<std::string>();
if (iceServerDescription["urls"].is_string()) {
iceServer.urls = { iceServerDescription["urls"].get<std::string>() };
} else if (iceServerDescription["urls"].is_array()) {
iceServer.urls = iceServerDescription["urls"].get<std::vector<std::string>>();
} else {
continue;
}
if (iceServerDescription.contains("username")) {
iceServer.username = iceServerDescription["username"].get<std::string>();
}
if (iceServerDescription.contains("credential")) {
iceServer.password = iceServerDescription["credential"].get<std::string>();
}
configuration.servers.push_back(iceServer);
}

Expand Down
1 change: 1 addition & 0 deletions test/include/fakeParameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ json generateLocalDtlsParameters();
json generateTransportRemoteParameters();
std::string generateProducerRemoteId();
json generateConsumerRemoteParameters(const std::string& codecMimeType);
json generateIceServers();

#endif
8 changes: 7 additions & 1 deletion test/src/Handler.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

static const json TransportRemoteParameters = generateTransportRemoteParameters();
static const json RtpParametersByKind = generateRtpParametersByKind();
static const json IceServers = generateIceServers();

static mediasoupclient::PeerConnection::Options PeerConnectionOptions;

Expand Down Expand Up @@ -201,8 +202,13 @@ TEST_CASE("RecvHandler", "[Handler][RecvHandler]")
REQUIRE_NOTHROW(recvHandler.RestartIce(iceParameters));
}

SECTION("recvHandler.UpdateIceServers() succeeds")
SECTION("recvHandler.UpdateIceServers() succeeds with empty array")
{
REQUIRE_NOTHROW(recvHandler.UpdateIceServers(json::array()));
}

SECTION("recvHandler.UpdateIceServers() succeeds with non-empty array")
{
REQUIRE_NOTHROW(recvHandler.UpdateIceServers(IceServers));
}
}
19 changes: 19 additions & 0 deletions test/src/fakeParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,22 @@ json generateConsumerRemoteParameters(const std::string& codecMimeType)

return json::object();
};

json generateIceServers()
{
auto json = R"(
[
{
"urls" : [
"turn:t1.server.com",
"turn:t2.server.com"
],
"username" : "fakeuser",
"credential" : "fakepass"
},
{
"urls" : "stun:s.server.com"
}
])"_json;
return json;
};