mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
Fix signal server member list error when rejoin same one connection
This commit is contained in:
@@ -98,24 +98,24 @@ inline int ProcessMouseKeyEven(SDL_Event &ev) {
|
|||||||
|
|
||||||
if (SDL_KEYDOWN == ev.type) // SDL_KEYUP
|
if (SDL_KEYDOWN == ev.type) // SDL_KEYUP
|
||||||
{
|
{
|
||||||
printf("SDLK_DOWN: %d\n", SDL_KeyCode(ev.key.keysym.sym));
|
// printf("SDLK_DOWN: %d\n", SDL_KeyCode(ev.key.keysym.sym));
|
||||||
if (SDLK_DOWN == ev.key.keysym.sym) {
|
if (SDLK_DOWN == ev.key.keysym.sym) {
|
||||||
printf("SDLK_DOWN \n");
|
// printf("SDLK_DOWN \n");
|
||||||
|
|
||||||
} else if (SDLK_UP == ev.key.keysym.sym) {
|
} else if (SDLK_UP == ev.key.keysym.sym) {
|
||||||
printf("SDLK_UP \n");
|
// printf("SDLK_UP \n");
|
||||||
|
|
||||||
} else if (SDLK_LEFT == ev.key.keysym.sym) {
|
} else if (SDLK_LEFT == ev.key.keysym.sym) {
|
||||||
printf("SDLK_LEFT \n");
|
// printf("SDLK_LEFT \n");
|
||||||
|
|
||||||
} else if (SDLK_RIGHT == ev.key.keysym.sym) {
|
} else if (SDLK_RIGHT == ev.key.keysym.sym) {
|
||||||
printf("SDLK_RIGHT \n");
|
// printf("SDLK_RIGHT \n");
|
||||||
}
|
}
|
||||||
} else if (SDL_MOUSEBUTTONDOWN == ev.type) {
|
} else if (SDL_MOUSEBUTTONDOWN == ev.type) {
|
||||||
if (SDL_BUTTON_LEFT == ev.button.button) {
|
if (SDL_BUTTON_LEFT == ev.button.button) {
|
||||||
int px = ev.button.x;
|
int px = ev.button.x;
|
||||||
int py = ev.button.y;
|
int py = ev.button.y;
|
||||||
printf("SDL_MOUSEBUTTONDOWN x, y %d %d \n", px, py);
|
// printf("SDL_MOUSEBUTTONDOWN x, y %d %d \n", px, py);
|
||||||
|
|
||||||
remote_action.type = ControlType::mouse;
|
remote_action.type = ControlType::mouse;
|
||||||
remote_action.m.flag = MouseFlag::left_down;
|
remote_action.m.flag = MouseFlag::left_down;
|
||||||
@@ -128,7 +128,7 @@ inline int ProcessMouseKeyEven(SDL_Event &ev) {
|
|||||||
} else if (SDL_BUTTON_RIGHT == ev.button.button) {
|
} else if (SDL_BUTTON_RIGHT == ev.button.button) {
|
||||||
int px = ev.button.x;
|
int px = ev.button.x;
|
||||||
int py = ev.button.y;
|
int py = ev.button.y;
|
||||||
printf("SDL_BUTTON_RIGHT x, y %d %d \n", px, py);
|
// printf("SDL_BUTTON_RIGHT x, y %d %d \n", px, py);
|
||||||
|
|
||||||
remote_action.type = ControlType::mouse;
|
remote_action.type = ControlType::mouse;
|
||||||
remote_action.m.flag = MouseFlag::right_down;
|
remote_action.m.flag = MouseFlag::right_down;
|
||||||
@@ -142,7 +142,7 @@ inline int ProcessMouseKeyEven(SDL_Event &ev) {
|
|||||||
if (SDL_BUTTON_LEFT == ev.button.button) {
|
if (SDL_BUTTON_LEFT == ev.button.button) {
|
||||||
int px = ev.button.x;
|
int px = ev.button.x;
|
||||||
int py = ev.button.y;
|
int py = ev.button.y;
|
||||||
printf("SDL_MOUSEBUTTONUP x, y %d %d \n", px, py);
|
// printf("SDL_MOUSEBUTTONUP x, y %d %d \n", px, py);
|
||||||
|
|
||||||
remote_action.type = ControlType::mouse;
|
remote_action.type = ControlType::mouse;
|
||||||
remote_action.m.flag = MouseFlag::left_up;
|
remote_action.m.flag = MouseFlag::left_up;
|
||||||
@@ -155,7 +155,7 @@ inline int ProcessMouseKeyEven(SDL_Event &ev) {
|
|||||||
} else if (SDL_BUTTON_RIGHT == ev.button.button) {
|
} else if (SDL_BUTTON_RIGHT == ev.button.button) {
|
||||||
int px = ev.button.x;
|
int px = ev.button.x;
|
||||||
int py = ev.button.y;
|
int py = ev.button.y;
|
||||||
printf("SDL_MOUSEBUTTONUP x, y %d %d \n", px, py);
|
// printf("SDL_MOUSEBUTTONUP x, y %d %d \n", px, py);
|
||||||
|
|
||||||
remote_action.type = ControlType::mouse;
|
remote_action.type = ControlType::mouse;
|
||||||
remote_action.m.flag = MouseFlag::right_up;
|
remote_action.m.flag = MouseFlag::right_up;
|
||||||
@@ -169,7 +169,7 @@ inline int ProcessMouseKeyEven(SDL_Event &ev) {
|
|||||||
int px = ev.motion.x;
|
int px = ev.motion.x;
|
||||||
int py = ev.motion.y;
|
int py = ev.motion.y;
|
||||||
|
|
||||||
printf("SDL_MOUSEMOTION x, y %d %d \n", px, py);
|
// printf("SDL_MOUSEMOTION x, y %d %d \n", px, py);
|
||||||
|
|
||||||
remote_action.type = ControlType::mouse;
|
remote_action.type = ControlType::mouse;
|
||||||
remote_action.m.flag = MouseFlag::move;
|
remote_action.m.flag = MouseFlag::move;
|
||||||
@@ -213,9 +213,9 @@ void ReceiveDataBuffer(const char *data, size_t size, const char *user_id,
|
|||||||
RemoteAction remote_action;
|
RemoteAction remote_action;
|
||||||
memcpy(&remote_action, data, sizeof(remote_action));
|
memcpy(&remote_action, data, sizeof(remote_action));
|
||||||
|
|
||||||
std::cout << "remote_action: " << remote_action.type << " "
|
// std::cout << "remote_action: " << remote_action.type << " "
|
||||||
<< remote_action.m.flag << " " << remote_action.m.x << " "
|
// << remote_action.m.flag << " " << remote_action.m.x << " "
|
||||||
<< remote_action.m.y << std::endl;
|
// << remote_action.m.y << std::endl;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
INPUT ip;
|
INPUT ip;
|
||||||
|
|
||||||
@@ -238,15 +238,15 @@ void ReceiveDataBuffer(const char *data, size_t size, const char *user_id,
|
|||||||
ip.mi.time = 0;
|
ip.mi.time = 0;
|
||||||
|
|
||||||
// Set cursor pos
|
// Set cursor pos
|
||||||
// SetCursorPos(ip.mi.dx, ip.mi.dy);
|
SetCursorPos(ip.mi.dx, ip.mi.dy);
|
||||||
// Send the press
|
// Send the press
|
||||||
if (ip.mi.dwFlags != MOUSEEVENTF_MOVE) {
|
if (ip.mi.dwFlags != MOUSEEVENTF_MOVE) {
|
||||||
// SendInput(1, &ip, sizeof(INPUT));
|
SendInput(1, &ip, sizeof(INPUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Receive data from [" << user << "], " << ip.type << " "
|
// std::cout << "Receive data from [" << user << "], " << ip.type << " "
|
||||||
<< ip.mi.dwFlags << " " << ip.mi.dx << " " << ip.mi.dy
|
// << ip.mi.dwFlags << " " << ip.mi.dx << " " << ip.mi.dy
|
||||||
<< std::endl;
|
// << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -538,11 +538,13 @@ int main() {
|
|||||||
static bool connect_button_pressed = false;
|
static bool connect_button_pressed = false;
|
||||||
static const char *connect_label = "Connect";
|
static const char *connect_label = "Connect";
|
||||||
{
|
{
|
||||||
static char buf[20] = "";
|
static char remote_id[20] = "";
|
||||||
|
strcpy(remote_id, GetMac(mac_addr).c_str());
|
||||||
ImGui::Text("REMOTE ID:");
|
ImGui::Text("REMOTE ID:");
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(110);
|
ImGui::SetNextItemWidth(110);
|
||||||
ImGui::InputTextWithHint("id_buf", "000002", buf, IM_ARRAYSIZE(buf),
|
ImGui::InputTextWithHint("id_buf", "000002", remote_id,
|
||||||
|
IM_ARRAYSIZE(remote_id),
|
||||||
ImGuiInputTextFlags_AllowTabInput);
|
ImGuiInputTextFlags_AllowTabInput);
|
||||||
|
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
@@ -559,7 +561,7 @@ int main() {
|
|||||||
if (ImGui::Button(connect_label)) {
|
if (ImGui::Button(connect_label)) {
|
||||||
if (strcmp(connect_label, "Connect") == 0 && !joined) {
|
if (strcmp(connect_label, "Connect") == 0 && !joined) {
|
||||||
std::string user_id = "C-" + std::string(GetMac(mac_addr));
|
std::string user_id = "C-" + std::string(GetMac(mac_addr));
|
||||||
JoinConnection(peer_client, buf);
|
JoinConnection(peer_client, remote_id);
|
||||||
joined = true;
|
joined = true;
|
||||||
} else if (strcmp(connect_label, "Disconnect") == 0 && joined) {
|
} else if (strcmp(connect_label, "Disconnect") == 0 && joined) {
|
||||||
LeaveConnection(peer_client);
|
LeaveConnection(peer_client);
|
||||||
|
|||||||
@@ -113,7 +113,9 @@ void SignalServer::run(uint16_t port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SignalServer::send_msg(websocketpp::connection_hdl hdl, json message) {
|
void SignalServer::send_msg(websocketpp::connection_hdl hdl, json message) {
|
||||||
server_.send(hdl, message.dump(), websocketpp::frame::opcode::text);
|
if (!hdl.expired()) {
|
||||||
|
server_.send(hdl, message.dump(), websocketpp::frame::opcode::text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SignalServer::on_message(websocketpp::connection_hdl hdl,
|
void SignalServer::on_message(websocketpp::connection_hdl hdl,
|
||||||
@@ -170,6 +172,18 @@ void SignalServer::on_message(websocketpp::connection_hdl hdl,
|
|||||||
LOG_INFO("[{}] leaves transmission [{}]", user_id.c_str(),
|
LOG_INFO("[{}] leaves transmission [{}]", user_id.c_str(),
|
||||||
transmission_id.c_str());
|
transmission_id.c_str());
|
||||||
transmission_manager_.ReleaseUserIdFromTransmission(hdl);
|
transmission_manager_.ReleaseUserIdFromTransmission(hdl);
|
||||||
|
|
||||||
|
json message = {{"type", "user_leave_transmission"},
|
||||||
|
{"transmission_id", transmission_id},
|
||||||
|
{"user_id", user_id}};
|
||||||
|
|
||||||
|
std::vector<std::string> user_id_list =
|
||||||
|
transmission_manager_.GetAllUserIdOfTransmission(transmission_id);
|
||||||
|
|
||||||
|
for (const auto& user_id : user_id_list) {
|
||||||
|
send_msg(transmission_manager_.GetWsHandle(user_id), message);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "query_user_id_list"_H: {
|
case "query_user_id_list"_H: {
|
||||||
|
|||||||
@@ -79,7 +79,16 @@ bool TransmissionManager::ReleaseAllUserIdFromTransmission(
|
|||||||
const std::string& transmission_id) {
|
const std::string& transmission_id) {
|
||||||
if (transmission_user_id_list_.end() !=
|
if (transmission_user_id_list_.end() !=
|
||||||
transmission_user_id_list_.find(transmission_id)) {
|
transmission_user_id_list_.find(transmission_id)) {
|
||||||
transmission_user_id_list_[transmission_id].clear();
|
auto user_id_list = transmission_user_id_list_[transmission_id];
|
||||||
|
for (auto& user_id : user_id_list) {
|
||||||
|
if (user_id_ws_hdl_list_.find(user_id) != user_id_ws_hdl_list_.end()) {
|
||||||
|
LOG_INFO("Remove user id [{}] from transmission [{}]", user_id,
|
||||||
|
transmission_id);
|
||||||
|
user_id_ws_hdl_list_.erase(user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
user_id_list.clear();
|
||||||
transmission_user_id_list_.erase(transmission_id);
|
transmission_user_id_list_.erase(transmission_id);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -212,6 +212,11 @@ int PeerConnection::Leave() {
|
|||||||
LOG_INFO("[{}] sends leave transmission [{}] notification ", user_id_,
|
LOG_INFO("[{}] sends leave transmission [{}] notification ", user_id_,
|
||||||
transmission_id_);
|
transmission_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto &user_id_it : ice_transmission_list_) {
|
||||||
|
user_id_it.second->DestroyIceTransmission();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user