mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
@@ -42,6 +42,10 @@ WebRtc::~WebRtc() {
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
const std::string WebRtc::GetDefaultCountryCode() {
|
||||
return medium_.GetDefaultCountryCode();
|
||||
}
|
||||
|
||||
bool WebRtc::IsAvailable() { return medium_.IsValid(); }
|
||||
|
||||
bool WebRtc::IsAcceptingConnections() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
@@ -33,6 +33,10 @@ class WebRtcMedium {
|
||||
|
||||
virtual ~WebRtcMedium() = default;
|
||||
|
||||
// Gets the default two-letter country code associated with current locale.
|
||||
// For example, en_US locale resolves to "US".
|
||||
virtual const std::string GetDefaultCountryCode() = 0;
|
||||
|
||||
// Creates and returns a new webrtc::PeerConnectionInterface object via
|
||||
// |callback|.
|
||||
virtual void CreatePeerConnection(webrtc::PeerConnectionObserver* observer,
|
||||
|
||||
@@ -32,6 +32,10 @@ void WebRtcSignalingMessenger::StopReceivingMessages() {
|
||||
env.UnregisterWebRtcSignalingMessenger(self_id_);
|
||||
}
|
||||
|
||||
const std::string WebRtcMedium::GetDefaultCountryCode() {
|
||||
return "US";
|
||||
}
|
||||
|
||||
void WebRtcMedium::CreatePeerConnection(
|
||||
webrtc::PeerConnectionObserver* observer, PeerConnectionCallback callback) {
|
||||
auto& env = MediumEnvironment::Instance();
|
||||
|
||||
@@ -38,6 +38,8 @@ class WebRtcMedium : public api::WebRtcMedium {
|
||||
WebRtcMedium() = default;
|
||||
~WebRtcMedium() override = default;
|
||||
|
||||
const std::string GetDefaultCountryCode() override;
|
||||
|
||||
// Creates and returns a new webrtc::PeerConnectionInterface object via
|
||||
// |callback|.
|
||||
void CreatePeerConnection(webrtc::PeerConnectionObserver* observer,
|
||||
|
||||
@@ -47,6 +47,12 @@ class WebRtcMedium final {
|
||||
WebRtcMedium(WebRtcMedium&&) = delete;
|
||||
WebRtcMedium& operator=(WebRtcMedium&&) = delete;
|
||||
|
||||
// Gets the default two-letter country code associated with current locale.
|
||||
// For example, en_US locale resolves to "US".
|
||||
const std::string GetDefaultCountryCode() {
|
||||
return impl_->GetDefaultCountryCode();
|
||||
}
|
||||
|
||||
// Creates and returns a new webrtc::PeerConnectionInterface object via
|
||||
// |callback|.
|
||||
void CreatePeerConnection(webrtc::PeerConnectionObserver* observer,
|
||||
|
||||
Reference in New Issue
Block a user