sweeper_video/include/tunnel_client.hpp

41 lines
868 B
C++
Raw Normal View History

2026-01-21 14:02:52 +08:00
#pragma once
#include <atomic>
#include <string>
#include <thread>
2026-01-21 14:58:32 +08:00
#include <websocketpp/connection.hpp>
namespace websocketpp
{
namespace client
{
}
} // namespace websocketpp
2026-01-21 14:02:52 +08:00
class TunnelClient
{
public:
TunnelClient(const std::string& vid, const std::string& server_ws_url, int local_http_port);
void start();
void stop();
private:
void run_loop();
2026-01-21 14:58:32 +08:00
// 新增:流式处理 & 安全发送
void handle_request_and_reply(const nlohmann::json& req);
void send_text_safe(const std::string& s);
void send_binary_safe(const void* data, size_t len);
2026-01-21 14:02:52 +08:00
private:
std::string vid_;
std::string ws_url_;
2026-01-21 14:58:32 +08:00
int local_port_ = 0;
2026-01-21 14:02:52 +08:00
std::atomic<bool> running_{false};
std::thread th_;
2026-01-21 14:58:32 +08:00
// websocketpp 句柄
websocketpp::connection_hdl hdl_;
ws_client* client_ = nullptr; // 指向 run_loop 的 client
2026-01-21 14:02:52 +08:00
};