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[]) int main(int argc, char *argv[])
{ {
//#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
// QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//#endif #endif
QApplication a(argc, argv); 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()) 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); return DefWindowProc(hWnd, message, wParam, lParam);
@ -255,7 +255,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
break; break;
case WM_DESTROY: case WM_DESTROY:
TsWsClient::stop_all_client(); g_ws_client.stop_all_client();
SendMessage(g_hDlgMain, WMU_DLG_MAIN_EXIT, NULL, NULL); SendMessage(g_hDlgMain, WMU_DLG_MAIN_EXIT, NULL, NULL);
PostQuitMessage(0); PostQuitMessage(0);
break; break;
@ -264,7 +264,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
COPYDATASTRUCT* data = (COPYDATASTRUCT*)lParam; COPYDATASTRUCT* data = (COPYDATASTRUCT*)lParam;
ex_astr url_protocol((char*)data->lpData); ex_astr url_protocol((char*)data->lpData);
// MessageBoxA(hWnd, url_protocol.c_str(), "url-protocol", MB_OK); // 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; break;
} }
default: default:

View File

@ -100,7 +100,6 @@ password 51:b:%s\n\
//#endif //#endif
TsWsClient g_ws_client; TsWsClient g_ws_client;
TsWsClient g_wss_client;
void* g_app = NULL; void* g_app = NULL;
@ -137,7 +136,6 @@ void TsWsClient::init_app(void* app)
void TsWsClient::stop_all_client() void TsWsClient::stop_all_client()
{ {
g_ws_client.stop(); g_ws_client.stop();
g_wss_client.stop();
} }
// ============================================================================ // ============================================================================
@ -174,15 +172,14 @@ void TsWsClient::url_scheme_handler(const std::string& url)
return; return;
} }
// now we support 'register' method only.
method.assign(url, pos_protocol + 3, pos_method - pos_protocol - 3); method.assign(url, pos_protocol + 3, pos_method - pos_protocol - 3);
if (method[method.length() - 1] == '/') if (method.empty())
method.erase(method.length() - 1, 1);
if (method != "register")
{ {
EXLOGE("[url-schema] unknown method: %s\n", method.c_str()); EXLOGE("[ws] no method, what should I do now?\n");
return; return;
} }
if (method[method.length() - 1] == '/')
method.erase(method.length() - 1, 1);
param.assign(url, pos_method + 7); // ?param= param.assign(url, pos_method + 7); // ?param=
if (param.empty()) if (param.empty())
@ -223,8 +220,23 @@ void TsWsClient::url_scheme_handler(const std::string& url)
return; return;
} }
// now we support 'register' method only. if (method == "register")
_process_register(param, js_root); {
_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 // static
@ -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 session_id = js_root["session_id"].asCString();
std::string protocol; std::string protocol;
protocol.assign(ws_url, 0, 3); protocol.assign(ws_url, 0, 5);
if (protocol == "ws:") if (protocol == "ws://")
{ {
g_ws_client._register(false, ws_url, assist_id, session_id); 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 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(); ~TsWsClient();
static void init_app(void* app); void init_app(void* app);
static void stop_all_client(); void stop_all_client();
static void url_scheme_handler(const std::string& url); void url_scheme_handler(const std::string& url);
protected: protected:
void _thread_loop(void); 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 _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: private:
struct mg_mgr m_mg_mgr; struct mg_mgr m_mg_mgr;
@ -74,4 +76,7 @@ private:
uint32_t m_assist_id; uint32_t m_assist_id;
}; };
extern TsWsClient g_ws_client;
#endif // __TS_WS_CLIENT_H__ #endif // __TS_WS_CLIENT_H__