mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Internal change
PiperOrigin-RevId: 365062363
This commit is contained in:
@@ -32,6 +32,7 @@ namespace connections {
|
||||
namespace mediums {
|
||||
|
||||
constexpr absl::Duration ConnectionFlow::kTimeout;
|
||||
constexpr absl::Duration ConnectionFlow::kPeerConnectionTimeout;
|
||||
|
||||
namespace {
|
||||
// This is the same as the nearby data channel name.
|
||||
@@ -136,6 +137,7 @@ SessionDescriptionWrapper ConnectionFlow::CreateOffer() {
|
||||
return std::move(result.result());
|
||||
}
|
||||
|
||||
NEARBY_LOG(ERROR, "Failed to create offer: %d", result.exception());
|
||||
return SessionDescriptionWrapper();
|
||||
}
|
||||
|
||||
@@ -159,6 +161,7 @@ SessionDescriptionWrapper ConnectionFlow::CreateAnswer() {
|
||||
return std::move(result.result());
|
||||
}
|
||||
|
||||
NEARBY_LOG(ERROR, "Failed to create answer: %d", result.exception());
|
||||
return SessionDescriptionWrapper();
|
||||
}
|
||||
|
||||
@@ -175,7 +178,12 @@ bool ConnectionFlow::SetLocalSessionDescription(SessionDescriptionWrapper sdp) {
|
||||
peer_connection_->SetLocalDescription(observer, sdp.Release());
|
||||
|
||||
ExceptionOr<bool> result = success_future->Get(kTimeout);
|
||||
return result.ok() && result.result();
|
||||
bool success = result.ok() && result.result();
|
||||
if (!success) {
|
||||
NEARBY_LOG(ERROR, "Failed to set local session description: %d",
|
||||
result.exception());
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool ConnectionFlow::SetRemoteSessionDescription(
|
||||
@@ -190,7 +198,12 @@ bool ConnectionFlow::SetRemoteSessionDescription(
|
||||
peer_connection_->SetRemoteDescription(observer, sdp.Release());
|
||||
|
||||
ExceptionOr<bool> result = success_future->Get(kTimeout);
|
||||
return result.ok() && result.result();
|
||||
bool success = result.ok() && result.result();
|
||||
if (!success) {
|
||||
NEARBY_LOG(ERROR, "Failed to set remote description: %d",
|
||||
result.exception());
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool ConnectionFlow::OnOfferReceived(SessionDescriptionWrapper offer) {
|
||||
@@ -267,8 +280,13 @@ bool ConnectionFlow::InitPeerConnection(WebRtcMedium& webrtc_medium) {
|
||||
success_future.Set(true);
|
||||
});
|
||||
|
||||
ExceptionOr<bool> result = success_future.Get(kTimeout);
|
||||
return result.ok() && result.result();
|
||||
ExceptionOr<bool> result = success_future.Get(kPeerConnectionTimeout);
|
||||
bool success = result.ok() && result.result();
|
||||
if (!success) {
|
||||
NEARBY_LOG(ERROR, "Failed to create peer connection: %d",
|
||||
result.exception());
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
void ConnectionFlow::OnSignalingStable() {
|
||||
|
||||
@@ -133,6 +133,8 @@ class ConnectionFlow {
|
||||
|
||||
// TODO(bfranz): Consider whether this needs to be configurable per platform
|
||||
static constexpr absl::Duration kTimeout = absl::Milliseconds(250);
|
||||
static constexpr absl::Duration kPeerConnectionTimeout =
|
||||
absl::Milliseconds(2500);
|
||||
|
||||
bool InitPeerConnection(WebRtcMedium& webrtc_medium);
|
||||
|
||||
|
||||
@@ -223,6 +223,22 @@ TEST_F(ConnectionFlowTest, NullPeerConnection) {
|
||||
EXPECT_EQ(answerer, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(ConnectionFlowTest, PeerConnectionTimeout) {
|
||||
MediumEnvironment::Instance().SetUseValidPeerConnection(
|
||||
/*use_valid_peer_connection=*/true);
|
||||
WebRtcMedium medium1;
|
||||
std::unique_ptr<ConnectionFlow> flow1 = ConnectionFlow::Create(
|
||||
LocalIceCandidateListener(), DataChannelListener(), medium1);
|
||||
EXPECT_NE(flow1, nullptr);
|
||||
|
||||
// Attempt to trigger the 2.5s peer connection timeout.
|
||||
MediumEnvironment::Instance().SetPeerConnectionLatency(absl::Seconds(5));
|
||||
WebRtcMedium medium2;
|
||||
std::unique_ptr<ConnectionFlow> flow2 = ConnectionFlow::Create(
|
||||
LocalIceCandidateListener(), DataChannelListener(), medium2);
|
||||
EXPECT_EQ(flow2, nullptr);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace mediums
|
||||
} // namespace connections
|
||||
|
||||
Reference in New Issue
Block a user