[fix] enable web file browsing across control transports, refs #135

This commit is contained in:
dijunkun
2026-11-11 16:27:27 +08:00
parent ec2c5485a2
commit b2817d0adc
4 changed files with 15 additions and 11 deletions
@@ -151,7 +151,8 @@ void PeerEventHandler::OnReceiveDataBuffer(
source_id == runtime->clipboard_label_ ||
source_id == web_clipboard::kStream))
return;
if (source_id == runtime->control_data_label_ &&
// MiniRTC reports the browser's reliable control channel as data-stream.
if ((source_id == runtime->control_data_label_ || source_id == kWebControlStream) &&
runtime->transfers_.HandleBrowser(data, size, handler, remote_id)) return;
if (source_id == web_clipboard::kStream) {
runtime->clipboard_.ReceiveWeb(
@@ -463,7 +464,7 @@ void PeerEventHandler::OnReceiveDataBuffer(
}
if (remote_action.type == ControlType::host_infomation) {
if (source_id == runtime->control_data_label_) {
if (source_id == runtime->control_data_label_ || source_id == kWebControlStream) {
runtime->transfers_.SetBrowserSupport(handler, remote_id,
remote_action.i.supports_file_browser);
}
@@ -685,12 +685,12 @@ std::string GuiRuntime::BuildHostInformation(bool advertise_trust,
LOG_INFO("Local display [{}:{}]", i + 1, action.i.display_list[i]);
auto message = action.to_json();
FreeRemoteAction(action);
if (advertise_trust) {
auto information = nlohmann::json::parse(message);
information["device_trust_version"] = 1;
message = information.dump();
}
return message;
auto information = nlohmann::json::parse(message);
// Older desktop builds advertise native directory RPC, but their Web
// control router cannot carry it. Negotiate the Web route independently.
information["host_info"]["supports_web_file_browser"] = UserSessionFeaturesAvailable();
if (advertise_trust) information["device_trust_version"] = 1;
return information.dump();
}
void GuiRuntime::AnnounceHostCapabilities(const std::string& id) {
@@ -1,6 +1,7 @@
#include "application/gui_application.h"
#include <SDL3/SDL_timer.h>
#include <stream_names.h>
#include <web_clipboard_protocol.h>
#include <algorithm>
#include <tuple>
@@ -35,7 +36,7 @@ bool GuiRuntime::ForwardUserSessionData(const std::string& id,
const bool user_stream = stream == file_label_ || stream == file_feedback_label_ ||
stream == clipboard_label_ || stream == web_clipboard::kStream;
Json action;
if (stream == control_data_label_ && size <= 65536)
if ((stream == control_data_label_ || stream == kWebControlStream) && size <= 65536)
action = Json::parse(data, data + size, nullptr, false);
const auto type = action.is_object() ? action.value("type", Json{}) : Json{};
const bool host_info = type == static_cast<int>(ControlType::host_infomation);
@@ -54,7 +55,9 @@ bool GuiRuntime::ForwardUserSessionData(const std::string& id,
}
if (local_gui_ready_ && local_host_ &&
(user_stream || user_control || host_info || preview || audio)) {
if (!local_host_->Send({{"op", "data"}, {"id", id}, {"epoch", epoch}, {"stream", stream},
// IPC uses the native label; the Web alias belongs to the SCTP boundary.
const auto& forwarded_stream = stream == kWebControlStream ? control_data_label_ : stream;
if (!local_host_->Send({{"op", "data"}, {"id", id}, {"epoch", epoch}, {"stream", forwarded_stream},
{"bytes", Json::binary(std::vector<uint8_t>(data, data + size))}})) {
LOG_WARN(
"Cannot forward user-session data on {}; reconnecting local frontend",