Allow setting the PIN in the intent url
This commit is contained in:
+4
-4
@@ -79,15 +79,15 @@ include(VulkanVersion)
|
||||
|
||||
if (WIVRN_USE_SYSTEM_BOOST STREQUAL "AUTO")
|
||||
if(WIVRN_BUILD_DISSECTOR)
|
||||
find_package(Boost 1.84.0 COMPONENTS locale)
|
||||
find_package(Boost 1.84.0 COMPONENTS locale url)
|
||||
else()
|
||||
find_package(Boost 1.75.0 COMPONENTS locale)
|
||||
find_package(Boost 1.75.0 COMPONENTS locale url)
|
||||
endif()
|
||||
elseif(WIVRN_USE_SYSTEM_BOOST STREQUAL "ON")
|
||||
if(WIVRN_BUILD_DISSECTOR)
|
||||
find_package(Boost 1.84.0 REQUIRED COMPONENTS locale)
|
||||
find_package(Boost 1.84.0 REQUIRED COMPONENTS locale url)
|
||||
else()
|
||||
find_package(Boost 1.75.0 REQUIRED COMPONENTS locale)
|
||||
find_package(Boost 1.75.0 REQUIRED COMPONENTS locale url)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "*.glsl")
|
||||
target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS})
|
||||
wivrn_compile_glsl(wivrn ${VULKAN_SHADERS})
|
||||
|
||||
target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb Boost::locale)
|
||||
target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb Boost::url Boost::locale)
|
||||
|
||||
if (WIVRN_USE_LIBKTX)
|
||||
target_link_libraries(wivrn ktx_read)
|
||||
|
||||
+31
-27
@@ -33,6 +33,7 @@
|
||||
#include "xr/xr.h"
|
||||
#include <algorithm>
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/url/parse.hpp>
|
||||
#include <chrono>
|
||||
#include <ctype.h>
|
||||
#include <exception>
|
||||
@@ -975,37 +976,33 @@ extern "C" __attribute__((visibility("default"))) void Java_org_meumeu_wivrn_Mai
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool is_tcp_scheme(boost::core::string_view scheme)
|
||||
{
|
||||
if (scheme.empty() or scheme == "wivrn")
|
||||
return false;
|
||||
if (scheme == "wivrn+tcp")
|
||||
return true;
|
||||
throw std::runtime_error("invalid URI scheme " + std::string(scheme));
|
||||
}
|
||||
|
||||
void application::set_server_uri(std::string uri)
|
||||
{
|
||||
std::string server_address;
|
||||
bool server_tcp_only = false;
|
||||
|
||||
if (uri.starts_with("wivrn://"))
|
||||
{
|
||||
server_address = uri.substr(strlen("wivrn://"));
|
||||
}
|
||||
else if (uri.starts_with("wivrn+tcp://"))
|
||||
{
|
||||
server_address = uri.substr(strlen("wivrn+tcp://"));
|
||||
server_tcp_only = true;
|
||||
}
|
||||
|
||||
auto colon = server_address.rfind(":");
|
||||
int port = wivrn::default_port;
|
||||
if (colon != std::string::npos)
|
||||
{
|
||||
port = std::stoi(server_address.substr(colon + 1));
|
||||
server_address = server_address.substr(0, colon);
|
||||
}
|
||||
auto parse_result = boost::urls::parse_uri(uri);
|
||||
if (parse_result.has_error())
|
||||
throw boost::system::system_error(parse_result.error(), "failed to parse uri");
|
||||
if (not parse_result.has_value())
|
||||
throw std::runtime_error("failed to parse uri, empty result");
|
||||
|
||||
{
|
||||
std::unique_lock _{server_intent_mutex};
|
||||
server_intent = wivrn_discover::service{
|
||||
.name = "",
|
||||
.hostname = server_address,
|
||||
.port = port,
|
||||
.tcp_only = server_tcp_only,
|
||||
};
|
||||
server_intent =
|
||||
wivrn_discover::service{
|
||||
.name = "",
|
||||
.hostname = parse_result->host(),
|
||||
.port = parse_result->has_port() ? parse_result->port_number() : wivrn::default_port,
|
||||
.tcp_only = is_tcp_scheme(parse_result->scheme()),
|
||||
.pin = parse_result->password(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1027,7 +1024,14 @@ application::application(application_info info) :
|
||||
if (auto data_string = intent.call<jni::string>("getDataString"))
|
||||
{
|
||||
spdlog::info("Started with intent {}", (std::string)data_string);
|
||||
set_server_uri(data_string);
|
||||
try
|
||||
{
|
||||
set_server_uri(data_string);
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("failed to set server uri: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
auto files_dir = ctx.call<jni::object<"java/io/File">>("getFilesDir");
|
||||
|
||||
@@ -355,7 +355,7 @@ public:
|
||||
{
|
||||
std::unique_lock _{instance().server_intent_mutex};
|
||||
|
||||
std::optional<wivrn_discover::service> intent = instance().server_intent;
|
||||
auto intent = instance().server_intent;
|
||||
instance().server_intent.reset();
|
||||
|
||||
return intent;
|
||||
|
||||
@@ -277,12 +277,12 @@ std::unique_ptr<wivrn_session> scenes::lobby::connect_to_session(wivrn_discover:
|
||||
{
|
||||
spdlog::debug("Connection to {}", address_string);
|
||||
|
||||
return std::visit([this, port = service.port, tcp_only = service.tcp_only](auto & address) {
|
||||
return std::make_unique<wivrn_session>(address, port, tcp_only, keypair, [&](int fd) {
|
||||
return std::visit([this, &service](auto & address) {
|
||||
return std::make_unique<wivrn_session>(address, service.port, service.tcp_only, keypair, [&](int fd) {
|
||||
auto request = pin_request.lock();
|
||||
request->pin_requested = true;
|
||||
request->pin_cancelled = false;
|
||||
request->pin = "";
|
||||
request->pin = service.pin;
|
||||
pin_buffer = "";
|
||||
|
||||
while (not request.wait_for(500ms, [&]() { return request->pin != "" or request->pin_cancelled; }))
|
||||
@@ -705,6 +705,7 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
{
|
||||
if (auto intent = application::get_intent())
|
||||
{
|
||||
pin_request.lock()->pin = intent->pin;
|
||||
connect(configuration::server_data{
|
||||
.manual = true,
|
||||
.service = *intent,
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
std::vector<std::variant<in_addr, in6_addr>> addresses;
|
||||
std::map<std::string, std::string> txt;
|
||||
std::chrono::steady_clock::time_point ttl;
|
||||
std::string pin;
|
||||
};
|
||||
|
||||
static inline const std::chrono::milliseconds poll_min_time{500};
|
||||
|
||||
Reference in New Issue
Block a user