mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
Rejoin transmission when server leaves
This commit is contained in:
@@ -59,21 +59,30 @@ bool SignalServer::on_close(websocketpp::connection_hdl hdl) {
|
|||||||
std::string transmission_id =
|
std::string transmission_id =
|
||||||
transmission_manager_.ReleaseUserIdFromTransmission(hdl);
|
transmission_manager_.ReleaseUserIdFromTransmission(hdl);
|
||||||
|
|
||||||
json message = {{"type", "user_leave_transmission"},
|
if (!transmission_id.empty()) {
|
||||||
{"transmission_id", transmission_id},
|
json message = {{"type", "user_leave_transmission"},
|
||||||
{"user_id", user_id}};
|
{"transmission_id", transmission_id},
|
||||||
|
{"user_id", user_id}};
|
||||||
|
|
||||||
std::vector<std::string> user_id_list =
|
std::vector<std::string> user_id_list =
|
||||||
transmission_manager_.GetAllUserIdOfTransmission(transmission_id);
|
transmission_manager_.GetAllUserIdOfTransmission(transmission_id);
|
||||||
|
|
||||||
if (user_id_list.empty()) {
|
if (user_id_list.empty()) {
|
||||||
transmission_list_.erase(transmission_id);
|
transmission_list_.erase(transmission_id);
|
||||||
LOG_INFO("Release transmission [{}] due to no user in this transmission",
|
LOG_INFO("Release transmission [{}] due to no user in this transmission",
|
||||||
transmission_id);
|
transmission_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& user_id : user_id_list) {
|
if (std::string::npos != user_id.find("S-")) {
|
||||||
send_msg(transmission_manager_.GetWsHandle(user_id), message);
|
transmission_list_.erase(transmission_id);
|
||||||
|
transmission_manager_.ReleaseAllUserIdFromTransmission(transmission_id);
|
||||||
|
LOG_INFO("Release transmission [{}] due to server leaves",
|
||||||
|
transmission_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& user_id : user_id_list) {
|
||||||
|
send_msg(transmission_manager_.GetWsHandle(user_id), message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ws_connections_.erase(hdl);
|
ws_connections_.erase(hdl);
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,16 @@ std::string TransmissionManager::ReleaseUserIdFromTransmission(
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TransmissionManager::ReleaseAllUserIdFromTransmission(
|
||||||
|
const std::string& transmission_id) {
|
||||||
|
if (transmission_user_id_list_.end() !=
|
||||||
|
transmission_user_id_list_.find(transmission_id)) {
|
||||||
|
transmission_user_id_list_[transmission_id].clear();
|
||||||
|
transmission_user_id_list_.erase(transmission_id);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
websocketpp::connection_hdl TransmissionManager::GetWsHandle(
|
websocketpp::connection_hdl TransmissionManager::GetWsHandle(
|
||||||
const std::string& user_id) {
|
const std::string& user_id) {
|
||||||
if (user_id_ws_hdl_list_.find(user_id) != user_id_ws_hdl_list_.end()) {
|
if (user_id_ws_hdl_list_.find(user_id) != user_id_ws_hdl_list_.end()) {
|
||||||
@@ -88,7 +98,7 @@ websocketpp::connection_hdl TransmissionManager::GetWsHandle(
|
|||||||
std::string TransmissionManager::GetUserId(websocketpp::connection_hdl hdl) {
|
std::string TransmissionManager::GetUserId(websocketpp::connection_hdl hdl) {
|
||||||
for (auto it = user_id_ws_hdl_list_.begin(); it != user_id_ws_hdl_list_.end();
|
for (auto it = user_id_ws_hdl_list_.begin(); it != user_id_ws_hdl_list_.end();
|
||||||
++it) {
|
++it) {
|
||||||
LOG_INFO("[{}]", it->first);
|
// LOG_INFO("[{}]", it->first);
|
||||||
if (it->second.lock().get() == hdl.lock().get()) return it->first;
|
if (it->second.lock().get() == hdl.lock().get()) return it->first;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class TransmissionManager {
|
|||||||
websocketpp::connection_hdl hdl);
|
websocketpp::connection_hdl hdl);
|
||||||
|
|
||||||
std::string ReleaseUserIdFromTransmission(websocketpp::connection_hdl hdl);
|
std::string ReleaseUserIdFromTransmission(websocketpp::connection_hdl hdl);
|
||||||
|
bool ReleaseAllUserIdFromTransmission(const std::string& transmission_id);
|
||||||
|
|
||||||
websocketpp::connection_hdl GetWsHandle(const std::string& user_id);
|
websocketpp::connection_hdl GetWsHandle(const std::string& user_id);
|
||||||
std::string GetUserId(websocketpp::connection_hdl hdl);
|
std::string GetUserId(websocketpp::connection_hdl hdl);
|
||||||
|
|||||||
@@ -276,6 +276,12 @@ void PeerConnection::ProcessSignal(const std::string &signal) {
|
|||||||
user_id_it->second->DestroyIceTransmission();
|
user_id_it->second->DestroyIceTransmission();
|
||||||
ice_transmission_list_.erase(user_id_it);
|
ice_transmission_list_.erase(user_id_it);
|
||||||
LOG_INFO("Terminate transmission to user [{}]", user_id);
|
LOG_INFO("Terminate transmission to user [{}]", user_id);
|
||||||
|
|
||||||
|
if (std::string::npos != user_id.find("S-")) {
|
||||||
|
LOG_INFO("Server leaves, try to rejoin transmission");
|
||||||
|
|
||||||
|
RequestTransmissionMemberList(transmission_id_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user