[refactor] migrate clients to unified MiniRTC APIs

This commit is contained in:
dijunkun
2026-11-07 00:41:25 +08:00
parent 1a12a1d7d5
commit 84466ccea4
39 changed files with 498 additions and 498 deletions
@@ -495,25 +495,25 @@ std::optional<int> ParsePort(const slint::SharedString& text) {
return port;
}
std::string ConnectionStatusText(ConnectionStatus status, int language) {
std::string ConnectionStatusText(MiniRtcConnectionStatus status, int language) {
switch (status) {
case ConnectionStatus::Connected:
case MiniRtcConnectionStatus::MiniRtcConnectionConnected:
return localization::p2p_connected[language];
case ConnectionStatus::Connecting:
case MiniRtcConnectionStatus::MiniRtcConnectionConnecting:
return localization::p2p_connecting[language];
case ConnectionStatus::Gathering:
case MiniRtcConnectionStatus::MiniRtcConnectionGathering:
return localization::p2p_gathering[language];
case ConnectionStatus::Disconnected:
case MiniRtcConnectionStatus::MiniRtcConnectionDisconnected:
return localization::p2p_disconnected[language];
case ConnectionStatus::NoSuchTransmissionId:
case MiniRtcConnectionStatus::MiniRtcConnectionNoSuchTransmissionId:
return localization::no_such_id[language];
case ConnectionStatus::IncorrectPassword:
case MiniRtcConnectionStatus::MiniRtcConnectionIncorrectPassword:
return localization::reinput_password[language];
case ConnectionStatus::Closed:
case MiniRtcConnectionStatus::MiniRtcConnectionClosed:
return localization::p2p_closed[language];
case ConnectionStatus::RemoteUnavailable:
case MiniRtcConnectionStatus::MiniRtcConnectionRemoteUnavailable:
return localization::device_offline[language];
case ConnectionStatus::Failed:
case MiniRtcConnectionStatus::MiniRtcConnectionFailed:
default:
return localization::p2p_failed[language];
}
@@ -1913,7 +1913,7 @@ void GuiApplication::BindMainCallbacks(bool gallery_window) {
main->on_recent_disconnect([this](slint::SharedString id) {
const std::string remote_id(id);
if (auto props = FindRemoteSession(remote_id);
props && props->connection_status_ == ConnectionStatus::Connected &&
props && props->connection_status_ == MiniRtcConnectionStatus::MiniRtcConnectionConnected &&
!props->closing_) {
CloseStreamTab(props->remote_id_);
SyncMainWindow();
@@ -2057,9 +2057,9 @@ void GuiApplication::BindMainCallbacks(bool gallery_window) {
main->on_connection_acknowledge([this] {
const auto props = FindRemoteSession(ui_->connection_dialog_remote_id);
if (props) {
const ConnectionStatus status = props->connection_status_.load();
if (status == ConnectionStatus::NoSuchTransmissionId ||
status == ConnectionStatus::RemoteUnavailable) {
const MiniRtcConnectionStatus status = props->connection_status_.load();
if (status == MiniRtcConnectionStatus::MiniRtcConnectionNoSuchTransmissionId ||
status == MiniRtcConnectionStatus::MiniRtcConnectionRemoteUnavailable) {
CloseStreamTab(props->remote_id_);
re_enter_remote_id_ = true;
}
@@ -2216,13 +2216,13 @@ void GuiApplication::BindStreamCallbacks() {
action.type = ControlType::display_id;
action.d = index;
const std::string message = action.to_json();
SendReliableDataFrame(props->peer_, message.c_str(), message.size(),
MiniRtcSendReliableDataFrame(props->peer_, message.c_str(), message.size(),
props->control_data_label_.c_str());
});
stream->on_send_shortcut([this](slint::SharedString shortcut) {
auto props = SelectedSession();
if (!props || !props->peer_ || !props->control_mouse_ ||
props->connection_status_.load() != ConnectionStatus::Connected) {
props->connection_status_.load() != MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
return;
}
const std::string name(shortcut);
@@ -2237,13 +2237,13 @@ void GuiApplication::BindStreamCallbacks() {
? ServiceCommandFlag::send_sas
: ServiceCommandFlag::lock_workstation;
const std::string message = action.to_json();
SendReliableDataFrame(props->peer_, message.c_str(), message.size(),
MiniRtcSendReliableDataFrame(props->peer_, message.c_str(), message.size(),
props->control_data_label_.c_str());
});
const auto send_privacy = [this](bool relock) {
auto props = SelectedSession();
if (!props || !props->peer_ || (!relock && !props->control_mouse_) ||
props->connection_status_.load() != ConnectionStatus::Connected) return;
props->connection_status_.load() != MiniRtcConnectionStatus::MiniRtcConnectionConnected) return;
RemoteAction action{};
action.type = ControlType::privacy_command;
{
@@ -2265,7 +2265,7 @@ void GuiApplication::BindStreamCallbacks() {
props->privacy_request_revision_ = status.revision;
}
const auto message = action.to_json();
if (SendReliableDataFrame(props->peer_, message.data(), message.size(),
if (MiniRtcSendReliableDataFrame(props->peer_, message.data(), message.size(),
props->control_data_label_.c_str()) != 0) {
std::lock_guard lock(props->privacy_status_mutex_);
props->privacy_command_pending_ = false;
@@ -2295,7 +2295,7 @@ void GuiApplication::BindStreamCallbacks() {
int preference) {
auto props = SelectedSession();
if (!props || !props->peer_ ||
props->connection_status_.load() != ConnectionStatus::Connected)
props->connection_status_.load() != MiniRtcConnectionStatus::MiniRtcConnectionConnected)
return;
RemoteAction action{};
action.type = ControlType::video_settings;
@@ -2308,7 +2308,7 @@ void GuiApplication::BindStreamCallbacks() {
if (!props->video_settings_supported_) return;
action.vs.request_id = props->video_settings_.request_id + 1;
const auto message = action.to_json();
if (SendReliableDataFrame(props->peer_, message.data(), message.size(),
if (MiniRtcSendReliableDataFrame(props->peer_, message.data(), message.size(),
props->control_data_label_.c_str()) != 0)
return;
props->video_settings_ = action.vs;
@@ -2773,7 +2773,7 @@ void GuiApplication::ShareLocalCursorState() {
std::shared_lock lock(connection_status_mutex_);
connected_controllers.reserve(connection_status_.size());
for (const auto& [remote_id, status] : connection_status_) {
if (status == ConnectionStatus::Connected) {
if (status == MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
connected_controllers.push_back(remote_id);
}
}
@@ -2997,7 +2997,7 @@ bool GuiApplication::RequestPasswordChange(const std::string &password) {
{"request_id", request_id},
{"new_password", password}};
const std::string message = request.dump();
if (SendSignalMessage(peer_, message.data(), message.size()) != 0) {
if (MiniRtcSendSignalMessage(peer_, message.data(), message.size()) != 0) {
{
std::lock_guard<std::mutex> lock(password_change_mutex_);
password_change_pending_ = false;
@@ -3128,7 +3128,7 @@ void GuiApplication::HandleCredentialRecovery() {
}
const auto message = nlohmann::json{{"type", "change_password"},
{"request_id", request_id}, {"new_password", password}}.dump();
if (SendSignalMessage(peer_, message.data(), message.size()) != 0) {
if (MiniRtcSendSignalMessage(peer_, message.data(), message.size()) != 0) {
std::lock_guard lock(password_change_mutex_);
password_change_result_ready_ = true;
password_change_result_uncertain_ = true;
@@ -3204,7 +3204,7 @@ void GuiApplication::SyncAnnouncements() {
const auto request = announcements_.TakePendingRequest();
if (!request.is_null()) {
const auto payload = request.dump();
if (!peer_ || SendSignalMessage(peer_, payload.data(), payload.size()) != 0)
if (!peer_ || MiniRtcSendSignalMessage(peer_, payload.data(), payload.size()) != 0)
announcements_.Failed(request["request_id"]);
}
if (ui_->announcement_version == announcements_.Version()) return;
@@ -3315,7 +3315,7 @@ void GuiApplication::SyncMainWindow() {
main->set_signal_connected(signal_online);
main->set_signal_reconnecting(signal_reconnecting);
main->set_signal_tls_error(signal_status_ ==
SignalStatus::SignalTlsCertError);
MiniRtcSignalStatus::MiniRtcSignalTlsCertError);
main->set_update_available(update_available_);
switch (update_checker_->status()) {
case UpdateChecker::Status::Idle:
@@ -3389,7 +3389,7 @@ void GuiApplication::SyncMainWindow() {
}
const auto is_connected = [this](const std::string& id) {
const auto props = FindRemoteSession(id);
return props && props->connection_status_ == ConnectionStatus::Connected &&
return props && props->connection_status_ == MiniRtcConnectionStatus::MiniRtcConnectionConnected &&
!props->closing_;
};
const auto preview_size = ui_->recent_preview_resolution.Update(
@@ -3512,8 +3512,8 @@ void GuiApplication::SyncConnectionDialog() {
ui_->connection_password_initialized = false;
}
ui_->connection_dialog_remote_id = props->remote_id_;
const ConnectionStatus status = props->connection_status_.load();
if (status == ConnectionStatus::Connected && !ui_->gallery_auth_id.empty()) {
const MiniRtcConnectionStatus status = props->connection_status_.load();
if (status == MiniRtcConnectionStatus::MiniRtcConnectionConnected && !ui_->gallery_auth_id.empty()) {
ui_->gallery_auth_id.clear();
show_connection_status_window_ = false;
ui_->main->set_connection_dialog_open(false);
@@ -3522,9 +3522,9 @@ void GuiApplication::SyncConnectionDialog() {
}
const auto auth = props->connection_auth_.Get();
const bool password_required = auth.password_required ||
(status == ConnectionStatus::IncorrectPassword && auth.validating);
(status == MiniRtcConnectionStatus::MiniRtcConnectionIncorrectPassword && auth.validating);
const bool pending = !password_required &&
(status == ConnectionStatus::Connecting || status == ConnectionStatus::Gathering);
(status == MiniRtcConnectionStatus::MiniRtcConnectionConnecting || status == MiniRtcConnectionStatus::MiniRtcConnectionGathering);
std::string text;
if (password_required) {
text = auth.validating
@@ -3855,7 +3855,7 @@ void GuiApplication::SyncStreamWindow() {
tab.title = UiText(
props->remote_host_name_.empty() ? id : props->remote_host_name_);
tab.connected =
props->connection_status_.load() == ConnectionStatus::Connected;
props->connection_status_.load() == MiniRtcConnectionStatus::MiniRtcConnectionConnected;
tabs_by_id.emplace(id, std::move(tab));
}
}
@@ -3905,10 +3905,10 @@ void GuiApplication::SyncStreamWindow() {
if (!props) {
return;
}
const ConnectionStatus status = props->connection_status_.load();
const MiniRtcConnectionStatus status = props->connection_status_.load();
bool remote_update_available = false;
HostPlatform remote_platform = HostPlatform::Unknown;
if (status == ConnectionStatus::Connected) {
if (status == MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
std::lock_guard lock(props->remote_version_mutex_);
remote_platform = props->remote_platform_;
// Wait for host_info: a version still in transit is not a legacy peer.
@@ -3925,14 +3925,14 @@ void GuiApplication::SyncStreamWindow() {
SetStreamKeyboardFocus(false);
}
const bool waiting_for_frame =
status == ConnectionStatus::Connected &&
status == MiniRtcConnectionStatus::MiniRtcConnectionConnected &&
!(*ui_->stream)->get_has_frame();
// Once the peer is connected, the frame-waiting hint replaces the
// connection status. Keeping these states mutually exclusive also avoids a
// transient overlap when both properties are synchronized in one tick.
(*ui_->stream)
->set_status_text(UiText(
status == ConnectionStatus::Connected
status == MiniRtcConnectionStatus::MiniRtcConnectionConnected
? std::string{}
: ConnectionStatusText(status, localization_language_index_)));
(*ui_->stream)
@@ -3949,7 +3949,7 @@ void GuiApplication::SyncStreamWindow() {
status, props->privacy_status_received_, props->privacy_command_pending_,
now - props->privacy_status_tick_, now - props->privacy_command_tick_);
const bool connected =
props->connection_status_.load() == ConnectionStatus::Connected;
props->connection_status_.load() == MiniRtcConnectionStatus::MiniRtcConnectionConnected;
(*ui_->stream)->set_privacy_unlock_visible(connected && props->privacy_unlock_notice_);
(*ui_->stream)->set_privacy_can_lock(connected && props->privacy_desktop_available_ &&
props->privacy_status_received_ && status.supported &&
@@ -3977,7 +3977,7 @@ void GuiApplication::SyncStreamWindow() {
{
std::lock_guard lock(props->remote_cursor_state_mutex_);
remote_cursor_active =
status == ConnectionStatus::Connected && props->control_mouse_ &&
status == MiniRtcConnectionStatus::MiniRtcConnectionConnected && props->control_mouse_ &&
props->remote_cursor_state_received_;
if (remote_cursor_active) {
remote_cursor_shape = static_cast<int>(
@@ -3998,7 +3998,7 @@ void GuiApplication::SyncStreamWindow() {
props->video_settings_.request_id = request_id;
}
(*ui_->stream)
->set_video_settings_enabled(status == ConnectionStatus::Connected &&
->set_video_settings_enabled(status == MiniRtcConnectionStatus::MiniRtcConnectionConnected &&
props->video_settings_supported_);
(*ui_->stream)
->set_video_settings_feedback(UiText(
@@ -4035,13 +4035,13 @@ void GuiApplication::SyncStreamWindow() {
const auto net = props->net_traffic_stats_.Load();
const auto codecs = props->net_traffic_stats_.LoadVideoCodecs();
(*ui_->stream)->set_stats_encoder(UiText(
status == ConnectionStatus::Connected && !codecs.remote_encoder.empty()
status == MiniRtcConnectionStatus::MiniRtcConnectionConnected && !codecs.remote_encoder.empty()
? codecs.remote_encoder : "—"));
(*ui_->stream)->set_stats_decoder(UiText(
status == ConnectionStatus::Connected && !codecs.local_decoder.empty()
status == MiniRtcConnectionStatus::MiniRtcConnectionConnected && !codecs.local_decoder.empty()
? codecs.local_decoder : "—"));
(*ui_->stream)->set_stats_encryption_enabled(
status == ConnectionStatus::Connected && net.srtp_active);
status == MiniRtcConnectionStatus::MiniRtcConnectionConnected && net.srtp_active);
std::vector<ui::NetworkStatsRow> stats_rows;
stats_rows.reserve(4);
const auto append_stats_row = [&](const std::string& label,
@@ -4067,7 +4067,7 @@ void GuiApplication::SyncStreamWindow() {
props->video_height_)));
(*ui_->stream)
->set_stats_connection_mode(
UiText(props->traversal_mode_ == TraversalMode::P2P
UiText(props->traversal_mode_ == MiniRtcTraversalMode::MiniRtcTraversalP2P
? localization::connection_mode_direct
[localization_language_index_]
: localization::connection_mode_relay
@@ -4095,7 +4095,7 @@ void GuiApplication::SyncStreamWindow() {
}
(*ui_->stream)->set_stats_fps(UiText(std::to_string(props->fps_)));
if (!props->net_traffic_stats_button_pressed_ ||
status != ConnectionStatus::Connected) {
status != MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
props->video_latency_snapshot_.reset();
} else if (refresh_stats) {
props->video_latency_snapshot_ = props->video_latency_->Get(fps_now);
@@ -4109,7 +4109,7 @@ void GuiApplication::SyncStreamWindow() {
: "—"));
const auto display_rtt = props->net_traffic_stats_.SmoothedRttMs(fps_now);
const bool rtt_available = props->net_traffic_stats_button_pressed_ &&
status == ConnectionStatus::Connected &&
status == MiniRtcConnectionStatus::MiniRtcConnectionConnected &&
display_rtt.has_value();
std::string connection_latency = "—";
if (rtt_available) {
@@ -4119,7 +4119,7 @@ void GuiApplication::SyncStreamWindow() {
: std::to_string(static_cast<int>(std::lround(*display_rtt))) + " ms";
}
(*ui_->stream)->set_stats_connection_latency(UiText(connection_latency));
if (refresh_stats && status == ConnectionStatus::Connected) {
if (refresh_stats && status == MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
LOG_DEBUG("Latency stats: remote={} video_ms={} video_samples={} "
"rtt_raw_ms={} rtt_display_ms={}",
props->remote_id_, latency ? latency->average_ms : -1,
@@ -4416,7 +4416,7 @@ void GuiApplication::SyncServerWindow() {
has_connected_controller =
std::any_of(connection_status_.begin(), connection_status_.end(),
[](const auto& entry) {
return entry.second == ConnectionStatus::Connected;
return entry.second == MiniRtcConnectionStatus::MiniRtcConnectionConnected;
});
}
@@ -4478,7 +4478,7 @@ void GuiApplication::SyncServerWindow() {
std::shared_lock lock(connection_status_mutex_);
controllers.reserve(connection_status_.size());
for (const auto& [id, status] : connection_status_) {
if (status != ConnectionStatus::Connected) continue;
if (status != MiniRtcConnectionStatus::MiniRtcConnectionConnected) continue;
const auto host = connection_host_names_.find(id);
const std::string name =
host != connection_host_names_.end() && !host->second.empty()
@@ -5033,12 +5033,12 @@ void GuiApplication::ApplySettingsFromConfig(bool reconnect) {
} else {
const bool av1 = config_center_->GetVideoEncodeFormat() ==
ConfigCenter::VIDEO_ENCODE_FORMAT::AV1;
const auto turn = static_cast<TurnMode>(config_center_->GetTurnMode());
const auto turn = static_cast<MiniRtcTurnMode>(config_center_->GetTurnMode());
if (av1 != params_.av1_encoding || turn != params_.turn_mode) {
// Update the listening peer for incoming connections and the template
// copied by ConnectTo for outgoing connections. Existing sessions retain
// the codec/ICE snapshot with which they negotiated.
if (!peer_ || UpdateConnectionSettings(peer_, true, av1, turn) == 0) {
if (!peer_ || MiniRtcUpdateConnectionSettings(peer_, true, av1, turn) == 0) {
params_.av1_encoding = av1;
params_.turn_mode = turn;
} else {
@@ -5139,7 +5139,7 @@ void GuiApplication::SelectStreamTab(int index) {
start_keyboard_capturer_ = selected_session &&
selected_session->control_mouse_ &&
selected_session->connection_status_.load() ==
ConnectionStatus::Connected;
MiniRtcConnectionStatus::MiniRtcConnectionConnected;
}
if (clipboard_resumed) {
// Flush a copy made in another local app before the next paste shortcut,
@@ -5366,7 +5366,7 @@ void GuiApplication::SendKeyInput(const std::string& text, bool pressed,
(void)meta;
auto props = SelectedSession();
if (!props || !props->peer_ || !props->control_mouse_ ||
props->connection_status_.load() != ConnectionStatus::Connected) {
props->connection_status_.load() != MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
return;
}
@@ -5423,7 +5423,7 @@ void GuiApplication::SyncAudioPlayback() {
std::shared_lock lock(remote_sessions_mutex_);
for (const auto& [id, props] : remote_sessions_) {
const bool allowed = !props->closing_ &&
props->connection_status_ == ConnectionStatus::Connected &&
props->connection_status_ == MiniRtcConnectionStatus::MiniRtcConnectionConnected &&
props->audio_capture_button_pressed_ &&
((wall_visible && props->wall_managed_) ||
(stream_active && props->tab_opened_ && props->tab_selected_));
@@ -5898,7 +5898,7 @@ void GuiApplication::GalleryAction(const std::string& action,
auto props = FindRemoteSession(value);
if (value != ui_->gallery_focus || !props || !props->peer_ ||
props->closing_ ||
props->connection_status_ != ConnectionStatus::Connected)
props->connection_status_ != MiniRtcConnectionStatus::MiniRtcConnectionConnected)
return;
{
std::lock_guard lock(props->gallery_frame_mutex_);
@@ -5955,7 +5955,7 @@ void GuiApplication::GalleryAction(const std::string& action,
for (const auto& id : ids) {
if (auto props = FindRemoteSession(id);
props && !props->closing_ &&
props->connection_status_ == ConnectionStatus::Connected) {
props->connection_status_ == MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
if (action == "mute") {
MuteRemoteAudio(props);
} else {
@@ -6236,7 +6236,7 @@ void GuiApplication::SyncGallery() {
// control. Followers can report different shapes without replacing it.
auto controlled = FindRemoteSession(ui_->gallery_control_id);
if (!visible || !controlled || controlled->closing_ ||
controlled->connection_status_ != ConnectionStatus::Connected) {
controlled->connection_status_ != MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
ReleaseControl();
} else {
HostPlatform platform;
@@ -6330,7 +6330,7 @@ void GuiApplication::SyncGallery() {
std::shared_lock lock(remote_sessions_mutex_);
for (const auto& [id, props] : remote_sessions_)
if (props && !props->lan_session_ && !props->closing_ &&
props->connection_status_ == ConnectionStatus::Connected)
props->connection_status_ == MiniRtcConnectionStatus::MiniRtcConnectionConnected)
connected_ids.push_back(id);
}
std::sort(connected_ids.begin(), connected_ids.end());
@@ -6338,15 +6338,15 @@ void GuiApplication::SyncGallery() {
for (const auto& id : connected_ids) {
const auto props = FindRemoteSession(id);
if (!props || props->closing_ ||
props->connection_status_ != ConnectionStatus::Connected)
props->connection_status_ != MiniRtcConnectionStatus::MiniRtcConnectionConnected)
continue;
ui::GalleryNetworkDevice device{};
device.name = UiText(name(id));
device.id = UiText(FormatPeerId(id.c_str()));
const auto mode = props->traversal_mode_.load();
device.mode = UiText(mode == TraversalMode::P2P
device.mode = UiText(mode == MiniRtcTraversalMode::MiniRtcTraversalP2P
? tr("直连")
: mode == TraversalMode::UnknownMode
: mode == MiniRtcTraversalMode::MiniRtcTraversalUnknown
? tr("等待统计")
: tr("中继"));
device.inbound = device.outbound = device.loss = "—";
@@ -6374,7 +6374,7 @@ void GuiApplication::SyncGallery() {
// Missing/stale reports cannot confirm either encrypted or plaintext.
device.encryption_known = has_report;
device.encryption_enabled = has_report && stats.srtp_active;
if (mode != TraversalMode::UnknownMode && has_report) {
if (mode != MiniRtcTraversalMode::MiniRtcTraversalUnknown && has_report) {
device.inbound = UiText(FormatBitrate(stats.total_inbound_stats.bitrate));
device.outbound = UiText(FormatBitrate(stats.total_outbound_stats.bitrate));
// MiniRTC's total loss is a sum of media fractions, not an aggregate.
@@ -6416,14 +6416,14 @@ void GuiApplication::SyncGallery() {
MuteRemoteAudio(props);
}
const auto status = props ? props->connection_status_.load()
: ConnectionStatus::Closed;
: MiniRtcConnectionStatus::MiniRtcConnectionClosed;
const bool usable = props && props->peer_ && !props->closing_;
const bool connecting = usable &&
(status == ConnectionStatus::Connecting ||
status == ConnectionStatus::Gathering);
(status == MiniRtcConnectionStatus::MiniRtcConnectionConnecting ||
status == MiniRtcConnectionStatus::MiniRtcConnectionGathering);
if (!signal_connected_)
operation.state = OperationState::Finished;
else if (!(usable && status == ConnectionStatus::Connected) &&
else if (!(usable && status == MiniRtcConnectionStatus::MiniRtcConnectionConnected) &&
(!connecting || operation.password)) {
std::string password = operation.password.value_or("");
bool remember = operation.remember_password;
@@ -6449,7 +6449,7 @@ void GuiApplication::SyncGallery() {
operation.password.reset();
}
} else if (!props || !props->peer_ ||
props->connection_status_ != ConnectionStatus::Connected) {
props->connection_status_ != MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
operation.state = OperationState::Finished;
} else if (operation.action == "file") {
if (!transfers_.ProcessSelectedFile(operation.file, props,
@@ -6472,12 +6472,12 @@ void GuiApplication::SyncGallery() {
else if (operation.action == "connect") {
const auto status = props->connection_status_.load();
const auto auth = props->connection_auth_.Get();
if (status == ConnectionStatus::Connected)
if (status == MiniRtcConnectionStatus::MiniRtcConnectionConnected)
operation.state = OperationState::Finished;
else if (auth.password_required && !auth.validating)
operation.state = OperationState::AwaitingPassword;
else if (status != ConnectionStatus::Connecting &&
status != ConnectionStatus::Gathering && !auth.validating)
else if (status != MiniRtcConnectionStatus::MiniRtcConnectionConnecting &&
status != MiniRtcConnectionStatus::MiniRtcConnectionGathering && !auth.validating)
operation.state = OperationState::Finished;
else if (operation.state == OperationState::AwaitingPassword) {
operation.state = OperationState::Running;
@@ -6486,7 +6486,7 @@ void GuiApplication::SyncGallery() {
operation.state = OperationState::Finished;
CloseStreamTab(operation.id);
}
} else if (props->connection_status_ != ConnectionStatus::Connected)
} else if (props->connection_status_ != MiniRtcConnectionStatus::MiniRtcConnectionConnected)
operation.state = OperationState::Finished;
else if (operation.action == "file") {
std::lock_guard lock(props->file_transfer_.file_transfer_list_mutex_);
@@ -6594,7 +6594,7 @@ void GuiApplication::SyncGallery() {
tile.host_name = UiText(props->remote_host_name_);
}
tile.connected = props &&
props->connection_status_ == ConnectionStatus::Connected &&
props->connection_status_ == MiniRtcConnectionStatus::MiniRtcConnectionConnected &&
!props->closing_;
const auto online = device_presence_cache_.GetOnline(id);
tile.online = tile.connected || online.value_or(false);
@@ -6648,7 +6648,7 @@ void GuiApplication::SyncGallery() {
};
for (size_t i = 0; i < ids.size(); ++i) {
const auto props = FindRemoteSession(ids[i]);
if (props && props->connection_status_ == ConnectionStatus::Connected &&
if (props && props->connection_status_ == MiniRtcConnectionStatus::MiniRtcConnectionConnected &&
!props->closing_) {
++connected;
}
@@ -6684,7 +6684,7 @@ void GuiApplication::SyncGallery() {
device.name = UiText(name(id));
const auto props = FindRemoteSession(id);
device.connected = props && !props->closing_ &&
props->connection_status_ == ConnectionStatus::Connected;
props->connection_status_ == MiniRtcConnectionStatus::MiniRtcConnectionConnected;
if (device.connected) {
selected_audio_available = true;
selected_audio_muted &= !props->audio_capture_button_pressed_;
@@ -6738,7 +6738,7 @@ void GuiApplication::SyncGallery() {
props->gallery_rgba_.reset();
}
if (props->preview_subscription_supported_ &&
props->connection_status_ == ConnectionStatus::Connected) {
props->connection_status_ == MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
if (wall_mode && !ui_->gallery_hidden_active_ids.count(id))
props->wall_managed_ = true;
// Keep session quality and audio; wall bandwidth, resolution and
@@ -6814,7 +6814,7 @@ void GuiApplication::SyncGallery() {
demand.request_id = ++props->preview_request_;
if (!demand.request_id) demand.request_id = ++props->preview_request_;
const auto message = demand.ToJson().dump();
if (SendReliableDataFrame(props->peer_, message.data(), message.size(),
if (MiniRtcSendReliableDataFrame(props->peer_, message.data(), message.size(),
props->control_data_label_.c_str()) == 0)
props->preview_requested_ = demand;
props->preview_request_at_ = now;
@@ -359,7 +359,7 @@ void ClipboardController::SendDeferredLocalText() {
return;
}
const int ret = SendReliableDataFrame(
const int ret = MiniRtcSendReliableDataFrame(
session->peer_, last_text_.data(), last_text_.size(),
session->clipboard_label_.c_str());
if (ret != 0) {
@@ -388,7 +388,7 @@ int ClipboardController::SendToPeers(const std::string &text) {
}
const int ret =
SendReliableDataFrame(props->peer_, text.data(), text.size(),
MiniRtcSendReliableDataFrame(props->peer_, text.data(), text.size(),
props->clipboard_label_.c_str());
if (ret != 0) {
LOG_WARN("Failed to send clipboard data to peer [{}], ret={}",
@@ -48,9 +48,9 @@ SessionDeviceManager::SessionDeviceManager(GuiRuntime &owner)
frame.size = size;
for (const auto& id : owner_.ConnectedControllers())
owner_.WithController(
id, [&](PeerPtr* peer, const std::string& wire) {
frame.captured_timestamp = GetSystemTimeMicros(peer);
return SendAudioFrameToPeer(peer, &frame,
id, [&](MiniRtcPeerPtr* peer, const std::string& wire) {
frame.captured_timestamp = MiniRtcGetSystemTimeMicros(peer);
return MiniRtcSendAudioFrameToPeer(peer, &frame,
owner_.audio_label_.c_str(),
wire.data(), wire.size());
});
@@ -239,11 +239,11 @@ int SessionDeviceManager::InitializeScreenCapturer() {
if (!owner_.preview_subscriptions_.ShouldSend(remote_id, now_time,
stream_id)) continue;
if (owner_.WithController(
remote_id, [&](PeerPtr* peer, const std::string& wire) {
remote_id, [&](MiniRtcPeerPtr* peer, const std::string& wire) {
if (resumed_after_gap || stream_changed)
RequestVideoKeyFrame(peer, stream_id.c_str());
frame.captured_timestamp = GetSystemTimeMicros(peer);
return SendVideoFrameToPeer(peer, &frame, stream_id.c_str(),
MiniRtcRequestVideoKeyFrame(peer, stream_id.c_str());
frame.captured_timestamp = MiniRtcGetSystemTimeMicros(peer);
return MiniRtcSendVideoFrameToPeer(peer, &frame, stream_id.c_str(),
wire.data(), wire.size());
}) != 0)
++send_errors;
@@ -285,7 +285,7 @@ bool SessionDeviceManager::ShouldCaptureCursor() const {
std::shared_lock lock(owner_.connection_status_mutex_);
return std::any_of(owner_.connection_status_.begin(),
owner_.connection_status_.end(), [](const auto& entry) {
return entry.second == ConnectionStatus::Connected &&
return entry.second == MiniRtcConnectionStatus::MiniRtcConnectionConnected &&
entry.first.find("web") != std::string::npos;
});
}
@@ -294,7 +294,7 @@ bool SessionDeviceManager::HasConnectedController() const {
std::shared_lock lock(owner_.connection_status_mutex_);
return std::any_of(owner_.connection_status_.begin(),
owner_.connection_status_.end(), [](const auto& entry) {
return entry.second == ConnectionStatus::Connected;
return entry.second == MiniRtcConnectionStatus::MiniRtcConnectionConnected;
});
}
@@ -108,7 +108,7 @@ void FileTransferManager::ProcessQueue(std::shared_ptr<RemoteSession> props) {
workers_.push_back(std::async(std::launch::async, [this, props, file] {
auto& state = state_for(props);
const auto id = file.file_id;
PeerPtr* peer;
MiniRtcPeerPtr* peer;
std::shared_ptr<PeerEventHandler> events;
{
std::shared_lock lock(owner_.remote_sessions_mutex_);
@@ -126,7 +126,7 @@ void FileTransferManager::ProcessQueue(std::shared_ptr<RemoteSession> props) {
auto callback = events->EnterCallback();
if (!callback || !events->DataAllowed()) return -1;
const auto wire_id = events->WireId(file.remote_id);
return SendReliableDataFrameToPeer(
return MiniRtcSendReliableDataFrameToPeer(
peer, data, size, file.file_label.c_str(),
wire_id.data(), wire_id.size());
}, file_transfer::Session::Progress{});
@@ -176,7 +176,7 @@ void FileTransferManager::ProcessQueue(std::shared_ptr<RemoteSession> props) {
// Release that reservation even though no data chunk was ever sent.
const auto packet = EncodeFileCancel(id, 0);
const auto wire_id = events->WireId(file.remote_id);
SendReliableDataFrameToPeer(peer, packet.data(), packet.size(),
MiniRtcSendReliableDataFrameToPeer(peer, packet.data(), packet.size(),
file.file_label.c_str(), wire_id.data(), wire_id.size());
}
}
@@ -347,7 +347,7 @@ void FileTransferManager::UpdateReceiveProgress(
std::shared_ptr<FileReceiver> FileTransferManager::ReceiverFor(
PeerEventHandler* handler, const std::string& remote) {
const auto props = owner_.FindRemoteSession(remote);
PeerPtr* peer;
MiniRtcPeerPtr* peer;
std::shared_ptr<PeerEventHandler> events;
{
std::shared_lock lock(owner_.remote_sessions_mutex_);
@@ -382,7 +382,7 @@ std::shared_ptr<FileReceiver> FileTransferManager::ReceiverFor(
if (!callback || !events->DataAllowed()) return -1;
const auto bytes = EncodeFileTransferAck(ack);
const auto wire_id = events->WireId(remote);
return SendReliableDataFrameToPeer(
return MiniRtcSendReliableDataFrameToPeer(
peer, bytes.data(), bytes.size(), kFileFeedbackStream,
wire_id.data(), wire_id.size());
});
@@ -529,11 +529,11 @@ bool FileTransferManager::SendBrowser(const std::string& remote, const FileBrows
if (!events) return false;
auto callback = events->EnterCallback();
if (!callback || !events->DataAllowed()) return false;
PeerPtr* peer = events->IsDirect() ? events->DirectPeer() : props ? props->peer_ : owner_.peer_;
MiniRtcPeerPtr* peer = events->IsDirect() ? events->DirectPeer() : props ? props->peer_ : owner_.peer_;
const auto data = message.dump(-1, ' ', false, FileBrowser::Json::error_handler_t::replace);
if (!peer || data.size() > 60000) return false;
const auto wire_id = events->WireId(remote);
return SendReliableDataFrameToPeer(peer, data.data(), data.size(),
return MiniRtcSendReliableDataFrameToPeer(peer, data.data(), data.size(),
owner_.control_data_label_.c_str(), wire_id.data(), wire_id.size()) == 0;
}
@@ -22,7 +22,7 @@ namespace crossdesk {
class VideoLatencyStats;
// Travels with the exact queued pixels, including native frames. Its clock is
// translated once at the receive callback; rendering needs no live PeerPtr.
// translated once at the receive callback; rendering needs no live MiniRtcPeerPtr.
struct VideoLatencyFrame {
using Clock = std::chrono::steady_clock;
std::shared_ptr<VideoLatencyStats> stats;
@@ -32,8 +32,8 @@ bool GuiRuntime::HasActiveSession() {
std::shared_lock lock(connection_status_mutex_);
return std::any_of(connection_status_.begin(), connection_status_.end(),
[](const auto& entry) {
return entry.second == ConnectionStatus::Connecting ||
entry.second == ConnectionStatus::Connected;
return entry.second == MiniRtcConnectionStatus::MiniRtcConnectionConnecting ||
entry.second == MiniRtcConnectionStatus::MiniRtcConnectionConnected;
});
}
@@ -57,7 +57,7 @@ void GuiRuntime::UnmuteRemoteAudio(const std::shared_ptr<RemoteSession>& props)
action.type = ControlType::audio_capture;
action.a = true;
const auto message = action.to_json();
SendReliableDataFrame(props->peer_, message.data(), message.size(),
MiniRtcSendReliableDataFrame(props->peer_, message.data(), message.size(),
props->control_data_label_.c_str());
}
@@ -79,7 +79,7 @@ void GuiRuntime::HandleConnectionStatusChange() {
const auto message =
BuildDevicePresenceRequest(client_id_, recent_connection_ids_, true, {},
gallery_presence_ids_).dump();
if (SendSignalMessage(peer_, message.data(), message.size()) == 0) {
if (MiniRtcSendSignalMessage(peer_, message.data(), message.size()) == 0) {
next_presence_refresh_at_ = now + kPresenceRefreshInterval;
} else {
need_to_send_recent_connections_ = true;
@@ -207,7 +207,7 @@ void GuiRuntime::HandleServerControllerDisconnected(
codec_status_controllers_.erase(remote_id);
privacy_sessions_.Disconnected(remote_id);
for (const auto& [id, status] : connection_status_) {
if (status != ConnectionStatus::Connected) {
if (status != MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
continue;
}
has_connected_controller = true;
@@ -296,7 +296,7 @@ int GuiRuntime::RequestSingleDevicePresence(const std::string& remote_id,
gallery_presence_ids_)
.dump();
int ret = SendSignalMessage(peer_, s.data(), s.size());
int ret = MiniRtcSendSignalMessage(peer_, s.data(), s.size());
if (ret != 0) {
std::lock_guard<std::mutex> lock(pending_presence_probe_mutex_);
pending_presence_probe_ = false;
@@ -315,7 +315,7 @@ int GuiRuntime::ForceSignalReconnect() {
LOG_WARN("Signal reconnect requested with no connection peer");
return -1;
}
return ReconnectSignal(peer_);
return MiniRtcReconnectSignal(peer_);
}
void GuiRuntime::CloseRemoteSession(std::shared_ptr<RemoteSession> props) {
@@ -332,7 +332,7 @@ void GuiRuntime::CloseRemoteSession(std::shared_ptr<RemoteSession> props) {
}
props->connection_established_ = false;
props->streaming_ = false;
props->connection_status_.store(ConnectionStatus::Closed);
props->connection_status_.store(MiniRtcConnectionStatus::MiniRtcConnectionClosed);
std::shared_ptr<std::vector<unsigned char>> frame_snapshot;
int video_width = 0;
int video_height = 0;
@@ -365,7 +365,7 @@ void GuiRuntime::CloseRemoteSession(std::shared_ptr<RemoteSession> props) {
video_frame_dirty_.store(true, std::memory_order_release);
}
PeerPtr* peer = nullptr;
MiniRtcPeerPtr* peer = nullptr;
{
// Audio/clipboard senders hold a shared map lock while using this pointer.
std::unique_lock lock(remote_sessions_mutex_);
@@ -384,8 +384,8 @@ void GuiRuntime::CloseRemoteSession(std::shared_ptr<RemoteSession> props) {
if (peer && !props->lan_session_) {
LOG_INFO("[{}] Background leave connection [{}]", props->local_id_,
props->remote_id_);
LeaveConnection(peer, props->remote_id_.c_str());
DestroyPeer(&peer);
MiniRtcLeaveConnection(peer, props->remote_id_.c_str());
MiniRtcDestroyPeer(&peer);
}
if (thumbnail && props->was_connected_) {
const char* nv12 = frame_snapshot && !frame_snapshot->empty()
@@ -430,7 +430,7 @@ void GuiRuntime::CloseServerController(const std::string& remote_id) {
return;
controller_cleanup_tasks_[remote_id] = session_cleanup_queue_.PostTask(
[peer = peer_, transmission_id = std::string(client_id_), remote_id] {
if (DisconnectPeerConnection(peer, transmission_id.c_str(),
if (MiniRtcDisconnectPeerConnection(peer, transmission_id.c_str(),
remote_id.c_str()) != 0) {
LOG_WARN("[{}] Could not queue controller disconnect notification",
remote_id);
@@ -462,8 +462,8 @@ void GuiRuntime::CloseConnectionPeer() {
HandleServerControllerDisconnected(id, "peer_closed");
signal_connected_ = false;
device_presence_cache_.SetSignalConnected(false);
signal_status_ = SignalStatus::SignalClosed;
PeerPtr* peer;
signal_status_ = MiniRtcSignalStatus::MiniRtcSignalClosed;
MiniRtcPeerPtr* peer;
{
std::unique_lock lock(remote_sessions_mutex_);
peer = std::exchange(peer_, nullptr);
@@ -474,8 +474,8 @@ void GuiRuntime::CloseConnectionPeer() {
[peer, handler = peer_events_, id = std::string(client_id_)]() mutable {
handler->Deactivate();
LOG_INFO("[{}] Background connection peer cleanup", id);
LeaveConnection(peer, id.c_str());
DestroyPeer(&peer);
MiniRtcLeaveConnection(peer, id.c_str());
MiniRtcDestroyPeer(&peer);
});
}
@@ -673,9 +673,9 @@ int GuiRuntime::ConnectTo(const std::string& remote_id, const char* password,
if (exists && !stale->closing_.load() &&
!stale->connection_established_) {
const auto status = stale->connection_status_.load();
if (status == ConnectionStatus::Disconnected ||
status == ConnectionStatus::Failed ||
status == ConnectionStatus::Closed) {
if (status == MiniRtcConnectionStatus::MiniRtcConnectionDisconnected ||
status == MiniRtcConnectionStatus::MiniRtcConnectionFailed ||
status == MiniRtcConnectionStatus::MiniRtcConnectionClosed) {
// The recreated session starts with an empty password; callers that
// pass none expect the one stored by the previous attempt to be reused.
const bool keep_stored_password = !password || !*password;
@@ -692,7 +692,7 @@ int GuiRuntime::ConnectTo(const std::string& remote_id, const char* password,
}
if (!exists) {
PeerPtr* peer_to_init = nullptr;
MiniRtcPeerPtr* peer_to_init = nullptr;
std::string local_id;
{
@@ -707,13 +707,13 @@ int GuiRuntime::ConnectTo(const std::string& remote_id, const char* password,
props->control_mouse_ = !background;
props->enable_mouse_control_ = !background;
props->audio_capture_button_pressed_ = !background;
memcpy(&props->params_, &params_, sizeof(Params));
memcpy(&props->params_, &params_, sizeof(MiniRtcParams));
props->params_.user_id = props->local_id_.c_str();
props->peer_events_ = std::make_shared<PeerEventHandler>(*this);
props->params_.user_data = props->peer_events_.get();
props->peer_ = CreatePeer(&props->params_);
props->peer_ = MiniRtcCreatePeer(&props->params_);
props->connection_status_.store(ConnectionStatus::Connecting);
props->connection_status_.store(MiniRtcConnectionStatus::MiniRtcConnectionConnecting);
if (!background) show_connection_status_window_ = true;
if (!props->peer_) {
@@ -724,18 +724,18 @@ int GuiRuntime::ConnectTo(const std::string& remote_id, const char* password,
const auto& displays = devices_.display_info_list();
for (size_t index = 0; index < displays.size(); ++index) {
const std::string stream_id = MakeDisplayStreamId(index);
AddVideoStream(props->peer_, stream_id.c_str());
MiniRtcAddVideoStream(props->peer_, stream_id.c_str());
}
AddAudioStream(props->peer_, props->audio_label_.c_str());
AddDataStream(props->peer_, props->data_label_.c_str(), false);
AddDataStream(props->peer_, props->mouse_label_.c_str(), true);
AddDataStream(props->peer_, props->keyboard_label_.c_str(), true);
AddDataStream(props->peer_, props->control_data_label_.c_str(), true);
AddDataStream(props->peer_, props->file_label_.c_str(), true);
AddDataStream(props->peer_, props->file_feedback_label_.c_str(), true);
AddDataStream(props->peer_, props->clipboard_label_.c_str(), true);
MiniRtcAddAudioStream(props->peer_, props->audio_label_.c_str());
MiniRtcAddDataStream(props->peer_, props->data_label_.c_str(), false);
MiniRtcAddDataStream(props->peer_, props->mouse_label_.c_str(), true);
MiniRtcAddDataStream(props->peer_, props->keyboard_label_.c_str(), true);
MiniRtcAddDataStream(props->peer_, props->control_data_label_.c_str(), true);
MiniRtcAddDataStream(props->peer_, props->file_label_.c_str(), true);
MiniRtcAddDataStream(props->peer_, props->file_feedback_label_.c_str(), true);
MiniRtcAddDataStream(props->peer_, props->clipboard_label_.c_str(), true);
props->connection_status_.store(ConnectionStatus::Connecting);
props->connection_status_.store(MiniRtcConnectionStatus::MiniRtcConnectionConnecting);
peer_to_init = props->peer_;
local_id = props->local_id_;
@@ -744,7 +744,7 @@ int GuiRuntime::ConnectTo(const std::string& remote_id, const char* password,
if (peer_to_init) {
LOG_INFO("[{}] Create peer instance successful", local_id);
Init(peer_to_init);
MiniRtcInit(peer_to_init);
LOG_INFO("[{}] Peer init finish", local_id);
}
}
@@ -773,10 +773,10 @@ int GuiRuntime::ConnectTo(const std::string& remote_id, const char* password,
props->rejoin_ = false;
return 0;
}
props->connection_status_.store(ConnectionStatus::Connecting);
props->connection_status_.store(MiniRtcConnectionStatus::MiniRtcConnectionConnecting);
std::string remote_id_with_pwd = remote_id + "@" + props->remote_password_;
if (props->peer_) {
ret = JoinConnection(props->peer_, remote_id_with_pwd.c_str());
ret = MiniRtcJoinConnection(props->peer_, remote_id_with_pwd.c_str());
if (0 == ret) {
props->rejoin_ = false;
} else {
@@ -6,7 +6,7 @@
#include "runtime/trusted_devices.h"
namespace crossdesk {
int DeviceLogin::Exchange(SignalExchangeStage stage, const nlohmann::json& message,
int DeviceLogin::Exchange(MiniRtcSignalExchangeStage stage, const nlohmann::json& message,
const TrustedDevices* identity, char* response, size_t capacity) {
auto output = [&](const nlohmann::json& reply) {
const auto text = reply.dump();
@@ -14,7 +14,7 @@ int DeviceLogin::Exchange(SignalExchangeStage stage, const nlohmann::json& messa
std::memcpy(response, text.data(), text.size());
return static_cast<int>(text.size());
};
if (stage == SignalExchangeStage::PrepareLogin) {
if (stage == MiniRtcSignalExchangeStage::PrepareLogin) {
phase_ = Phase::Idle;
used_password_ = false;
password_.clear();
+1 -1
View File
@@ -18,7 +18,7 @@ class TrustedDevices;
// One signaling connection's application authentication, owned by its callbacks.
class DeviceLogin {
public:
int Exchange(SignalExchangeStage stage, const nlohmann::json& message,
int Exchange(MiniRtcSignalExchangeStage stage, const nlohmann::json& message,
const TrustedDevices* identity, char* response, size_t capacity);
bool Pending() const { return phase_ != Phase::Idle; }
bool UsedPassword() const { return used_password_; }
@@ -53,8 +53,8 @@ void GuiRuntime::ForgetControllerTrust(const std::string& id, PeerEventHandler*
int GuiRuntime::SendTrustMessage(const std::string& id, const nlohmann::json& message) {
const auto text = message.dump();
return WithController(id, [&](PeerPtr* peer, const std::string& wire) {
return SendReliableDataFrameToPeer(peer, text.data(), text.size(),
return WithController(id, [&](MiniRtcPeerPtr* peer, const std::string& wire) {
return MiniRtcSendReliableDataFrameToPeer(peer, text.data(), text.size(),
control_data_label_.c_str(), wire.data(), wire.size());
}, false);
}
@@ -94,7 +94,7 @@ bool GuiRuntime::HandleDeviceTrustMessage(const std::string& id, PeerEventHandle
const auto wire = events->WireId(id);
const auto proof = trusted_devices_->Prove(message.at("nonce"),
props->local_id_, GetHostName()).dump();
SendReliableDataFrameToPeer(props->peer_, proof.data(), proof.size(),
MiniRtcSendReliableDataFrameToPeer(props->peer_, proof.data(), proof.size(),
control_data_label_.c_str(), wire.data(), wire.size());
} else if (type == "device_trust_proof") {
std::lock_guard lock(controller_trust_mutex_);
@@ -156,7 +156,7 @@ void GuiRuntime::TickControllerTrust() {
remote_input_.Disconnect(action.id);
CloseServerController(action.id);
} else if (action.kind > 0) {
events->ApplyConnectionStatus(ConnectionStatus::Connected, action.id);
events->ApplyConnectionStatus(MiniRtcConnectionStatus::MiniRtcConnectionConnected, action.id);
if (!action.host_info.empty()) {
const auto wire = events->WireId(action.id);
PeerEventHandler::OnReceiveDataBuffer(action.host_info.data(), action.host_info.size(),
+23 -23
View File
@@ -99,7 +99,7 @@ void GuiRuntime::SendRemoteInput(const RemoteAction& action) {
? action.k.flag == KeyFlag::key_up : action.ks.pressed_count == 0;
const auto available = [](const auto& props) {
return props && props->peer_ && !props->closing_ &&
props->connection_status_ == ConnectionStatus::Connected;
props->connection_status_ == MiniRtcConnectionStatus::MiniRtcConnectionConnected;
};
std::shared_lock lock(remote_sessions_mutex_);
const auto source = remote_sessions_.find(target_id);
@@ -121,9 +121,9 @@ void GuiRuntime::SendRemoteInput(const RemoteAction& action) {
// Use the negotiated unreliable stream; clicks and wheel events remain
// on the reliable mouse stream, with their own absolute coordinates.
const int result = mouse_move
? SendDataFrame(props->peer_, message.data(), message.size(),
? MiniRtcSendDataFrame(props->peer_, message.data(), message.size(),
props->data_label_.c_str())
: SendReliableDataFrame(
: MiniRtcSendReliableDataFrame(
props->peer_, message.data(), message.size(),
mouse ? props->mouse_label_.c_str() : props->keyboard_label_.c_str());
if (result != 0)
@@ -256,15 +256,15 @@ int GuiRuntime::CreateConnectionPeer() {
ConfigCenter::VIDEO_ENCODE_FORMAT::AV1
? true
: false;
params_.turn_mode = static_cast<TurnMode>(config_center_->GetTurnMode());
params_.turn_mode = static_cast<MiniRtcTurnMode>(config_center_->GetTurnMode());
params_.enable_srtp = config_center_->IsEnableSrtp();
params_.video_content_type = VideoContentType::ScreenContent;
params_.video_content_type = MiniRtcVideoContentType::ScreenContent;
// Bootstrap outgoing media with fixed defaults. Live overrides come only
// from the authorized controller and apply to its connection on this host.
params_.video_quality = VideoQuality::QualityHigh;
params_.video_quality = MiniRtcVideoQuality::MiniRtcVideoQualityHigh;
params_.video_frame_rate = 60;
params_.video_degradation_preference =
VideoDegradationPreference::MaintainResolution;
MiniRtcVideoDegradationPreference::MaintainResolution;
params_.on_receive_video_buffer = nullptr;
params_.on_receive_audio_buffer = PeerEventHandler::OnReceiveAudioBuffer;
params_.on_receive_data_buffer = PeerEventHandler::OnReceiveDataBuffer;
@@ -284,15 +284,15 @@ int GuiRuntime::CreateConnectionPeer() {
signal_connected_ = false;
device_presence_cache_.SetSignalConnected(false);
need_to_send_recent_connections_ = true;
signal_status_ = SignalStatus::SignalConnecting;
signal_status_ = MiniRtcSignalStatus::MiniRtcSignalConnecting;
{
std::unique_lock lock(remote_sessions_mutex_);
peer_ = CreatePeer(&params_);
peer_ = MiniRtcCreatePeer(&params_);
}
if (peer_) {
LOG_INFO("Create peer instance [{}] successful", client_id_);
Init(peer_);
MiniRtcInit(peer_);
LOG_INFO("Peer [{}] init finish", client_id_);
} else {
LOG_INFO("Create peer [{}] instance failed", client_id_);
@@ -302,19 +302,19 @@ int GuiRuntime::CreateConnectionPeer() {
const auto &displays = devices_.display_info_list();
for (size_t index = 0; index < displays.size(); ++index) {
const std::string stream_id = MakeDisplayStreamId(index);
AddVideoStream(peer_, stream_id.c_str());
MiniRtcAddVideoStream(peer_, stream_id.c_str());
}
AddAudioStream(peer_, audio_label_.c_str());
AddDataStream(peer_, data_label_.c_str(), false);
AddDataStream(peer_, mouse_label_.c_str(), true);
AddDataStream(peer_, keyboard_label_.c_str(), true);
AddDataStream(peer_, control_data_label_.c_str(), true);
AddDataStream(peer_, file_label_.c_str(), true);
AddDataStream(peer_, file_feedback_label_.c_str(), true);
AddDataStream(peer_, clipboard_label_.c_str(), true);
MiniRtcAddAudioStream(peer_, audio_label_.c_str());
MiniRtcAddDataStream(peer_, data_label_.c_str(), false);
MiniRtcAddDataStream(peer_, mouse_label_.c_str(), true);
MiniRtcAddDataStream(peer_, keyboard_label_.c_str(), true);
MiniRtcAddDataStream(peer_, control_data_label_.c_str(), true);
MiniRtcAddDataStream(peer_, file_label_.c_str(), true);
MiniRtcAddDataStream(peer_, file_feedback_label_.c_str(), true);
MiniRtcAddDataStream(peer_, clipboard_label_.c_str(), true);
if (!unattended_host_)
AddDataStream(peer_, web_clipboard::kStream, true);
MiniRtcAddDataStream(peer_, web_clipboard::kStream, true);
return 0;
} else {
return -1;
@@ -390,10 +390,10 @@ void GuiRuntime::SdlCaptureAudioIn(void *userdata, Uint8 *stream, int len) {
uint64_t captured_timestamp = 0;
for (const auto &it : runtime->remote_sessions_) {
auto props = it.second;
if (props->connection_status_.load() == ConnectionStatus::Connected) {
if (props->connection_status_.load() == MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
if (props->peer_) {
if (captured_timestamp == 0) {
const int64_t timestamp_us = GetSystemTimeMicros(props->peer_);
const int64_t timestamp_us = MiniRtcGetSystemTimeMicros(props->peer_);
if (timestamp_us > 0) {
captured_timestamp = static_cast<uint64_t>(timestamp_us);
}
@@ -402,7 +402,7 @@ void GuiRuntime::SdlCaptureAudioIn(void *userdata, Uint8 *stream, int len) {
frame.data = reinterpret_cast<const char *>(stream);
frame.size = static_cast<size_t>(len);
frame.captured_timestamp = captured_timestamp;
SendAudioFrame(props->peer_, &frame,
MiniRtcSendAudioFrame(props->peer_, &frame,
runtime->audio_label_.c_str());
}
}
+2 -2
View File
@@ -60,12 +60,12 @@ class GuiRuntime : protected gui_detail::GuiState {
void TickLan();
void BeginShutdown();
bool ShutdownDrained();
void RegisterStreams(PeerPtr* peer, size_t display_count);
void RegisterStreams(MiniRtcPeerPtr* peer, size_t display_count);
void ConnectLan(const std::string& address, unsigned port,
std::string password, bool remember_password = false);
int WithController(
const std::string& id,
const std::function<int(PeerPtr*, const std::string&)>& operation,
const std::function<int(MiniRtcPeerPtr*, const std::string&)>& operation,
bool require_trusted = true);
int SendControllerData(const std::string& id, const char* data, size_t size,
const char* label);
+20 -20
View File
@@ -7,17 +7,17 @@
#endif
namespace crossdesk {
void GuiRuntime::RegisterStreams(PeerPtr* peer, size_t displays) {
void GuiRuntime::RegisterStreams(MiniRtcPeerPtr* peer, size_t displays) {
for (size_t i = 0; i < displays; ++i) {
const auto id = MakeDisplayStreamId(i);
AddVideoStream(peer, id.c_str());
MiniRtcAddVideoStream(peer, id.c_str());
}
AddAudioStream(peer, audio_label_.c_str());
AddDataStream(peer, data_label_.c_str(), false);
MiniRtcAddAudioStream(peer, audio_label_.c_str());
MiniRtcAddDataStream(peer, data_label_.c_str(), false);
for (const auto& label :
{mouse_label_, keyboard_label_, control_data_label_, file_label_,
file_feedback_label_, clipboard_label_})
AddDataStream(peer, label.c_str(), true);
MiniRtcAddDataStream(peer, label.c_str(), true);
}
void GuiRuntime::InitializeLan() {
if (unattended_host_ || stopping_ || lan_ ||
@@ -37,8 +37,8 @@ void GuiRuntime::InitializeLan() {
auto events = std::make_shared<PeerEventHandler>(*this);
events->BindDirect(session);
// Direct initialization must not depend on cloud login/configuration having
// successfully populated the managed peer's Params snapshot.
Params params{};
// successfully populated the managed peer's MiniRtcParams snapshot.
MiniRtcParams params{};
std::snprintf(params.log_path, sizeof(params.log_path), "%s",
dll_log_path_.c_str());
params.hardware_acceleration = true;
@@ -46,12 +46,12 @@ void GuiRuntime::InitializeLan() {
params.av1_encoding = config_center_->GetVideoEncodeFormat() ==
ConfigCenter::VIDEO_ENCODE_FORMAT::AV1;
params.enable_srtp = true;
params.turn_mode = TurnMode::TurnDisabled;
params.video_content_type = VideoContentType::ScreenContent;
params.video_quality = VideoQuality::QualityHigh;
params.turn_mode = MiniRtcTurnMode::MiniRtcTurnDisabled;
params.video_content_type = MiniRtcVideoContentType::ScreenContent;
params.video_quality = MiniRtcVideoQuality::MiniRtcVideoQualityHigh;
params.video_frame_rate = 60;
params.video_degradation_preference =
VideoDegradationPreference::MaintainResolution;
MiniRtcVideoDegradationPreference::MaintainResolution;
params.on_receive_video_frame = PeerEventHandler::OnReceiveVideoBuffer;
params.on_receive_audio_buffer = PeerEventHandler::OnReceiveAudioBuffer;
params.on_receive_data_buffer = PeerEventHandler::OnReceiveDataBuffer;
@@ -69,7 +69,7 @@ void GuiRuntime::InitializeLan() {
lan::SessionManager::Prepared result;
result.callback_owner = events;
result.drain_callbacks = [events] { events->Deactivate(); };
result.peer = CreatePeer(&params);
result.peer = MiniRtcCreatePeer(&params);
events->SetDirectPeer(result.peer);
if (result.peer) RegisterStreams(result.peer, displays);
return result;
@@ -88,7 +88,7 @@ void GuiRuntime::InitializeLan() {
hooks.connected = [this](const std::shared_ptr<lan::Session>& session) {
auto events =
std::static_pointer_cast<PeerEventHandler>(session->callback_owner);
events->ApplyConnectionStatus(ConnectionStatus::Connected, session->key);
events->ApplyConnectionStatus(MiniRtcConnectionStatus::MiniRtcConnectionConnected, session->key);
events->FlushEarlyData();
};
hooks.closed = [this](const std::shared_ptr<lan::Session>& session) {
@@ -101,7 +101,7 @@ void GuiRuntime::InitializeLan() {
}
if (events) {
if (attached)
events->ApplyConnectionStatus(ConnectionStatus::Closed, session->key);
events->ApplyConnectionStatus(MiniRtcConnectionStatus::MiniRtcConnectionClosed, session->key);
events->StopAccepting();
transfers_.Cancel(events.get());
}
@@ -157,7 +157,7 @@ void GuiRuntime::ConnectLan(const std::string& address, unsigned port,
lan_connecting_ = session;
props->lan_session_ = session;
props->remote_id_ = session->key;
props->connection_status_ = ConnectionStatus::Connecting;
props->connection_status_ = MiniRtcConnectionStatus::MiniRtcConnectionConnecting;
props->connection_auth_.Complete();
{
std::unique_lock lock(remote_sessions_mutex_);
@@ -180,14 +180,14 @@ std::shared_ptr<PeerEventHandler> GuiRuntime::ControllerEvents(
}
int GuiRuntime::WithController(
const std::string& id,
const std::function<int(PeerPtr*, const std::string&)>& operation,
const std::function<int(MiniRtcPeerPtr*, const std::string&)>& operation,
bool require_trusted) {
if (require_trusted && !TrustedControllerAllowed(id)) return -1;
std::shared_lock lock(remote_sessions_mutex_);
auto it = lan_controllers_.find(id);
auto events = it == lan_controllers_.end() ? peer_events_ : it->second.events;
if (it == lan_controllers_.end() && id.rfind("lan/", 0) == 0) return -1;
PeerPtr* peer =
MiniRtcPeerPtr* peer =
it == lan_controllers_.end() ? peer_ : it->second.session->peer;
if (!peer || !events || !events->DataAllowed()) return -1;
auto callback = events->EnterCallback();
@@ -198,8 +198,8 @@ int GuiRuntime::WithController(
}
int GuiRuntime::SendControllerData(const std::string& id, const char* data,
size_t size, const char* label) {
return WithController(id, [&](PeerPtr* peer, const std::string& wire) {
return SendReliableDataFrameToPeer(peer, data, size, label, wire.data(),
return WithController(id, [&](MiniRtcPeerPtr* peer, const std::string& wire) {
return MiniRtcSendReliableDataFrameToPeer(peer, data, size, label, wire.data(),
wire.size());
});
}
@@ -208,7 +208,7 @@ std::vector<std::string> GuiRuntime::ConnectedControllers() {
std::shared_lock lock(connection_status_mutex_);
ids.reserve(connection_status_.size());
for (const auto& [id, status] : connection_status_)
if (status == ConnectionStatus::Connected) ids.push_back(id);
if (status == MiniRtcConnectionStatus::MiniRtcConnectionConnected) ids.push_back(id);
return ids;
}
void GuiRuntime::BeginShutdown() {
@@ -176,7 +176,7 @@ void PeerEventHandler::OnReceiveDataBuffer(
}
const std::string wire_id = handler->WireId(remote_id);
PeerPtr* bound_peer =
MiniRtcPeerPtr* bound_peer =
handler->IsDirect() ? handler->DirectPeer() : runtime->peer_;
std::string json_str(data, size);
if (json_str.find("\"automation\"") != std::string::npos) {
@@ -204,31 +204,31 @@ void PeerEventHandler::OnReceiveDataBuffer(
// their own demand. MiniRTC owns per-peer video/audio pause state.
if (!previous || subscription->IsNewerThan(*previous)) {
if (subscription->fps > 0)
accepted = UpdateVideoSettings(
accepted = MiniRtcUpdateVideoSettings(
bound_peer, wire_id.data(), wire_id.size(),
static_cast<VideoQuality>(subscription->quality),
static_cast<MiniRtcVideoQuality>(subscription->quality),
subscription->frame_rate,
static_cast<VideoDegradationPreference>(
static_cast<MiniRtcVideoDegradationPreference>(
subscription->EncoderPreference())) == 0;
if (accepted && (!previous || previous->max_bitrate_bps.value_or(0) !=
subscription->max_bitrate_bps.value_or(0)))
accepted = UpdateVideoBitrateLimit(
accepted = MiniRtcUpdateVideoBitrateLimit(
bound_peer, wire_id.data(), wire_id.size(),
subscription->max_bitrate_bps.value_or(0)) == 0;
// Rebalancing bandwidth alone must not force every device to send a
// keyframe. The pause API requests its own keyframes on resume.
if (accepted && (!previous || previous->width != subscription->width ||
previous->height != subscription->height))
accepted = UpdateVideoResolution(bound_peer, wire_id.data(),
accepted = MiniRtcUpdateVideoResolution(bound_peer, wire_id.data(),
wire_id.size(), subscription->width,
subscription->height) == 0;
if (accepted)
accepted =
SetVideoSendPaused(bound_peer, wire_id.data(), wire_id.size(),
MiniRtcSetVideoSendPaused(bound_peer, wire_id.data(), wire_id.size(),
subscription->fps == 0) == 0;
if (accepted)
accepted =
SetAudioSendPaused(bound_peer, wire_id.data(), wire_id.size(),
MiniRtcSetAudioSendPaused(bound_peer, wire_id.data(), wire_id.size(),
!subscription->audio) == 0;
if (accepted && subscription->audio)
runtime->devices_.StartSpeakerCapturer();
@@ -240,7 +240,7 @@ void PeerEventHandler::OnReceiveDataBuffer(
{"request_id", subscription->request_id},
{"accepted",
accepted}}.dump();
SendReliableDataFrameToPeer(bound_peer, reply.data(), reply.size(),
MiniRtcSendReliableDataFrameToPeer(bound_peer, reply.data(), reply.size(),
runtime->control_data_label_.c_str(),
wire_id.data(), wire_id.size());
return;
@@ -275,7 +275,7 @@ void PeerEventHandler::OnReceiveDataBuffer(
if (auto props = runtime->FindRemoteSession(remote_id);
props && source_id == props->control_data_label_ &&
!props->closing_ &&
props->connection_status_ == ConnectionStatus::Connected) {
props->connection_status_ == MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
props->net_traffic_stats_.StoreRemoteVideoEncoder(remote_action.vcs.encoder);
}
return;
@@ -314,17 +314,17 @@ void PeerEventHandler::OnReceiveDataBuffer(
return;
const auto& settings = remote_action.vs;
remote_action.vs.accepted =
UpdateVideoSettings(
MiniRtcUpdateVideoSettings(
bound_peer, wire_id.data(), wire_id.size(),
static_cast<VideoQuality>(settings.quality), settings.frame_rate,
static_cast<VideoDegradationPreference>(settings.preference)) == 0;
static_cast<MiniRtcVideoQuality>(settings.quality), settings.frame_rate,
static_cast<MiniRtcVideoDegradationPreference>(settings.preference)) == 0;
LOG_INFO("Video settings: peer={} source={} request={} quality={} fps={} "
"preference={} accepted={}",
remote_id, source_id, settings.request_id, settings.quality,
settings.frame_rate, settings.preference, remote_action.vs.accepted);
remote_action.type = ControlType::video_settings_status;
const auto message = remote_action.to_json();
SendReliableDataFrameToPeer(bound_peer, message.data(), message.size(),
MiniRtcSendReliableDataFrameToPeer(bound_peer, message.data(), message.size(),
runtime->control_data_label_.c_str(),
wire_id.data(), wire_id.size());
return;
@@ -479,7 +479,7 @@ void PeerEventHandler::OnReceiveDataBuffer(
props->video_settings_request_tick_ = SDL_GetTicks();
settings.vs = props->video_settings_;
const auto message = settings.to_json();
SendReliableDataFrame(
MiniRtcSendReliableDataFrame(
handler->IsDirect() ? handler->DirectPeer() : props->peer_,
message.data(), message.size(),
props->control_data_label_.c_str());
@@ -530,7 +530,7 @@ void PeerEventHandler::OnReceiveDataBuffer(
// command arrives after it (e.g. when unmuting an inactive window).
const auto subscription = runtime->preview_subscriptions_.Get(remote_id);
const bool paused = subscription ? !subscription->audio : !remote_action.a;
const int ret = SetAudioSendPaused(bound_peer, wire_id.data(),
const int ret = MiniRtcSetAudioSendPaused(bound_peer, wire_id.data(),
wire_id.size(), paused);
if (remote_action.a)
runtime->devices_.StartSpeakerCapturer();
@@ -65,7 +65,7 @@ bool PeerEventHandler::DataAllowed() const {
return session && session->authorized && !session->closing;
}
void PeerEventHandler::SendClientInfo(PeerPtr* peer,
void PeerEventHandler::SendClientInfo(MiniRtcPeerPtr* peer,
const std::string& client_id) {
if (!peer) {
return;
@@ -75,7 +75,7 @@ void PeerEventHandler::SendClientInfo(PeerPtr* peer,
{"version", CROSSDESK_VERSION},
{"platform", HostPlatformName(kClientPlatform)}};
const std::string payload = message.dump();
if (SendSignalMessage(peer, payload.data(), payload.size()) != 0) {
if (MiniRtcSendSignalMessage(peer, payload.data(), payload.size()) != 0) {
LOG_WARN("[{}] failed to report client information", client_id);
}
}
@@ -84,13 +84,13 @@ PeerEventHandler::PeerEventHandler(GuiRuntime& owner) : owner_(owner) {
owner_.transfers_.Connected(this, "");
}
int PeerEventHandler::OnSignalExchange(SignalExchangeStage stage, const char* message,
int PeerEventHandler::OnSignalExchange(MiniRtcSignalExchangeStage stage, const char* message,
size_t size, char* response, size_t capacity, void* user_data) {
auto* handler = static_cast<PeerEventHandler*>(user_data);
if (!handler || !message) return -1;
auto callback = handler->EnterCallback();
if (!callback) return -1;
if (stage == SignalExchangeStage::IncomingMessage &&
if (stage == MiniRtcSignalExchangeStage::IncomingMessage &&
!handler->device_login_.Pending()) return 0;
try {
return handler->device_login_.Exchange(stage,
@@ -209,7 +209,7 @@ void PeerEventHandler::OnSignalMessage(const char* message, size_t size,
}
}
void PeerEventHandler::OnSignalStatus(SignalStatus status, const char* user_id,
void PeerEventHandler::OnSignalStatus(MiniRtcSignalStatus status, const char* user_id,
size_t user_id_size, void* user_data) {
using RecoveryAction = GuiRuntime::CredentialRecoveryAction;
auto* handler = static_cast<PeerEventHandler*>(user_data);
@@ -220,13 +220,13 @@ void PeerEventHandler::OnSignalStatus(SignalStatus status, const char* user_id,
std::string client_id(user_id, user_id_size);
if (client_id == runtime->client_id_) {
runtime->announcements_.SetConnected(status == SignalStatus::SignalConnected);
runtime->announcements_.SetConnected(status == MiniRtcSignalStatus::MiniRtcSignalConnected);
runtime->signal_status_ = status;
runtime->device_presence_cache_.SetSignalConnected(
status == SignalStatus::SignalConnected);
if (SignalStatus::SignalConnecting == status) {
status == MiniRtcSignalStatus::MiniRtcSignalConnected);
if (MiniRtcSignalStatus::MiniRtcSignalConnecting == status) {
runtime->signal_connected_ = false;
} else if (SignalStatus::SignalConnected == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalConnected == status) {
runtime->signal_connected_ = true;
runtime->need_to_send_recent_connections_ = true;
LOG_INFO("[{}] connected to signal server", client_id);
@@ -241,20 +241,20 @@ void PeerEventHandler::OnSignalStatus(SignalStatus status, const char* user_id,
runtime->credential_recovery_action_ = RecoveryAction::ClearPending;
}
}
} else if (SignalStatus::SignalFailed == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalFailed == status) {
runtime->signal_connected_ = false;
std::lock_guard<std::mutex> lock(runtime->password_change_mutex_);
if (runtime->credential_recovery_in_progress_ &&
runtime->credential_recovery_attempt_pending_) {
runtime->credential_recovery_action_ = RecoveryAction::RetryActive;
}
} else if (SignalStatus::SignalClosed == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalClosed == status) {
runtime->signal_connected_ = false;
} else if (SignalStatus::SignalReconnecting == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalReconnecting == status) {
runtime->signal_connected_ = false;
} else if (SignalStatus::SignalServerClosed == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalServerClosed == status) {
runtime->signal_connected_ = false;
} else if (SignalStatus::SignalTlsCertError == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalTlsCertError == status) {
runtime->signal_connected_ = false;
}
} else {
@@ -266,27 +266,27 @@ void PeerEventHandler::OnSignalStatus(SignalStatus status, const char* user_id,
auto props = runtime->FindRemoteSession(remote_id);
if (!props) return;
props->signal_status_ = status;
if (SignalStatus::SignalConnecting == status) {
if (MiniRtcSignalStatus::MiniRtcSignalConnecting == status) {
props->signal_connected_ = false;
} else if (SignalStatus::SignalConnected == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalConnected == status) {
props->signal_connected_ = true;
LOG_INFO("[{}] connected to signal server", remote_id);
SendClientInfo(props->peer_, client_id);
} else if (SignalStatus::SignalFailed == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalFailed == status) {
props->signal_connected_ = false;
} else if (SignalStatus::SignalClosed == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalClosed == status) {
props->signal_connected_ = false;
} else if (SignalStatus::SignalReconnecting == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalReconnecting == status) {
props->signal_connected_ = false;
} else if (SignalStatus::SignalServerClosed == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalServerClosed == status) {
props->signal_connected_ = false;
} else if (SignalStatus::SignalTlsCertError == status) {
} else if (MiniRtcSignalStatus::MiniRtcSignalTlsCertError == status) {
props->signal_connected_ = false;
}
}
}
void PeerEventHandler::OnConnectionStatus(ConnectionStatus status,
void PeerEventHandler::OnConnectionStatus(MiniRtcConnectionStatus status,
const char* user_id, size_t size,
void* context) {
auto* handler = static_cast<PeerEventHandler*>(context);
@@ -300,7 +300,7 @@ void PeerEventHandler::OnConnectionStatus(ConnectionStatus status,
DispatchConnectionStatus(status, user_id, size, context);
}
void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
void PeerEventHandler::DispatchConnectionStatus(MiniRtcConnectionStatus status,
const char* user_id,
const size_t user_id_size,
void* user_data) {
@@ -311,9 +311,9 @@ void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
GuiRuntime* runtime = &handler->owner_;
std::string remote_id = handler->ConnectionKey(user_id, user_id_size);
if (status == ConnectionStatus::Connected) runtime->transfers_.Connected(handler, remote_id);
else if (status == ConnectionStatus::Disconnected || status == ConnectionStatus::Failed ||
status == ConnectionStatus::Closed) runtime->transfers_.Cancel(handler, remote_id);
if (status == MiniRtcConnectionStatus::MiniRtcConnectionConnected) runtime->transfers_.Connected(handler, remote_id);
else if (status == MiniRtcConnectionStatus::MiniRtcConnectionDisconnected || status == MiniRtcConnectionStatus::MiniRtcConnectionFailed ||
status == MiniRtcConnectionStatus::MiniRtcConnectionClosed) runtime->transfers_.Cancel(handler, remote_id);
std::shared_ptr<GuiRuntime::RemoteSession> props;
{
std::shared_lock lock(runtime->remote_sessions_mutex_);
@@ -324,7 +324,7 @@ void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
}
if (!props) {
if (status == ConnectionStatus::Connected) {
if (status == MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
if (!runtime->BeginControllerTrust(remote_id, handler)) return;
} else {
runtime->ForgetControllerTrust(remote_id, handler);
@@ -335,11 +335,11 @@ void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
runtime->is_client_mode_ = true;
if (!props->wall_managed_) runtime->show_connection_status_window_ = true;
props->connection_status_.store(status);
if (status != ConnectionStatus::Connecting && status != ConnectionStatus::Gathering)
if (status != MiniRtcConnectionStatus::MiniRtcConnectionConnecting && status != MiniRtcConnectionStatus::MiniRtcConnectionGathering)
props->connection_auth_.Complete();
switch (status) {
case ConnectionStatus::Connected: {
case MiniRtcConnectionStatus::MiniRtcConnectionConnected: {
runtime->ResetRemoteServiceStatus(*props);
{
std::lock_guard lock(props->remote_cursor_state_mutex_);
@@ -368,7 +368,7 @@ void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
information["device_trust_version"] = 1;
std::string msg = information.dump();
const int ret =
SendReliableDataFrame(props->peer_, msg.data(), msg.size(),
MiniRtcSendReliableDataFrame(props->peer_, msg.data(), msg.size(),
runtime->control_data_label_.c_str());
if (ret != 0) {
LOG_WARN("[{}] host information send failed, ret={}", remote_id,
@@ -386,9 +386,9 @@ void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
if (!props->wall_managed_) runtime->start_keyboard_capturer_ = true;
break;
}
case ConnectionStatus::Disconnected:
case ConnectionStatus::Failed:
case ConnectionStatus::Closed: {
case MiniRtcConnectionStatus::MiniRtcConnectionDisconnected:
case MiniRtcConnectionStatus::MiniRtcConnectionFailed:
case MiniRtcConnectionStatus::MiniRtcConnectionClosed: {
runtime->keyboard_.ReleaseRemotePressedKeys(remote_id,
"connection_closed");
props->connection_established_ = false;
@@ -406,7 +406,7 @@ void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
props->gallery_video_latency_->Reset();
props->gallery_frame_timing_ = {};
}
props->traversal_mode_ = TraversalMode::UnknownMode;
props->traversal_mode_ = MiniRtcTraversalMode::MiniRtcTraversalUnknown;
props->enable_mouse_control_ = false;
props->preview_subscription_supported_ = false;
props->preview_resolution_supported_ = false;
@@ -477,7 +477,7 @@ void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
runtime->focus_on_stream_window_ = false;
if (status == ConnectionStatus::Closed) {
if (status == MiniRtcConnectionStatus::MiniRtcConnectionClosed) {
props->remote_close_pending_.store(true, std::memory_order_release);
}
@@ -491,7 +491,7 @@ void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
runtime->show_connection_status_window_ = true;
{
std::unique_lock lock(runtime->connection_status_mutex_);
if (status == ConnectionStatus::Connected) {
if (status == MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
runtime->disconnect_lock_.Connected(remote_id);
// Local privacy requires explicit desktop capability. Host info may
// arrive before Connected; consume that saved capability here.
@@ -500,19 +500,19 @@ void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
runtime->ApplyPrivacyAdmission(automatic_enable);
}
runtime->connection_status_[remote_id] = status;
if (status == ConnectionStatus::Connected)
if (status == MiniRtcConnectionStatus::MiniRtcConnectionConnected)
runtime->remote_input_.Connect(remote_id);
#if _WIN32
runtime->windows_rdp_handoff_connected_->store(std::any_of(
runtime->connection_status_.begin(), runtime->connection_status_.end(),
[](const auto& entry) { return entry.second == ConnectionStatus::Connected; }),
[](const auto& entry) { return entry.second == MiniRtcConnectionStatus::MiniRtcConnectionConnected; }),
std::memory_order_relaxed);
#endif
runtime->devices_.OnControllerConnectionsChanged();
}
switch (status) {
case ConnectionStatus::Connected: {
case MiniRtcConnectionStatus::MiniRtcConnectionConnected: {
runtime->preview_subscriptions_.Remove(remote_id);
#if _WIN32
runtime->last_windows_service_status_tick_ = 0;
@@ -557,9 +557,9 @@ void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
break;
}
case ConnectionStatus::Disconnected:
case ConnectionStatus::Failed:
case ConnectionStatus::Closed: {
case MiniRtcConnectionStatus::MiniRtcConnectionDisconnected:
case MiniRtcConnectionStatus::MiniRtcConnectionFailed:
case MiniRtcConnectionStatus::MiniRtcConnectionClosed: {
runtime->HandleServerControllerDisconnected(remote_id,
"connection_closed");
break;
@@ -571,7 +571,7 @@ void PeerEventHandler::DispatchConnectionStatus(ConnectionStatus status,
}
void PeerEventHandler::OnNetStatusReport(
const char* client_id, size_t client_id_size, TraversalMode mode,
const char* client_id, size_t client_id_size, MiniRtcTraversalMode mode,
const MiniRtcNetTrafficStats* net_traffic_stats, const char* user_id,
const size_t user_id_size, void* user_data) {
auto* handler = static_cast<PeerEventHandler*>(user_data);
@@ -640,7 +640,7 @@ void PeerEventHandler::OnNetStatusReport(
const auto status = runtime->connection_status_.find(remote_id);
report_codecs = runtime->codec_status_controllers_.count(remote_id) != 0 &&
status != runtime->connection_status_.end() &&
status->second == ConnectionStatus::Connected;
status->second == MiniRtcConnectionStatus::MiniRtcConnectionConnected;
}
if (net_traffic_stats && report_codecs) {
RemoteAction action{};
@@ -37,10 +37,10 @@ public:
std::string WireId(const std::string& key) const;
bool DataAllowed() const;
bool IsDirect() const { return direct_bound_; }
void SetDirectPeer(PeerPtr* peer) { direct_peer_ = peer; }
PeerPtr* DirectPeer() const { return direct_peer_; }
void SetDirectPeer(MiniRtcPeerPtr* peer) { direct_peer_ = peer; }
MiniRtcPeerPtr* DirectPeer() const { return direct_peer_; }
void FlushEarlyData();
void ApplyConnectionStatus(ConnectionStatus status, const std::string& id) {
void ApplyConnectionStatus(MiniRtcConnectionStatus status, const std::string& id) {
DispatchConnectionStatus(status, id.data(), id.size(), this);
}
void StopAccepting() { callbacks_.StopAccepting(); }
@@ -60,30 +60,30 @@ public:
const char *user_id, size_t user_id_size,
const char *src_id, size_t src_id_size,
void *user_data);
static void OnSignalStatus(SignalStatus status, const char *user_id,
static void OnSignalStatus(MiniRtcSignalStatus status, const char *user_id,
size_t user_id_size, void *user_data);
static void OnSignalMessage(const char *message, size_t size,
void *user_data);
static int OnSignalExchange(SignalExchangeStage stage, const char* message,
static int OnSignalExchange(MiniRtcSignalExchangeStage stage, const char* message,
size_t size, char* response, size_t capacity,
void* user_data);
static void OnConnectionStatus(ConnectionStatus status, const char *user_id,
static void OnConnectionStatus(MiniRtcConnectionStatus status, const char *user_id,
size_t user_id_size, void *user_data);
static void OnNetStatusReport(const char *client_id, size_t client_id_size,
TraversalMode mode,
MiniRtcTraversalMode mode,
const MiniRtcNetTrafficStats *net_traffic_stats,
const char *user_id, size_t user_id_size,
void *user_data);
private:
static void DispatchConnectionStatus(ConnectionStatus status, const char* id,
static void DispatchConnectionStatus(MiniRtcConnectionStatus status, const char* id,
size_t size, void* context);
static void SendClientInfo(PeerPtr* peer, const std::string& client_id);
static void SendClientInfo(MiniRtcPeerPtr* peer, const std::string& client_id);
bool QueueEarlyData(const char* data, size_t size, const char* label,
size_t label_size);
std::weak_ptr<lan::Session> direct_;
bool direct_bound_ = false;
PeerPtr* direct_peer_ = nullptr;
MiniRtcPeerPtr* direct_peer_ = nullptr;
std::mutex early_data_mutex_;
std::vector<std::string> early_data_;
size_t early_data_bytes_ = 0;
@@ -51,7 +51,7 @@ void PeerEventHandler::OnReceiveVideoBuffer(
if (props->connection_established_) {
const auto timing_now = VideoLatencyFrame::Clock::now();
// Pair the clocks before preview conversion so its cost is included.
const auto local_now_us = GetSystemTimeMicros(
const auto local_now_us = MiniRtcGetSystemTimeMicros(
handler->IsDirect() ? handler->DirectPeer() : props->peer_);
const auto* received_native = GetNativeVideoFrame(video_frame);
props->received_video_stats_.Record(
@@ -26,7 +26,7 @@ bool GuiRuntime::IsAuthorizedController(const std::string& remote_id) {
std::shared_lock lock(connection_status_mutex_);
const auto found = connection_status_.find(remote_id);
return found != connection_status_.end() &&
found->second == ConnectionStatus::Connected;
found->second == MiniRtcConnectionStatus::MiniRtcConnectionConnected;
}
void GuiRuntime::SetControllerPrivacySupport(const std::string& remote_id,
@@ -34,9 +34,9 @@ void GuiRuntime::SetControllerPrivacySupport(const std::string& remote_id,
std::unique_lock lock(connection_status_mutex_);
const auto found = connection_status_.find(remote_id);
if (found == connection_status_.end()) return;
if (found->second != ConnectionStatus::Connected) {
if (found->second == ConnectionStatus::Connecting ||
found->second == ConnectionStatus::Gathering) {
if (found->second != MiniRtcConnectionStatus::MiniRtcConnectionConnected) {
if (found->second == MiniRtcConnectionStatus::MiniRtcConnectionConnecting ||
found->second == MiniRtcConnectionStatus::MiniRtcConnectionGathering) {
privacy_sessions_.RememberSupport(remote_id, supported);
LOG_INFO("Privacy: retained early controller capability, peer={}, supported={}",
remote_id, supported);
@@ -64,7 +64,7 @@ void GuiRuntime::QueuePrivacyCommand(const std::string& remote_id,
std::shared_lock session_lock(connection_status_mutex_);
const auto found = connection_status_.find(remote_id);
if (found == connection_status_.end() ||
found->second != ConnectionStatus::Connected ||
found->second != MiniRtcConnectionStatus::MiniRtcConnectionConnected ||
!privacy_sessions_.Supports(remote_id)) return;
std::lock_guard lock(privacy_commands_mutex_);
if (privacy_commands_.size() >= 32) return;
@@ -94,7 +94,7 @@ void GuiRuntime::HandlePrivacy() {
std::shared_lock lock(connection_status_mutex_);
const auto found = connection_status_.find(remote_id);
if (found == connection_status_.end() ||
found->second != ConnectionStatus::Connected ||
found->second != MiniRtcConnectionStatus::MiniRtcConnectionConnected ||
!privacy_sessions_.Supports(remote_id)) continue;
if (command.flag == PrivacyCommandFlag::enable) {
if (privacy_sessions_.CanEnable())
@@ -124,7 +124,7 @@ void GuiRuntime::HandlePrivacy() {
privacy_.CancelAutomaticResume();
status = privacy_.Snapshot();
for (const auto& [id, state] : connection_status_)
if (state == ConnectionStatus::Connected &&
if (state == MiniRtcConnectionStatus::MiniRtcConnectionConnected &&
privacy_sessions_.Supports(id))
controllers.push_back(id);
if (!privacy_sessions_.CanEnable()) {
@@ -112,8 +112,8 @@ struct RemoteSession {
std::mutex gallery_conversion_mutex_;
std::vector<unsigned char> gallery_nv12_, gallery_scaled_, gallery_scratch_;
std::shared_ptr<lan::Session> lan_session_;
Params params_;
PeerPtr* peer_ = nullptr;
MiniRtcParams params_;
MiniRtcPeerPtr* peer_ = nullptr;
std::shared_ptr<PeerEventHandler> peer_events_;
std::atomic<bool> closing_{false};
// Transport callbacks request tab closure; only the UI thread destroys it.
@@ -130,7 +130,7 @@ struct RemoteSession {
std::string remote_id_;
bool exit_ = false;
bool signal_connected_ = false;
SignalStatus signal_status_ = SignalStatus::SignalClosed;
MiniRtcSignalStatus signal_status_ = MiniRtcSignalStatus::MiniRtcSignalClosed;
bool connection_established_ = false;
std::atomic<bool> was_connected_{false};
// Transport callbacks publish changes; the UI thread persists history.
@@ -211,8 +211,8 @@ struct RemoteSession {
bool remote_cursor_state_received_ = false;
CursorPresentation cursor_presentation_;
// Shared by minirtc callbacks, Slint rendering and SDL audio callbacks.
std::atomic<ConnectionStatus> connection_status_ = ConnectionStatus::Closed;
std::atomic<TraversalMode> traversal_mode_{TraversalMode::UnknownMode};
std::atomic<MiniRtcConnectionStatus> connection_status_ = MiniRtcConnectionStatus::MiniRtcConnectionClosed;
std::atomic<MiniRtcTraversalMode> traversal_mode_{MiniRtcTraversalMode::MiniRtcTraversalUnknown};
int fps_ = 0;
int frame_count_ = 0;
std::chrono::steady_clock::time_point last_time_;
+5 -5
View File
@@ -67,11 +67,11 @@ struct RecentConnectionsState {
};
struct PeerState {
SignalStatus signal_status_ = SignalStatus::SignalClosed;
MiniRtcSignalStatus signal_status_ = MiniRtcSignalStatus::MiniRtcSignalClosed;
std::string signal_status_str_;
std::atomic<bool> signal_connected_{false};
PeerPtr *peer_ = nullptr;
PeerPtr *peer_reserved_ = nullptr;
MiniRtcPeerPtr *peer_ = nullptr;
MiniRtcPeerPtr *peer_reserved_ = nullptr;
std::string video_primary_label_ = "primary_display";
std::string video_secondary_label_ = "secondary_display";
std::string audio_label_ = "audio";
@@ -83,7 +83,7 @@ struct PeerState {
std::string file_label_ = kFileStream;
std::string file_feedback_label_ = kFileFeedbackStream;
std::string clipboard_label_ = kClipboardStream;
Params params_{};
MiniRtcParams params_{};
};
// OS-specific service and permission state is kept separate from transport
@@ -203,7 +203,7 @@ struct ConnectionState {
std::unordered_map<std::string, PendingReconnect> pending_reconnects_;
std::shared_mutex connection_status_mutex_;
std::unordered_map<std::string, ConnectionStatus> connection_status_;
std::unordered_map<std::string, MiniRtcConnectionStatus> connection_status_;
std::unordered_map<std::string, std::string> connection_host_names_;
std::unordered_set<std::string> codec_status_controllers_;
// Cursor position is sampled asynchronously after remote mouse input has
@@ -83,13 +83,13 @@ void Session::Error(MiniRtcDirectError error, void* context) {
s->failed = true;
}
}
void Session::Status(ConnectionStatus status) {
void Session::Status(MiniRtcConnectionStatus status) {
if (closing) return;
if (status == ConnectionStatus::Connected)
if (status == MiniRtcConnectionStatus::MiniRtcConnectionConnected)
ready = true;
else if (status == ConnectionStatus::Closed ||
status == ConnectionStatus::Failed ||
status == ConnectionStatus::Disconnected)
else if (status == MiniRtcConnectionStatus::MiniRtcConnectionClosed ||
status == MiniRtcConnectionStatus::MiniRtcConnectionFailed ||
status == MiniRtcConnectionStatus::MiniRtcConnectionDisconnected)
failed = true;
}
SessionManager::SessionManager(std::filesystem::path path, Hooks hooks)
@@ -417,9 +417,9 @@ void SessionManager::Prepare(const SessionPtr& s) {
options.send_signal = Session::SendSignal;
options.on_error = Session::Error;
options.context = s.get();
if (InitDirectPeer(prepared.peer, &options) != 0 ||
if (MiniRtcInitDirectPeer(prepared.peer, &options) != 0 ||
(!s->closing &&
StartDirectSession(prepared.peer, !s->incoming) != 0))
MiniRtcStartDirectSession(prepared.peer, !s->incoming) != 0))
s->failed = true;
return prepared;
})});
@@ -560,7 +560,7 @@ void SessionManager::Message(const SessionPtr& s, const std::string& text) {
Check(type == "candidate" &&
(s->phase == Session::AwaitAnswer ||
s->phase == Session::Negotiating || s->phase == Session::Connected));
if (ReceiveDirectSignal(s->peer, text.data(), text.size()) != 0)
if (MiniRtcReceiveDirectSignal(s->peer, text.data(), text.size()) != 0)
Fail(s, "InvalidSignal");
}
void SessionManager::Dispose(const SessionPtr& s) {
@@ -571,8 +571,8 @@ void SessionManager::Dispose(const SessionPtr& s) {
cleanup_jobs_.push_back(
std::async(std::launch::async, [s, peer, owner, drain]() mutable {
if (drain) drain();
CloseDirectSession(peer);
DestroyPeer(&peer);
MiniRtcCloseDirectSession(peer);
MiniRtcDestroyPeer(&peer);
}));
}
void SessionManager::Close(const SessionPtr& s, const std::string& error) {
@@ -43,7 +43,7 @@ struct Session {
bool incoming = false;
uint64_t epoch = 0, receive_seq = 0, send_seq = 0;
std::chrono::steady_clock::time_point deadline;
PeerPtr* peer = nullptr; // Only published/cleared by the manager.
MiniRtcPeerPtr* peer = nullptr; // Only published/cleared by the manager.
std::atomic<bool> closing{false}, authorized{false}, ready{false},
failed{false};
std::atomic<int> failure_code{-1};
@@ -54,7 +54,7 @@ struct Session {
std::function<void()> drain_callbacks;
static int SendSignal(const char* data, size_t size, void* context);
static void Error(MiniRtcDirectError error, void* context);
void Status(ConnectionStatus status);
void Status(MiniRtcConnectionStatus status);
};
// All public methods run on the GUI manager thread. Only Session's bounded
@@ -63,7 +63,7 @@ class SessionManager {
public:
using SessionPtr = std::shared_ptr<Session>;
struct Prepared {
PeerPtr* peer = nullptr;
MiniRtcPeerPtr* peer = nullptr;
std::shared_ptr<void> callback_owner;
std::function<void()> drain_callbacks;
};
@@ -120,7 +120,7 @@ void GuiRuntime::HandleWindowsServiceIntegration() {
std::shared_lock lock(connection_status_mutex_);
return std::any_of(connection_status_.begin(), connection_status_.end(),
[](const auto &entry) {
return entry.second == ConnectionStatus::Connected;
return entry.second == MiniRtcConnectionStatus::MiniRtcConnectionConnected;
});
}();
if (!has_connected_remote) {