mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
webrtc
PiperOrigin-RevId: 833487914
This commit is contained in:
committed by
Copybara-Service
parent
646c9aa1b5
commit
a241cbb7ac
@@ -42,6 +42,7 @@ cc_library(
|
||||
hdrs = ["account_manager.h"],
|
||||
visibility = [
|
||||
"//internal/account:__pkg__",
|
||||
"//internal/platform:__pkg__",
|
||||
"//internal/platform/implementation:__subpackages__",
|
||||
"//internal/test:__subpackages__",
|
||||
"//location/nearby/cpp/sharing/clients/cpp:__subpackages__",
|
||||
|
||||
@@ -61,6 +61,7 @@ objc_library(
|
||||
"preferences_manager.mm",
|
||||
"scheduled_executor.mm",
|
||||
"timer.mm",
|
||||
"webrtc.mm",
|
||||
"wifi_hotspot.mm",
|
||||
"wifi_lan.mm",
|
||||
],
|
||||
@@ -69,6 +70,7 @@ objc_library(
|
||||
"device_info.h",
|
||||
"preferences_manager.h",
|
||||
"timer.h",
|
||||
"webrtc.h",
|
||||
"wifi.h",
|
||||
"wifi_hotspot.h",
|
||||
"wifi_lan.h",
|
||||
@@ -91,6 +93,7 @@ objc_library(
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/synchronization",
|
||||
"@com_google_absl//absl/time",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/types:span",
|
||||
"//third_party/apple_frameworks:CoreBluetooth",
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
@@ -99,6 +102,18 @@ objc_library(
|
||||
"//internal/base:file_path",
|
||||
"//internal/base:files",
|
||||
"//internal/base:masker",
|
||||
"//internal/platform/implementation/apple/Mediums/Hotspot",
|
||||
"//internal/account",
|
||||
"//internal/crypto_cros",
|
||||
"//internal/platform/implementation:account_manager",
|
||||
"//internal/platform:comm",
|
||||
"//internal/platform:logging",
|
||||
"//internal/platform:types",
|
||||
"//internal/proto:tachyon_cc_proto",
|
||||
"//third_party/webrtc/files/stable/webrtc/api/task_queue:default_task_queue_factory",
|
||||
"//third_party/webrtc/files/stable/webrtc/api:create_modular_peer_connection_factory",
|
||||
"//third_party/webrtc/files/stable/webrtc/api:libjingle_peerconnection_api",
|
||||
"//third_party/webrtc/files/stable/webrtc/rtc_base:checks",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform/implementation:comm",
|
||||
"//internal/platform/implementation:platform",
|
||||
|
||||
@@ -71,6 +71,8 @@ objc_library(
|
||||
"//internal/platform/implementation/apple/Mediums/WiFiCommon",
|
||||
"//internal/platform/implementation/apple/Mediums/WiFiCommon/Tests:FakeNWFramework",
|
||||
"//third_party/apple_frameworks:CommonCrypto",
|
||||
"//third_party/apple_frameworks:CoreBluetooth",
|
||||
"//third_party/apple_frameworks:CoreLocation",
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
"//third_party/apple_frameworks:XCTest",
|
||||
"//third_party/objective_c/ocmock/v3:OCMock",
|
||||
|
||||
@@ -321,7 +321,7 @@ void GNCEnsureFileAtPath(std::string path) {
|
||||
|
||||
- (void)testCreateWebRtcMedium {
|
||||
auto webrtc_medium = nearby::api::ImplementationPlatform::CreateWebRtcMedium();
|
||||
XCTAssertEqual(webrtc_medium.get(), nullptr);
|
||||
XCTAssertNotEqual(webrtc_medium.get(), nullptr);
|
||||
}
|
||||
|
||||
- (void)testCreateInputFileWithPayloadID {
|
||||
|
||||
@@ -45,6 +45,10 @@
|
||||
#include "internal/platform/implementation/shared/file.h"
|
||||
#include "internal/platform/payload_id.h"
|
||||
|
||||
#ifndef NO_WEBRTC
|
||||
#import "internal/platform/implementation/apple/webrtc.h"
|
||||
#endif
|
||||
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
@@ -204,7 +208,9 @@ std::unique_ptr<WifiDirectMedium> ImplementationPlatform::CreateWifiDirectMedium
|
||||
}
|
||||
|
||||
#ifndef NO_WEBRTC
|
||||
std::unique_ptr<WebRtcMedium> ImplementationPlatform::CreateWebRtcMedium() { return nullptr; }
|
||||
std::unique_ptr<WebRtcMedium> ImplementationPlatform::CreateWebRtcMedium() {
|
||||
return std::make_unique<apple::WebRtcMedium>();
|
||||
}
|
||||
#endif
|
||||
|
||||
std::unique_ptr<AppLifecycleMonitor> ImplementationPlatform::CreateAppLifecycleMonitor(
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright 2025 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef PLATFORM_IMPL_APPLE_WEBRTC_H_
|
||||
#define PLATFORM_IMPL_APPLE_WEBRTC_H_
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/implementation/webrtc.h"
|
||||
#include "webrtc/api/peer_connection_interface.h"
|
||||
|
||||
namespace nearby::apple {
|
||||
|
||||
class WebRtcMedium : public api::WebRtcMedium {
|
||||
public:
|
||||
~WebRtcMedium() override = default;
|
||||
|
||||
// Gets the default two-letter country code associated with current locale.
|
||||
// For example, en_US locale resolves to "US".
|
||||
// This follows the ISO 3166-1 Alpha-2 standard.
|
||||
std::string GetDefaultCountryCode() override;
|
||||
|
||||
// Creates and returns a new webrtc::PeerConnectionInterface object via
|
||||
// |callback|.
|
||||
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,
|
||||
const location::nearby::connections::LocationHint& location_hint)
|
||||
override;
|
||||
};
|
||||
|
||||
} // namespace nearby::apple
|
||||
|
||||
#endif // PLATFORM_IMPL_APPLE_WEBRTC_H_
|
||||
@@ -0,0 +1,97 @@
|
||||
// Copyright 2025 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/platform/implementation/apple/webrtc.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/account/account_manager_impl.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/crypto.h"
|
||||
#include "internal/platform/implementation/account_manager.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/tachyon_express_signaling_messenger.h"
|
||||
#include "internal/proto/tachyon.pb.h"
|
||||
#include "internal/proto/tachyon_enums.proto.h"
|
||||
#include "webrtc/api/create_modular_peer_connection_factory.h"
|
||||
#include "webrtc/api/task_queue/default_task_queue_factory.h"
|
||||
|
||||
namespace nearby::apple {
|
||||
|
||||
std::string WebRtcMedium::GetDefaultCountryCode() {
|
||||
NSString* countryCode = [NSLocale.currentLocale objectForKey:NSLocaleCountryCode];
|
||||
if (countryCode) {
|
||||
return std::string([countryCode UTF8String]);
|
||||
}
|
||||
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) {
|
||||
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.
|
||||
webrtc::PeerConnectionInterface::IceServer ice_server;
|
||||
ice_server.urls.emplace_back("stun:stun.l.google.com:19302");
|
||||
ice_server.urls.emplace_back("stun:stun1.l.google.com:19302");
|
||||
ice_server.urls.emplace_back("stun:stun2.l.google.com:19302");
|
||||
ice_server.urls.emplace_back("stun:stun3.l.google.com:19302");
|
||||
ice_server.urls.emplace_back("stun:stun4.l.google.com:19302");
|
||||
rtc_config.servers.push_back(ice_server);
|
||||
|
||||
std::unique_ptr<webrtc::Thread> signaling_thread = webrtc::Thread::Create();
|
||||
signaling_thread->SetName("signaling_thread", nullptr);
|
||||
if (!signaling_thread->Start()) {
|
||||
callback(/*peer_connection=*/nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
webrtc::PeerConnectionDependencies dependencies(observer);
|
||||
webrtc::PeerConnectionFactoryDependencies factory_dependencies;
|
||||
factory_dependencies.signaling_thread = signaling_thread.release();
|
||||
|
||||
webrtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory =
|
||||
webrtc::CreateModularPeerConnectionFactory(std::move(factory_dependencies));
|
||||
if (options.has_value()) {
|
||||
peer_connection_factory->SetOptions(options.value());
|
||||
}
|
||||
webrtc::RTCErrorOr<webrtc::scoped_refptr<webrtc::PeerConnectionInterface>>
|
||||
peer_connection_or_error =
|
||||
peer_connection_factory->CreatePeerConnectionOrError(rtc_config, std::move(dependencies));
|
||||
if (peer_connection_or_error.ok()) {
|
||||
callback(peer_connection_or_error.MoveValue());
|
||||
} else {
|
||||
callback(/*peer_connection=*/nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<api::WebRtcSignalingMessenger> WebRtcMedium::GetSignalingMessenger(
|
||||
absl::string_view self_id, const location::nearby::connections::LocationHint& location_hint) {
|
||||
return std::make_unique<TachyonExpressSignalingMessenger>(self_id, location_hint);
|
||||
}
|
||||
|
||||
} // namespace nearby::apple
|
||||
@@ -60,7 +60,7 @@ void WebRtcSignalingMessenger::StopReceivingMessages() {
|
||||
|
||||
WebRtcMedium::~WebRtcMedium() { single_thread_executor_.Shutdown(); }
|
||||
|
||||
const std::string WebRtcMedium::GetDefaultCountryCode() { return "US"; }
|
||||
std::string WebRtcMedium::GetDefaultCountryCode() { return "US"; }
|
||||
|
||||
void WebRtcMedium::CreatePeerConnection(
|
||||
webrtc::PeerConnectionObserver* observer, PeerConnectionCallback callback) {
|
||||
|
||||
@@ -59,7 +59,7 @@ class WebRtcMedium : public api::WebRtcMedium {
|
||||
WebRtcMedium() = default;
|
||||
~WebRtcMedium() override;
|
||||
|
||||
const std::string GetDefaultCountryCode() override;
|
||||
std::string GetDefaultCountryCode() override;
|
||||
|
||||
// Creates and returns a new webrtc::PeerConnectionInterface object via
|
||||
// |callback|.
|
||||
|
||||
@@ -55,7 +55,7 @@ class WebRtcMedium {
|
||||
|
||||
// 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;
|
||||
virtual std::string GetDefaultCountryCode() = 0;
|
||||
|
||||
// Creates and returns a new webrtc::PeerConnectionInterface object via
|
||||
// |callback|.
|
||||
|
||||
@@ -57,7 +57,7 @@ bool WebRtcSignalingMessenger::StartReceivingMessages(
|
||||
// TODO(b/261663238): replace with real implementation.
|
||||
void WebRtcSignalingMessenger::StopReceivingMessages() {}
|
||||
|
||||
const std::string WebRtcMedium::GetDefaultCountryCode() {
|
||||
std::string WebRtcMedium::GetDefaultCountryCode() {
|
||||
wchar_t systemGeoName[LOCALE_NAME_MAX_LENGTH];
|
||||
|
||||
if (!GetUserDefaultGeoName(systemGeoName, LOCALE_NAME_MAX_LENGTH)) {
|
||||
|
||||
@@ -61,7 +61,7 @@ class WebRtcMedium : public api::WebRtcMedium {
|
||||
// Gets the default two-letter country code associated with current locale.
|
||||
// For example, en_US locale resolves to "US".
|
||||
// This follows the ISO 3166-1 Alpha-2 standard.
|
||||
const std::string GetDefaultCountryCode() override;
|
||||
std::string GetDefaultCountryCode() override;
|
||||
|
||||
// Creates and returns a new webrtc::PeerConnectionInterface object via
|
||||
// |callback|.
|
||||
|
||||
Reference in New Issue
Block a user