mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
Dev version: Support multiple ice connections
This commit is contained in:
@@ -21,6 +21,14 @@ bool TransmissionManager::BindHostToTransmission(
|
||||
|
||||
bool TransmissionManager::BindGuestToTransmission(
|
||||
websocketpp::connection_hdl hdl, const std::string& transmission_id) {
|
||||
if (transmission_guest_list_.find(transmission_id) !=
|
||||
transmission_guest_list_.end()) {
|
||||
transmission_guest_list_[transmission_id].push_back(hdl);
|
||||
} else {
|
||||
std::vector<websocketpp::connection_hdl> guest_hdl_list;
|
||||
guest_hdl_list.push_back(hdl);
|
||||
transmission_guest_list_[transmission_id] = guest_hdl_list;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -34,11 +42,23 @@ bool TransmissionManager::ReleaseGuestFromTransmission(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TransmissionManager::BindHostUsernameToWsHandle(
|
||||
const std::string& host_username, websocketpp::connection_hdl hdl) {
|
||||
if (transmission_host_username_list_.find(host_username) !=
|
||||
transmission_host_username_list_.end()) {
|
||||
LOG_ERROR("Guest already bind to username [{}]", host_username.c_str());
|
||||
return false;
|
||||
} else {
|
||||
transmission_host_username_list_[host_username] = hdl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TransmissionManager::BindGuestUsernameToWsHandle(
|
||||
const std::string& guest_username, websocketpp::connection_hdl hdl) {
|
||||
if (transmission_guest_username_list_.find(guest_username) !=
|
||||
transmission_guest_username_list_.end()) {
|
||||
LOG_WARN("Guest already bind to username [{}]", guest_username.c_str());
|
||||
LOG_ERROR("Guest already bind to username [{}]", guest_username.c_str());
|
||||
return false;
|
||||
} else {
|
||||
transmission_guest_username_list_[guest_username] = hdl;
|
||||
@@ -57,14 +77,32 @@ websocketpp::connection_hdl TransmissionManager::GetHostOfTransmission(
|
||||
}
|
||||
}
|
||||
|
||||
std::set<websocketpp::connection_hdl>
|
||||
TransmissionManager::GetGuestOfTransmission(
|
||||
std::string TransmissionManager::GetHostUsername(
|
||||
websocketpp::connection_hdl hdl) {
|
||||
for (auto host : transmission_host_username_list_) {
|
||||
if (host.second.lock().get() == hdl.lock().get()) return host.first;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string TransmissionManager::GetGuestUsername(
|
||||
websocketpp::connection_hdl hdl) {
|
||||
for (auto guest : transmission_guest_username_list_) {
|
||||
if (guest.second.lock().get() == hdl.lock().get()) return guest.first;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::vector<websocketpp::connection_hdl>
|
||||
TransmissionManager::GetAllGuestsOfTransmission(
|
||||
const std::string& transmission_id) {
|
||||
if (transmission_guest_list_.find(transmission_id) !=
|
||||
transmission_guest_list_.end()) {
|
||||
return transmission_guest_list_[transmission_id];
|
||||
} else {
|
||||
return std::set<websocketpp::connection_hdl>();
|
||||
return std::vector<websocketpp::connection_hdl>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,4 +115,18 @@ websocketpp::connection_hdl TransmissionManager::GetGuestWsHandle(
|
||||
websocketpp::connection_hdl hdl;
|
||||
return hdl;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> TransmissionManager::GetAllMembersOfTransmission(
|
||||
const std::string& transmission_id) {
|
||||
std::vector<std::string> member_list;
|
||||
|
||||
member_list.push_back(
|
||||
GetHostUsername(GetHostOfTransmission(transmission_id)));
|
||||
|
||||
for (auto guest_hdl : GetAllGuestsOfTransmission(transmission_id)) {
|
||||
member_list.push_back(GetGuestUsername(guest_hdl));
|
||||
}
|
||||
|
||||
return member_list;
|
||||
}
|
||||
Reference in New Issue
Block a user