From ed2d8ab7c33e415e171a928bd39583adf145e8c9 Mon Sep 17 00:00:00 2001 From: hai007 Date: Mon, 20 Oct 2025 15:32:04 -0700 Subject: [PATCH] Wi-Fi Direct Service Implementation(3) PiperOrigin-RevId: 821831834 --- .../windows/wifi_direct_service.h | 2 ++ .../windows/wifi_direct_service_medium.cc | 35 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/internal/platform/implementation/windows/wifi_direct_service.h b/internal/platform/implementation/windows/wifi_direct_service.h index 9c0aeeb3..913f4111 100644 --- a/internal/platform/implementation/windows/wifi_direct_service.h +++ b/internal/platform/implementation/windows/wifi_direct_service.h @@ -167,6 +167,8 @@ class WifiDirectServiceMedium { IInspectable inspectable); fire_and_forget Watcher_DeviceStopped(DeviceWatcher sender, IInspectable inspectable); + std::string ip_address_local_; + std::string ip_address_remote_; absl::Mutex mutex_; absl::flat_hash_map 0) { + auto const& pair = endpoint_pairs.GetAt(0); + ip_address_local_ = + winrt::to_string(pair.LocalHostName().DisplayName()); + ip_address_remote_ = + winrt::to_string(pair.RemoteHostName().DisplayName()); + LOG(INFO) << "GO: Local IP: " << ip_address_local_ + << ", Remote IP: " << ip_address_remote_; + } else { + LOG(WARNING) << "GO: No connection endpoint pairs found."; + } + LOG(INFO) << "Service Address: " << winrt::to_string(session_.ServiceAddress()) << ", Service Name: " @@ -275,7 +289,7 @@ fire_and_forget WifiDirectServiceMedium::OnSessionRequested( LOG(INFO) << "GO: TryEnqueue: Session status changed"; }); }); - LOG(INFO) << "GC: Dispatch to UI thread to call ConnectAsync finish"; + LOG(INFO) << "GO: Dispatch to UI thread to call ConnectAsync finish"; } catch (std::exception exception) { LOG(ERROR) << __func__ << ": Failed to get session. Exception: " << exception.what(); @@ -360,7 +374,7 @@ fire_and_forget WifiDirectServiceMedium::Watcher_DeviceAdded( WiFiDirectServiceSession session = nullptr; if (kPin.empty()) { - session = service_.ConnectAsync().get(); // NOLINT + session = service_.ConnectAsync().get(); // NOLINT } else { auto prov_info = co_await service_.GetProvisioningInfoAsync( WiFiDirectServiceConfigurationMethod::PinEntry); @@ -383,6 +397,19 @@ fire_and_forget WifiDirectServiceMedium::Watcher_DeviceAdded( } LOG(INFO) << "GC: ConnectAsync succeeded"; session_ = std::move(session); + + auto endpoint_pairs = session_.GetConnectionEndpointPairs(); + if (endpoint_pairs.Size() > 0) { + auto const& pair = endpoint_pairs.GetAt(0); + ip_address_local_ = winrt::to_string(pair.LocalHostName().DisplayName()); + ip_address_remote_ = + winrt::to_string(pair.RemoteHostName().DisplayName()); + LOG(INFO) << "GC: Local IP: " << ip_address_local_ + << ", Remote IP: " << ip_address_remote_; + } else { + LOG(WARNING) << "GC: No connection endpoint pairs found."; + } + LOG(INFO) << "Service Address: " << winrt::to_string(session_.ServiceAddress()) << ", Service Name: " << winrt::to_string(session_.ServiceName())