Fix mouse double click issue and switch remote desktop issue
This commit is contained in:
@@ -318,7 +318,9 @@ void CWebService::ServerThread(int port) {
|
||||
uint64_t device_id = id_str.empty() ? 0 : strtoull(id_str.c_str(), nullptr, 10);
|
||||
HandleConnect(ws_ptr, token, device_id);
|
||||
} else if (cmd == "disconnect") {
|
||||
HandleDisconnect(ws_ptr, token);
|
||||
std::string disc_id_str = root.get("id", "").asString();
|
||||
uint64_t disc_device_id = disc_id_str.empty() ? 0 : strtoull(disc_id_str.c_str(), nullptr, 10);
|
||||
HandleDisconnect(ws_ptr, token, disc_device_id);
|
||||
} else if (cmd == "ping") {
|
||||
HandlePing(ws_ptr, token);
|
||||
} else if (cmd == "mouse") {
|
||||
@@ -572,7 +574,7 @@ void CWebService::HandleConnect(void* ws_ptr, const std::string& token, uint64_t
|
||||
}
|
||||
}
|
||||
|
||||
void CWebService::HandleDisconnect(void* ws_ptr, const std::string& token) {
|
||||
void CWebService::HandleDisconnect(void* ws_ptr, const std::string& token, uint64_t requested_device_id) {
|
||||
std::string username, role;
|
||||
if (!ValidateToken(token, username, role)) {
|
||||
SendText(ws_ptr, BuildJsonResponse("disconnect_result", false, "Invalid token"));
|
||||
@@ -585,8 +587,12 @@ void CWebService::HandleDisconnect(void* ws_ptr, const std::string& token) {
|
||||
std::lock_guard<std::mutex> lock(m_ClientsMutex);
|
||||
auto it = m_Clients.find(ws_ptr);
|
||||
if (it != m_Clients.end()) {
|
||||
device_id = it->second.watch_device_id;
|
||||
it->second.watch_device_id = 0;
|
||||
// Only disconnect if no specific device requested, or if it matches current device
|
||||
// This prevents race condition when quickly switching devices
|
||||
if (requested_device_id == 0 || it->second.watch_device_id == requested_device_id) {
|
||||
device_id = it->second.watch_device_id;
|
||||
it->second.watch_device_id = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user