mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Add WEB_RTC_NON_CELLULAR enum, VI
PiperOrigin-RevId: 690941154
This commit is contained in:
committed by
Copybara-Service
parent
0e4379ddc6
commit
7fca68d543
@@ -35,8 +35,8 @@
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/cancellation_flag_listener.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/future.h"
|
||||
#include "internal/platform/feature_flags.h"
|
||||
#include "internal/platform/future.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/mutex_lock.h"
|
||||
#include "internal/platform/webrtc.h"
|
||||
@@ -744,29 +744,27 @@ std::unique_ptr<ConnectionFlow> WebRtc::CreateConnectionFlow(
|
||||
}},
|
||||
},
|
||||
{
|
||||
.adapter_type_changed_cb =
|
||||
{[this](/*rtc::AdapterType*/ int adapter_type) {
|
||||
OffloadFromThread(
|
||||
"rtc-adapter-type-changed", [this, adapter_type]() {
|
||||
if (FeatureFlags::GetInstance()
|
||||
.GetFlags()
|
||||
.support_web_rtc_non_cellular_medium) {
|
||||
AdapterTypeChangedHandler(adapter_type);
|
||||
}
|
||||
});
|
||||
}},
|
||||
.adapter_type_changed_cb = {[this](rtc::AdapterType adapter_type) {
|
||||
OffloadFromThread("rtc-adapter-type-changed",
|
||||
[this, adapter_type]() {
|
||||
if (FeatureFlags::GetInstance()
|
||||
.GetFlags()
|
||||
.support_web_rtc_non_cellular_medium) {
|
||||
AdapterTypeChangedHandler(adapter_type);
|
||||
}
|
||||
});
|
||||
}},
|
||||
},
|
||||
*medium_);
|
||||
}
|
||||
|
||||
void WebRtc::AdapterTypeChangedHandler(/*rtc::AdapterType*/ int adapter_type) {
|
||||
// TODO(edwinwu): Uncomment this once OSS supports WEB_RTC
|
||||
// MutexLock lock(&mutex_);
|
||||
// is_using_cellular_ = adapter_type == rtc::ADAPTER_TYPE_CELLULAR ||
|
||||
// adapter_type == rtc::ADAPTER_TYPE_CELLULAR_2G ||
|
||||
// adapter_type == rtc::ADAPTER_TYPE_CELLULAR_3G ||
|
||||
// adapter_type == rtc::ADAPTER_TYPE_CELLULAR_4G ||
|
||||
// adapter_type == rtc::ADAPTER_TYPE_CELLULAR_5G;
|
||||
void WebRtc::AdapterTypeChangedHandler(rtc::AdapterType adapter_type) {
|
||||
MutexLock lock(&mutex_);
|
||||
is_using_cellular_ = adapter_type == rtc::ADAPTER_TYPE_CELLULAR ||
|
||||
adapter_type == rtc::ADAPTER_TYPE_CELLULAR_2G ||
|
||||
adapter_type == rtc::ADAPTER_TYPE_CELLULAR_3G ||
|
||||
adapter_type == rtc::ADAPTER_TYPE_CELLULAR_4G ||
|
||||
adapter_type == rtc::ADAPTER_TYPE_CELLULAR_5G;
|
||||
}
|
||||
|
||||
void WebRtc::RemoveConnectionFlow(const WebrtcPeerId& remote_peer_id) {
|
||||
|
||||
@@ -235,7 +235,7 @@ class WebRtc {
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
// Runs on |single_thread_executor_|.
|
||||
void AdapterTypeChangedHandler(/*rtc::AdapterType*/ int adapter_type)
|
||||
void AdapterTypeChangedHandler(rtc::AdapterType adapter_type)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
void OffloadFromThread(const std::string& name, Runnable runnable);
|
||||
|
||||
@@ -68,7 +68,6 @@ cc_library(
|
||||
"//connections:core_types",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:types",
|
||||
# TODO: Support WebRTC
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -485,6 +485,16 @@ void ConnectionFlow::OnRenegotiationNeeded() {
|
||||
CHECK(IsRunningOnSignalingThread());
|
||||
}
|
||||
|
||||
void ConnectionFlow::OnIceSelectedCandidatePairChanged(
|
||||
const cricket::CandidatePairChangeEvent& event) {
|
||||
NEARBY_LOGS(INFO) << "OnIceSelectedCandidatePairChanged";
|
||||
CHECK(IsRunningOnSignalingThread());
|
||||
// TODO(edwinwu) - Implement the unit test for this. We should be able to get
|
||||
// the adapter type from the PeerConnection.
|
||||
adapter_type_listener_.adapter_type_changed_cb(
|
||||
event.selected_candidate_pair.local_candidate().network_type());
|
||||
}
|
||||
|
||||
bool ConnectionFlow::TransitionState(State current_state, State new_state) {
|
||||
CHECK(IsRunningOnSignalingThread());
|
||||
if (current_state != state_) {
|
||||
|
||||
@@ -86,12 +86,9 @@ class ConnectionFlow : public webrtc::PeerConnectionObserver {
|
||||
kEnded,
|
||||
};
|
||||
|
||||
// The listener that notifies the AdapterType has been changed.
|
||||
// TODO(edwinwu): replace param |int| to |rtc::AdapterType| once OSS supports
|
||||
// WebRtc.
|
||||
struct AdapterTypeListener {
|
||||
absl::AnyInvocable<void(/*rtc::AdapterType*/ int adapter_type)>
|
||||
adapter_type_changed_cb = DefaultCallback</*rtc::AdapterType*/ int>();
|
||||
absl::AnyInvocable<void(rtc::AdapterType adapter_type)>
|
||||
adapter_type_changed_cb = DefaultCallback<rtc::AdapterType>();
|
||||
};
|
||||
|
||||
// This method blocks on the creation of the peer connection object.
|
||||
@@ -149,9 +146,8 @@ class ConnectionFlow : public webrtc::PeerConnectionObserver {
|
||||
void OnConnectionChange(
|
||||
webrtc::PeerConnectionInterface::PeerConnectionState new_state) override;
|
||||
void OnRenegotiationNeeded() override;
|
||||
// TODO(edwinwu): Implement once OSS supports WebRtc.
|
||||
// void OnIceSelectedCandidatePairChanged(
|
||||
// const cricket::CandidatePairChangeEvent& event) override;
|
||||
void OnIceSelectedCandidatePairChanged(
|
||||
const cricket::CandidatePairChangeEvent& event) override;
|
||||
|
||||
// Public because it's used in tests too.
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionInterface> GetPeerConnection();
|
||||
|
||||
@@ -81,7 +81,7 @@ TEST_F(ConnectionFlowTest, SuccessfulOfferAnswerFlow) {
|
||||
offerer_socket_future.Set(std::move(socket));
|
||||
}},
|
||||
{.adapter_type_changed_cb =
|
||||
[](/*rtc::AdapterType*/ int adapter_type) {
|
||||
[](rtc::AdapterType adapter_type) {
|
||||
// Do nothing
|
||||
}},
|
||||
webrtc_medium_offerer);
|
||||
@@ -101,7 +101,7 @@ TEST_F(ConnectionFlowTest, SuccessfulOfferAnswerFlow) {
|
||||
answerer_socket_future.Set(std::move(socket));
|
||||
}},
|
||||
{.adapter_type_changed_cb =
|
||||
[](/*rtc::AdapterType*/ int adapter_type) {
|
||||
[](rtc::AdapterType adapter_type) {
|
||||
// Do nothing
|
||||
}},
|
||||
webrtc_medium_answerer);
|
||||
@@ -280,7 +280,7 @@ TEST_F(ConnectionFlowTest, TerminateAnswerer) {
|
||||
offerer_socket_future.Set(std::move(socket));
|
||||
}},
|
||||
{.adapter_type_changed_cb =
|
||||
[](/*rtc::AdapterType*/ int adapter_type) {
|
||||
[](rtc::AdapterType adapter_type) {
|
||||
// Do nothing
|
||||
}},
|
||||
webrtc_medium_offerer);
|
||||
@@ -300,8 +300,9 @@ TEST_F(ConnectionFlowTest, TerminateAnswerer) {
|
||||
answerer_socket_future.Set(std::move(wrapper));
|
||||
}},
|
||||
{.adapter_type_changed_cb =
|
||||
[](/*rtc::AdapterType*/ int adapter_type) {
|
||||
// Do nothing
|
||||
[](rtc::AdapterType adapter_type) {
|
||||
EXPECT_GE(adapter_type, rtc::ADAPTER_TYPE_UNKNOWN);
|
||||
EXPECT_LE(adapter_type, rtc::ADAPTER_TYPE_CELLULAR_5G);
|
||||
}},
|
||||
webrtc_medium_answerer);
|
||||
ASSERT_NE(answerer, nullptr);
|
||||
@@ -369,8 +370,9 @@ TEST_F(ConnectionFlowTest, TerminateOfferer) {
|
||||
offerer_socket_future.Set(std::move(socket));
|
||||
}},
|
||||
{.adapter_type_changed_cb =
|
||||
[](/*rtc::AdapterType*/ int adapter_type) {
|
||||
// Do nothing
|
||||
[](rtc::AdapterType adapter_type) {
|
||||
EXPECT_GE(adapter_type, rtc::ADAPTER_TYPE_UNKNOWN);
|
||||
EXPECT_LE(adapter_type, rtc::ADAPTER_TYPE_CELLULAR_5G);
|
||||
}},
|
||||
webrtc_medium_offerer);
|
||||
ASSERT_NE(offerer, nullptr);
|
||||
@@ -389,8 +391,9 @@ TEST_F(ConnectionFlowTest, TerminateOfferer) {
|
||||
answerer_socket_future.Set(std::move(wrapper));
|
||||
}},
|
||||
{.adapter_type_changed_cb =
|
||||
[](/*rtc::AdapterType*/ int adapter_type) {
|
||||
// Do nothing
|
||||
[](rtc::AdapterType adapter_type) {
|
||||
EXPECT_GE(adapter_type, rtc::ADAPTER_TYPE_UNKNOWN);
|
||||
EXPECT_LE(adapter_type, rtc::ADAPTER_TYPE_CELLULAR_5G);
|
||||
}},
|
||||
webrtc_medium_answerer);
|
||||
ASSERT_NE(answerer, nullptr);
|
||||
@@ -432,6 +435,7 @@ TEST_F(ConnectionFlowTest, TerminateOfferer) {
|
||||
answerer_socket.result().GetInputStream().Read(4);
|
||||
EXPECT_TRUE(received_message.GetResult().Empty());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace mediums
|
||||
} // namespace connections
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/single_thread_executor.h"
|
||||
#include "internal/platform/socket.h"
|
||||
#include "webrtc/api/data_channel_interface.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
@@ -90,9 +90,10 @@ class WebRtcMedium {
|
||||
PeerConnectionCallback callback) {
|
||||
if (FeatureFlags::GetInstance()
|
||||
.GetFlags()
|
||||
.support_web_rtc_non_cellular_medium) {
|
||||
// TODO(edwinwu): Add support for non-cellular networks.
|
||||
impl_->CreatePeerConnection(std::nullopt, observer, std::move(callback));
|
||||
.support_web_rtc_non_cellular_medium && non_cellular_) {
|
||||
std::optional<webrtc::PeerConnectionFactoryInterface::Options> options;
|
||||
options->network_ignore_mask |= rtc::ADAPTER_TYPE_CELLULAR;
|
||||
impl_->CreatePeerConnection(options, observer, std::move(callback));
|
||||
} else {
|
||||
impl_->CreatePeerConnection(observer, std::move(callback));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user