win: 支持通过API接口进行远程调用,支持通过API接口进行录像回放。

feature/assist-websocket
Apex Liu 2022-05-19 18:05:55 +08:00
parent dcadf399a4
commit 9d359248db
4 changed files with 66 additions and 23 deletions

View File

@ -45,9 +45,9 @@ void show_usage(QCommandLineParser& parser) {
int main(int argc, char *argv[])
{
//#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
// QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QApplication a(argc, argv);

View File

@ -243,7 +243,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (!g_url_protocol.empty())
{
TsWsClient::url_scheme_handler(g_url_protocol);
g_ws_client.url_scheme_handler(g_url_protocol);
}
return DefWindowProc(hWnd, message, wParam, lParam);
@ -255,7 +255,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
break;
case WM_DESTROY:
TsWsClient::stop_all_client();
g_ws_client.stop_all_client();
SendMessage(g_hDlgMain, WMU_DLG_MAIN_EXIT, NULL, NULL);
PostQuitMessage(0);
break;
@ -264,7 +264,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
COPYDATASTRUCT* data = (COPYDATASTRUCT*)lParam;
ex_astr url_protocol((char*)data->lpData);
// MessageBoxA(hWnd, url_protocol.c_str(), "url-protocol", MB_OK);
TsWsClient::url_scheme_handler(url_protocol);
g_ws_client.url_scheme_handler(url_protocol);
break;
}
default:

View File

@ -100,7 +100,6 @@ password 51:b:%s\n\
//#endif
TsWsClient g_ws_client;
TsWsClient g_wss_client;
void* g_app = NULL;
@ -137,7 +136,6 @@ void TsWsClient::init_app(void* app)
void TsWsClient::stop_all_client()
{
g_ws_client.stop();
g_wss_client.stop();
}
// ============================================================================
@ -174,15 +172,14 @@ void TsWsClient::url_scheme_handler(const std::string& url)
return;
}
// now we support 'register' method only.
method.assign(url, pos_protocol + 3, pos_method - pos_protocol - 3);
if (method[method.length() - 1] == '/')
method.erase(method.length() - 1, 1);
if (method != "register")
if (method.empty())
{
EXLOGE("[url-schema] unknown method: %s\n", method.c_str());
EXLOGE("[ws] no method, what should I do now?\n");
return;
}
if (method[method.length() - 1] == '/')
method.erase(method.length() - 1, 1);
param.assign(url, pos_method + 7); // ?param=
if (param.empty())
@ -223,9 +220,24 @@ void TsWsClient::url_scheme_handler(const std::string& url)
return;
}
// now we support 'register' method only.
if (method == "register")
{
_process_register(param, js_root);
}
else if (method == "run")
{
_process_run(param, js_root);
}
else if (method == "replay_rdp")
{
_process_replay_rdp(param, js_root);
}
else
{
EXLOGE("[ws] unknown method: %s\n", method.c_str());
return;
}
}
// static
void TsWsClient::_process_register(const std::string& param, Json::Value& js_root)
@ -244,14 +256,14 @@ void TsWsClient::_process_register(const std::string& param, Json::Value& js_roo
std::string session_id = js_root["session_id"].asCString();
std::string protocol;
protocol.assign(ws_url, 0, 3);
if (protocol == "ws:")
protocol.assign(ws_url, 0, 5);
if (protocol == "ws://")
{
g_ws_client._register(false, ws_url, assist_id, session_id);
}
else if (protocol == "wss")
else if (protocol == "wss:/")
{
g_wss_client._register(true, ws_url, assist_id, session_id);
g_ws_client._register(true, ws_url, assist_id, session_id);
}
else
{
@ -260,6 +272,32 @@ void TsWsClient::_process_register(const std::string& param, Json::Value& js_roo
}
}
void TsWsClient::_process_run(const std::string& param, Json::Value& js_root)
{
// wrapper for _rpc_func_run_client().
Json::Value js_param;
js_param["method"] = "run";
js_param["param"] = js_root;
AssistMessage msg_req;
std::string buf;
_rpc_func_run_client(buf, msg_req, js_param);
}
void TsWsClient::_process_replay_rdp(const std::string& param, Json::Value& js_root)
{
// wrapper for _rpc_func_replay_rdp().
Json::Value js_param;
js_param["method"] = "replay_rdp";
js_param["param"] = js_root;
AssistMessage msg_req;
std::string buf;
_rpc_func_replay_rdp(buf, msg_req, js_param);
}
// ============================================================================

View File

@ -33,10 +33,10 @@ public:
~TsWsClient();
static void init_app(void* app);
static void stop_all_client();
void init_app(void* app);
void stop_all_client();
static void url_scheme_handler(const std::string& url);
void url_scheme_handler(const std::string& url);
protected:
void _thread_loop(void);
@ -66,7 +66,9 @@ private:
static void _mg_event_handler(struct mg_connection* nc, int ev, void* ev_data);
static void _process_register(const std::string& param, Json::Value& js_root);
void _process_register(const std::string& param, Json::Value& js_root);
void _process_run(const std::string& param, Json::Value& js_root);
void _process_replay_rdp(const std::string& param, Json::Value& js_root);
private:
struct mg_mgr m_mg_mgr;
@ -74,4 +76,7 @@ private:
uint32_t m_assist_id;
};
extern TsWsClient g_ws_client;
#endif // __TS_WS_CLIENT_H__