Merge branch 'google3' to roll forward to cl/340537221.

This commit is contained in:
hai007
2020-11-03 15:30:12 -08:00
7 changed files with 26 additions and 19 deletions
+4
View File
@@ -42,6 +42,10 @@ WebRtc::~WebRtc() {
Disconnect();
}
const std::string WebRtc::GetDefaultCountryCode() {
return medium_.GetDefaultCountryCode();
}
bool WebRtc::IsAvailable() { return medium_.IsValid(); }
bool WebRtc::IsAcceptingConnections() {
+4
View File
@@ -44,6 +44,10 @@ class WebRtc {
WebRtc();
~WebRtc();
// Gets the default two-letter country code associated with current locale.
// For example, en_US locale resolves to "US".
const std::string GetDefaultCountryCode();
// Returns if WebRtc is available as a medium for nearby to transport data.
// Runs on @MainThread.
bool IsAvailable();
+2 -19
View File
@@ -1,6 +1,5 @@
#include "core/internal/webrtc_bwu_handler.h"
#include <locale>
#include <string>
#include "core/internal/client_proxy.h"
@@ -61,7 +60,8 @@ ByteArray WebrtcBwuHandler::InitializeUpgradedMediumForEndpoint(
// stop the advertising yet.
std::string upgrade_service_id = Utils::WrapUpgradeServiceId(service_id);
LocationHint location_hint = Utils::BuildLocationHint(GetCountryCode());
LocationHint location_hint =
Utils::BuildLocationHint(webrtc_.GetDefaultCountryCode());
mediums::PeerId self_id{mediums::PeerId::FromRandom()};
if (!webrtc_.IsAcceptingConnections()) {
@@ -141,23 +141,6 @@ WebrtcBwuHandler::CreateUpgradedEndpointChannel(
void WebrtcBwuHandler::OnEndpointDisconnect(ClientProxy* client,
const std::string& endpoint_id) {}
std::string WebrtcBwuHandler::GetCountryCode() {
std::string default_locale_name = std::locale("").name();
// locale name has a format: <lang>_<country>.<encoding>
int s = default_locale_name.find("_");
int e = default_locale_name.find(".");
if (s == -1 || e == -1) {
return "";
}
auto country_code = default_locale_name.substr(s + 1, e - s - 1);
std::transform(country_code.begin(), country_code.end(), country_code.begin(),
std::towlower);
return country_code;
}
WebrtcBwuHandler::WebrtcIncomingSocket::WebrtcIncomingSocket(
const std::string& name, mediums::WebRtcSocketWrapper socket)
: name_(name), socket_(socket) {}