mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[feat] net traffic stats supported
This commit is contained in:
@@ -26,6 +26,10 @@ static std::vector<std::string> recent_connections = {u8"近期连接",
|
||||
"Recent Connections"};
|
||||
static std::vector<std::string> disconnect = {u8"断开连接", "Disconnect"};
|
||||
static std::vector<std::string> fullscreen = {u8" 全屏", " Fullscreen"};
|
||||
static std::vector<std::string> show_net_traffic_stats = {
|
||||
u8"显示流量统计", "Show Net Traffic Stats"};
|
||||
static std::vector<std::string> hide_net_traffic_stats = {
|
||||
u8"隐藏流量统计", "Hide Net Traffic Stats"};
|
||||
static std::vector<std::string> exit_fullscreen = {u8" 退出全屏",
|
||||
" Exit fullscreen"};
|
||||
static std::vector<std::string> control_mouse = {u8" 控制", " Control"};
|
||||
|
||||
@@ -85,6 +85,23 @@ int Render::ControlBar() {
|
||||
2.0f);
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
// net traffic stats button
|
||||
std::string net_traffic_stats = ICON_FA_SIGNAL;
|
||||
if (ImGui::Button(net_traffic_stats.c_str(), ImVec2(25, 25))) {
|
||||
net_traffic_stats_button_pressed_ = !net_traffic_stats_button_pressed_;
|
||||
net_traffic_stats_button_label_ =
|
||||
net_traffic_stats_button_pressed_
|
||||
? localization::hide_net_traffic_stats
|
||||
[localization_language_index_]
|
||||
: localization::show_net_traffic_stats
|
||||
[localization_language_index_];
|
||||
}
|
||||
|
||||
if (net_traffic_stats_button_pressed_) {
|
||||
NetTrafficStats();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
// fullscreen button
|
||||
std::string fullscreen =
|
||||
@@ -140,4 +157,77 @@ int Render::ControlBar() {
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Render::NetTrafficStats() {
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(ImVec2((viewport->WorkSize.x - viewport->WorkPos.x -
|
||||
connection_status_window_width_) /
|
||||
2,
|
||||
(viewport->WorkSize.y - viewport->WorkPos.y -
|
||||
connection_status_window_height_) /
|
||||
2));
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(connection_status_window_width_,
|
||||
connection_status_window_height_));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
||||
|
||||
ImGui::Begin("NetTrafficStatsWindow", nullptr,
|
||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoSavedSettings);
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
if (ImGui::BeginTable("split", 3)) {
|
||||
int row = 0;
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text(" ");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("In");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Out");
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Video");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%d", net_traffic_stats_.video_in);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%d", net_traffic_stats_.video_out);
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Audio");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%d", net_traffic_stats_.audio_in);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%d", net_traffic_stats_.audio_out);
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Total");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%d", net_traffic_stats_.total_in);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%d", net_traffic_stats_.total_out);
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::SetCursorPosX(connection_status_window_width_ * 6 / 19);
|
||||
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
|
||||
|
||||
// ok
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
|
||||
ImGui::IsKeyPressed(ImGuiKey_Enter)) {
|
||||
net_traffic_stats_button_pressed_ = false;
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ class Render {
|
||||
int DrawMainWindow();
|
||||
int DrawStreamWindow();
|
||||
int ConfirmDeleteConnection();
|
||||
int NetTrafficStats();
|
||||
|
||||
public:
|
||||
static void OnReceiveVideoBufferCb(const XVideoFrame *video_frame,
|
||||
@@ -84,8 +85,9 @@ class Render {
|
||||
size_t user_id_size, void *user_data);
|
||||
|
||||
static void NetStatusReport(const char *client_id, size_t client_id_size,
|
||||
TraversalMode mode, const unsigned short send,
|
||||
const unsigned short receive, void *user_data);
|
||||
TraversalMode mode,
|
||||
const XNetTrafficStats *net_traffic_stats,
|
||||
void *user_data);
|
||||
|
||||
static SDL_HitTestResult HitTestCallback(SDL_Window *window,
|
||||
const SDL_Point *area, void *data);
|
||||
@@ -148,6 +150,7 @@ class Render {
|
||||
std::string mac_addr_str_ = "";
|
||||
std::string connect_button_label_ = "Connect";
|
||||
std::string fullscreen_button_label_ = "Fullscreen";
|
||||
std::string net_traffic_stats_button_label_ = "Show Net Traffic Stats";
|
||||
std::string mouse_control_button_label_ = "Mouse Control";
|
||||
std::string audio_capture_button_label_ = "Audio Capture";
|
||||
std::string settings_button_label_ = "Setting";
|
||||
@@ -180,8 +183,8 @@ class Render {
|
||||
int main_window_width_before_maximized_ = 640;
|
||||
int main_window_height_before_maximized_ = 480;
|
||||
int control_window_min_width_ = 20;
|
||||
int control_window_max_width_ = 170;
|
||||
int control_window_width_ = 170;
|
||||
int control_window_max_width_ = 200;
|
||||
int control_window_width_ = 200;
|
||||
int control_window_height_ = 40;
|
||||
int local_window_width_ = 320;
|
||||
int local_window_height_ = 235;
|
||||
@@ -259,6 +262,7 @@ class Render {
|
||||
uint32_t password_validating_time_ = 0;
|
||||
bool control_bar_expand_ = true;
|
||||
bool fullscreen_button_pressed_ = false;
|
||||
bool net_traffic_stats_button_pressed_ = false;
|
||||
bool mouse_control_button_pressed_ = false;
|
||||
bool audio_capture_button_pressed_ = false;
|
||||
bool show_settings_window_ = false;
|
||||
@@ -312,6 +316,8 @@ class Render {
|
||||
PeerPtr *peer_ = nullptr;
|
||||
PeerPtr *peer_reserved_ = nullptr;
|
||||
Params params_;
|
||||
TraversalMode traversal_mode_ = TraversalMode::UnknownMode;
|
||||
XNetTrafficStats net_traffic_stats_;
|
||||
|
||||
private:
|
||||
SDL_AudioDeviceID input_dev_;
|
||||
|
||||
@@ -332,8 +332,9 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char *user_id,
|
||||
}
|
||||
|
||||
void Render::NetStatusReport(const char *client_id, size_t client_id_size,
|
||||
TraversalMode mode, const unsigned short send,
|
||||
const unsigned short receive, void *user_data) {
|
||||
TraversalMode mode,
|
||||
const XNetTrafficStats *net_traffic_stats,
|
||||
void *user_data) {
|
||||
Render *render = (Render *)user_data;
|
||||
if (!render) {
|
||||
return;
|
||||
@@ -345,7 +346,17 @@ void Render::NetStatusReport(const char *client_id, size_t client_id_size,
|
||||
LOG_INFO("Use client id [{}] and save id into cache file", client_id);
|
||||
render->SaveSettingsIntoCacheFile();
|
||||
}
|
||||
if (mode != TraversalMode::UnknownMode) {
|
||||
LOG_INFO("Net mode: [{}]", int(mode));
|
||||
if (render->traversal_mode_ != mode) {
|
||||
render->traversal_mode_ = mode;
|
||||
LOG_INFO("Net mode: [{}]", int(render->traversal_mode_));
|
||||
}
|
||||
|
||||
if (net_traffic_stats) {
|
||||
render->net_traffic_stats_.video_in = net_traffic_stats->video_in;
|
||||
render->net_traffic_stats_.video_out = net_traffic_stats->video_out;
|
||||
render->net_traffic_stats_.audio_in = net_traffic_stats->audio_in;
|
||||
render->net_traffic_stats_.audio_out = net_traffic_stats->audio_out;
|
||||
render->net_traffic_stats_.total_in = net_traffic_stats->total_in;
|
||||
render->net_traffic_stats_.total_out = net_traffic_stats->total_out;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user