add wivrn+tcp scheme
This commit is contained in:
@@ -106,6 +106,7 @@
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="wivrn" />
|
||||
<data android:scheme="wivrn+tcp" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
@@ -959,6 +959,12 @@ application::application(application_info info) :
|
||||
server_address = data_string.substr(strlen("wivrn://"));
|
||||
}
|
||||
|
||||
if (data_string.starts_with("wivrn+tcp://"))
|
||||
{
|
||||
server_address = data_string.substr(strlen("wivrn+tcp://"));
|
||||
server_tcp_only = true;
|
||||
}
|
||||
|
||||
auto files_dir = ctx.call<jni::object<"java/io/File">>("getFilesDir");
|
||||
if (auto files_dir_path = files_dir.call<jni::string>("getAbsolutePath"))
|
||||
{
|
||||
|
||||
@@ -147,6 +147,7 @@ class application : public singleton<application>
|
||||
std::shared_ptr<wifi_lock> wifi;
|
||||
|
||||
std::string server_address;
|
||||
bool server_tcp_only = false;
|
||||
|
||||
std::mutex scene_stack_lock;
|
||||
std::vector<std::shared_ptr<scene>> scene_stack;
|
||||
@@ -377,6 +378,11 @@ public:
|
||||
return server_address;
|
||||
}
|
||||
|
||||
const bool & get_server_tcp_only() const
|
||||
{
|
||||
return server_tcp_only;
|
||||
}
|
||||
|
||||
static vk::raii::PhysicalDevice & get_physical_device()
|
||||
{
|
||||
return instance().vk_physical_device;
|
||||
|
||||
@@ -103,6 +103,7 @@ configuration::configuration(const std::string & path)
|
||||
.name = (std::string)i["pretty_name"],
|
||||
.hostname = (std::string)i["hostname"],
|
||||
.port = (int)i["port"].get_int64(),
|
||||
.tcp_only = i["tcp_only"].is_bool() && i["tcp_only"].get_bool(),
|
||||
.txt = {{"cookie", (std::string)i["cookie"]}}
|
||||
|
||||
}};
|
||||
@@ -143,6 +144,7 @@ void configuration::save()
|
||||
ss << "\"pretty_name\":" << json_string(server_data.service.name) << ",";
|
||||
ss << "\"hostname\":" << json_string(server_data.service.hostname) << ",";
|
||||
ss << "\"port\":" << server_data.service.port << ",";
|
||||
ss << "\"tcp_only\":" << std::boolalpha << server_data.service.tcp_only << ",";
|
||||
ss << "\"cookie\":" << json_string(cookie);
|
||||
ss << "},";
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ void real_main()
|
||||
.name = app.get_server_address(),
|
||||
.hostname = server_address,
|
||||
.port = port,
|
||||
.tcp_only = app.get_server_tcp_only(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -224,8 +224,8 @@ std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service servic
|
||||
{
|
||||
spdlog::debug("Trying address {}", address_string);
|
||||
|
||||
return std::visit([port = service.port](auto & address) {
|
||||
return std::make_unique<wivrn_session>(address, port);
|
||||
return std::visit([port = service.port, tcp_only = service.tcp_only](auto & address) {
|
||||
return std::make_unique<wivrn_session>(address, port, tcp_only);
|
||||
},
|
||||
address);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void init_stream(T & stream)
|
||||
} // namespace
|
||||
|
||||
template <typename T>
|
||||
void wivrn_session::handshake(T address)
|
||||
void wivrn_session::handshake(T address, bool tcp_only)
|
||||
{
|
||||
// Wait for handshake on control socket,
|
||||
// then send ours on stream or control socket,
|
||||
@@ -75,7 +75,7 @@ void wivrn_session::handshake(T address)
|
||||
try
|
||||
{
|
||||
auto h = std::get<to_headset::handshake>(*packet);
|
||||
if (h.stream_port > 0)
|
||||
if (h.stream_port > 0 && !tcp_only)
|
||||
{
|
||||
stream = decltype(stream)();
|
||||
stream.connect(address, h.stream_port);
|
||||
@@ -113,18 +113,18 @@ void wivrn_session::handshake(T address)
|
||||
}
|
||||
}
|
||||
|
||||
wivrn_session::wivrn_session(in6_addr address, int port) :
|
||||
wivrn_session::wivrn_session(in6_addr address, int port, bool tcp_only) :
|
||||
control(address, port), stream(-1), address(address)
|
||||
{
|
||||
char buffer[100];
|
||||
spdlog::info("Connection to {}:{}", inet_ntop(AF_INET6, &address, buffer, sizeof(buffer)), port);
|
||||
handshake(address);
|
||||
handshake(address, tcp_only);
|
||||
}
|
||||
|
||||
wivrn_session::wivrn_session(in_addr address, int port) :
|
||||
wivrn_session::wivrn_session(in_addr address, int port, bool tcp_only) :
|
||||
control(address, port), stream(-1), address(address)
|
||||
{
|
||||
char buffer[100];
|
||||
spdlog::info("Connection to {}:{}", inet_ntop(AF_INET, &address, buffer, sizeof(buffer)), port);
|
||||
handshake(address);
|
||||
handshake(address, tcp_only);
|
||||
}
|
||||
|
||||
@@ -31,13 +31,13 @@ class wivrn_session
|
||||
typed_socket<UDP, to_headset::packets, from_headset::packets> stream;
|
||||
|
||||
template <typename T>
|
||||
void handshake(T address);
|
||||
void handshake(T address, bool tcp_only);
|
||||
|
||||
public:
|
||||
std::variant<in_addr, in6_addr> address;
|
||||
|
||||
wivrn_session(in6_addr address, int port);
|
||||
wivrn_session(in_addr address, int port);
|
||||
wivrn_session(in6_addr address, int port, bool tcp_only);
|
||||
wivrn_session(in_addr address, int port, bool tcp_only);
|
||||
wivrn_session(const wivrn_session &) = delete;
|
||||
wivrn_session & operator=(const wivrn_session &) = delete;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
std::string name;
|
||||
std::string hostname;
|
||||
int port;
|
||||
bool tcp_only = false;
|
||||
|
||||
std::vector<std::variant<in_addr, in6_addr>> addresses;
|
||||
std::map<std::string, std::string> txt;
|
||||
|
||||
Reference in New Issue
Block a user