Add WEB_RTC_NON_CELLULAR enum, II

PiperOrigin-RevId: 685103930
This commit is contained in:
Edwin Wu
2024-10-12 00:28:58 -07:00
committed by Copybara-Service
parent fec1c8f63f
commit 7b2eddc458
9 changed files with 85 additions and 7 deletions
-2
View File
@@ -335,11 +335,9 @@ cc_library(
# TODO: Support WebRTC
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/types:optional",
],
)
@@ -105,6 +105,7 @@ cc_library(
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
)
@@ -15,9 +15,16 @@
#include "internal/platform/implementation/g3/webrtc.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "absl/strings/string_view.h"
#include "absl/time/clock.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/implementation/webrtc.h"
#include "internal/platform/medium_environment.h"
#include "webrtc/api/peer_connection_interface.h"
#include "webrtc/api/task_queue/default_task_queue_factory.h"
#include "webrtc/rtc_base/checks.h"
@@ -56,6 +63,12 @@ const std::string WebRtcMedium::GetDefaultCountryCode() { return "US"; }
void WebRtcMedium::CreatePeerConnection(
webrtc::PeerConnectionObserver* observer, PeerConnectionCallback callback) {
CreatePeerConnection(std::nullopt, observer, std::move(callback));
}
void WebRtcMedium::CreatePeerConnection(
std::optional<webrtc::PeerConnectionFactoryInterface::Options> options,
webrtc::PeerConnectionObserver* observer, PeerConnectionCallback callback) {
auto& env = MediumEnvironment::Instance();
if (!env.GetUseValidPeerConnection()) {
callback(nullptr);
@@ -75,6 +88,9 @@ void WebRtcMedium::CreatePeerConnection(
webrtc::CreateDefaultTaskQueueFactory();
factory_dependencies.signaling_thread = signaling_thread.release();
if (options.has_value()) {
// TODO(edwinwu): Add support for non-cellular networks.
}
auto peer_connection_or_error =
webrtc::CreateModularPeerConnectionFactory(
std::move(factory_dependencies))
@@ -16,8 +16,11 @@
#define PLATFORM_IMPL_G3_WEBRTC_H_
#include <memory>
#include <optional>
#include <string>
#include "absl/strings/string_view.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/implementation/webrtc.h"
#include "internal/platform/implementation/g3/single_thread_executor.h"
#include "webrtc/api/peer_connection_interface.h"
@@ -63,6 +66,13 @@ class WebRtcMedium : public api::WebRtcMedium {
void CreatePeerConnection(webrtc::PeerConnectionObserver* observer,
PeerConnectionCallback callback) override;
// Creates and returns a new webrtc::PeerConnectionInterface object via
// |callback| with |PeerConnectionFactoryInterface::Options|.
void CreatePeerConnection(
std::optional<webrtc::PeerConnectionFactoryInterface::Options> options,
webrtc::PeerConnectionObserver* observer,
PeerConnectionCallback callback) override;
// Returns a signaling messenger for sending WebRTC signaling messages.
std::unique_ptr<api::WebRtcSignalingMessenger> GetSignalingMessenger(
absl::string_view self_id,
@@ -18,8 +18,10 @@
#ifndef NO_WEBRTC
#include <memory>
#include <optional>
#include <string>
#include "absl/functional/any_invocable.h"
#include "absl/strings/string_view.h"
#include "connections/implementation/proto/offline_wire_formats.pb.h"
#include "internal/platform/byte_array.h"
@@ -60,6 +62,13 @@ class WebRtcMedium {
virtual void CreatePeerConnection(webrtc::PeerConnectionObserver* observer,
PeerConnectionCallback callback) = 0;
// Creates and returns a new webrtc::PeerConnectionInterface object via
// |callback| with |PeerConnectionFactoryInterface::Options|.
virtual void CreatePeerConnection(
std::optional<webrtc::PeerConnectionFactoryInterface::Options> options,
webrtc::PeerConnectionObserver* observer,
PeerConnectionCallback callback) = 0;
// Returns a signaling messenger for sending WebRTC signaling messages.
virtual std::unique_ptr<WebRtcSignalingMessenger> GetSignalingMessenger(
absl::string_view self_id,
@@ -17,6 +17,7 @@
#include <winnls.h>
#include <memory>
#include <optional>
#include <string>
#include <utility>
@@ -71,6 +72,12 @@ const std::string WebRtcMedium::GetDefaultCountryCode() {
void WebRtcMedium::CreatePeerConnection(
webrtc::PeerConnectionObserver* observer, PeerConnectionCallback callback) {
CreatePeerConnection(std::nullopt, observer, std::move(callback));
}
void WebRtcMedium::CreatePeerConnection(
std::optional<webrtc::PeerConnectionFactoryInterface::Options> options,
webrtc::PeerConnectionObserver* observer, PeerConnectionCallback callback) {
webrtc::PeerConnectionInterface::RTCConfiguration rtc_config;
rtc_config.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
// TODO(b/261663238): Add the TURN servers and go beyond the default servers.
@@ -94,6 +101,9 @@ void WebRtcMedium::CreatePeerConnection(
webrtc::CreateDefaultTaskQueueFactory();
factory_dependencies.signaling_thread = signaling_thread.release();
if (options.has_value()) {
// TODO(edwinwu): Add support for non-cellular networks.
}
auto peer_connection_or_error =
webrtc::CreateModularPeerConnectionFactory(
std::move(factory_dependencies))
@@ -15,10 +15,15 @@
#ifndef PLATFORM_IMPL_WINDOWS_WEBRTC_H_
#define PLATFORM_IMPL_WINDOWS_WEBRTC_H_
#include <memory>
#include <optional>
#include <string>
#include "absl/strings/string_view.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/implementation/account_manager.h"
#include "internal/platform/implementation/webrtc.h"
#include "webrtc/api/peer_connection_interface.h"
namespace nearby {
namespace windows {
@@ -63,6 +68,13 @@ class WebRtcMedium : public api::WebRtcMedium {
void CreatePeerConnection(webrtc::PeerConnectionObserver* observer,
PeerConnectionCallback callback) override;
// Creates and returns a new webrtc::PeerConnectionInterface object via
// |callback| with |PeerConnectionFactoryInterface::Options|.
void CreatePeerConnection(
std::optional<webrtc::PeerConnectionFactoryInterface::Options> options,
webrtc::PeerConnectionObserver* observer,
PeerConnectionCallback callback) override;
// Returns a signaling messenger for sending WebRTC signaling messages.
// TODO(b/261663238): replace with real implementation.
std::unique_ptr<api::WebRtcSignalingMessenger> GetSignalingMessenger(
@@ -15,12 +15,17 @@
#include "internal/platform/implementation/windows/webrtc.h"
#include <memory>
#include <optional>
#include <string>
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "internal/platform/implementation/webrtc.h"
#include "webrtc/api/jsep.h"
#include "webrtc/api/data_channel_interface.h"
#include "webrtc/api/peer_connection_interface.h"
#include "webrtc/api/scoped_refptr.h"
namespace nearby {
namespace windows {
@@ -58,8 +63,9 @@ TEST(WebrtcTest, CreatePeerConnectionSucceeds) {
auto observer = std::make_unique<MockPeerConnectionObserver>();
WebRtcMedium medium;
medium.CreatePeerConnection(
observer.get(), [](rtc::scoped_refptr<webrtc::PeerConnectionInterface>
peer_connection) mutable {
std::nullopt, observer.get(),
[](rtc::scoped_refptr<webrtc::PeerConnectionInterface>
peer_connection) mutable {
if (!peer_connection) {
FAIL() << "Peer connection should have been non-null";
return;
+17 -1
View File
@@ -18,7 +18,12 @@
#ifndef NO_WEBRTC
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "absl/strings/string_view.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/implementation/platform.h"
#include "internal/platform/implementation/webrtc.h"
#include "webrtc/api/peer_connection_interface.h"
@@ -74,11 +79,21 @@ class WebRtcMedium {
return impl_->GetDefaultCountryCode();
}
void SetNonCellular(bool non_cellular) {
non_cellular_ = non_cellular;
}
// Creates and returns a new webrtc::PeerConnectionInterface object via
// |callback|.
void CreatePeerConnection(webrtc::PeerConnectionObserver* observer,
PeerConnectionCallback callback) {
impl_->CreatePeerConnection(observer, std::move(callback));
// TODO(edwinwu): Add a flag to control this and add support for
// non-cellular networks.
if (non_cellular_) {
impl_->CreatePeerConnection(std::nullopt, observer, std::move(callback));
} else {
impl_->CreatePeerConnection(observer, std::move(callback));
}
}
// Returns a signaling messenger for sending WebRTC signaling messages.
@@ -93,6 +108,7 @@ class WebRtcMedium {
private:
std::unique_ptr<api::WebRtcMedium> impl_;
bool non_cellular_ = false;
};
} // namespace nearby