mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
Release ice instance when a user leave transmission
This commit is contained in:
@@ -25,7 +25,12 @@ IceTransmission::IceTransmission(
|
||||
ice_ws_transport_(ice_ws_transmission),
|
||||
on_receive_ice_msg_cb_(on_receive_ice_msg) {}
|
||||
|
||||
IceTransmission::~IceTransmission() {}
|
||||
IceTransmission::~IceTransmission() {
|
||||
if (ice_agent_) {
|
||||
delete ice_agent_;
|
||||
ice_agent_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int IceTransmission::InitIceTransmission(std::string &ip, int port) {
|
||||
ice_agent_ = new IceAgent(ip, port);
|
||||
@@ -75,22 +80,15 @@ int IceTransmission::InitIceTransmission(std::string &ip, int port) {
|
||||
}
|
||||
|
||||
int IceTransmission::DestroyIceTransmission() {
|
||||
if (ice_agent_) {
|
||||
delete ice_agent_;
|
||||
}
|
||||
return 0;
|
||||
LOG_INFO("[{}] Destroy ice transmission", user_id_);
|
||||
return ice_agent_->DestoryIceAgent();
|
||||
}
|
||||
|
||||
int IceTransmission::CreateTransmission(const std::string &transmission_id) {
|
||||
LOG_INFO("Create transport");
|
||||
LOG_INFO("[{}] Create transmission", user_id_);
|
||||
offer_peer_ = false;
|
||||
transmission_id_ = transmission_id;
|
||||
|
||||
// if (SignalStatus::Connected != signal_status_) {
|
||||
// LOG_ERROR("Not connect to signalserver");
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
json message = {{"type", "create_transmission"},
|
||||
{"transmission_id", transmission_id}};
|
||||
if (ice_ws_transport_) {
|
||||
@@ -98,7 +96,6 @@ int IceTransmission::CreateTransmission(const std::string &transmission_id) {
|
||||
LOG_INFO("Send msg: {}", message.dump().c_str());
|
||||
}
|
||||
|
||||
// CreateOffer();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -109,7 +106,7 @@ int IceTransmission::SetTransmissionId(const std::string &transmission_id) {
|
||||
}
|
||||
|
||||
int IceTransmission::JoinTransmission() {
|
||||
LOG_INFO("Join transport");
|
||||
LOG_INFO("[{}] Join transmission", user_id_);
|
||||
|
||||
CreateOffer();
|
||||
return 0;
|
||||
|
||||
@@ -64,6 +64,20 @@ int PeerConnection::Create(PeerConnectionParams params,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "user_leave_transmission"_H: {
|
||||
std::string user_id = j["user_id"];
|
||||
LOG_INFO("Receive notification: user id [{}] leave transmission",
|
||||
user_id);
|
||||
auto user_id_it = ice_transmission_list_.find(user_id);
|
||||
if (user_id_it != ice_transmission_list_.end()) {
|
||||
user_id_it->second->DestroyIceTransmission();
|
||||
delete user_id_it->second;
|
||||
user_id_it->second = nullptr;
|
||||
ice_transmission_list_.erase(user_id_it);
|
||||
LOG_INFO("Terminate transmission to user [{}]", user_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "offer"_H: {
|
||||
std::string remote_sdp = j["sdp"].get<std::string>();
|
||||
|
||||
@@ -169,6 +183,20 @@ int PeerConnection::Join(PeerConnectionParams params,
|
||||
|
||||
break;
|
||||
}
|
||||
case "user_leave_transmission"_H: {
|
||||
std::string user_id = j["user_id"];
|
||||
LOG_INFO("Receive notification: user id [{}] leave transmission",
|
||||
user_id);
|
||||
auto user_id_it = ice_transmission_list_.find(user_id);
|
||||
if (user_id_it != ice_transmission_list_.end()) {
|
||||
user_id_it->second->DestroyIceTransmission();
|
||||
delete user_id_it->second;
|
||||
user_id_it->second = nullptr;
|
||||
ice_transmission_list_.erase(user_id_it);
|
||||
LOG_INFO("Terminate transmission to user [{}]", user_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "ws_connection_id"_H: {
|
||||
ws_connection_id_ = j["ws_connection_id"].get<unsigned int>();
|
||||
LOG_INFO("Receive local peer websocket connection id [{}]",
|
||||
|
||||
@@ -55,14 +55,16 @@ bool SignalServer::on_open(websocketpp::connection_hdl hdl) {
|
||||
|
||||
bool SignalServer::on_close(websocketpp::connection_hdl hdl) {
|
||||
LOG_INFO("Websocket onnection [{}] closed", ws_connection_id_);
|
||||
std::string user_id = transmission_manager_.GetUserId(hdl);
|
||||
std::string transmission_id =
|
||||
transmission_manager_.ReleaseUserIdFromTransmission(hdl);
|
||||
|
||||
std::vector<std::string> user_id_list =
|
||||
transmission_manager_.GetAllUserIdOfTransmission(transmission_id);
|
||||
json message = {{"type", "user_leave_transmission"},
|
||||
{"transmission_id", transmission_id},
|
||||
{"user_id", transmission_manager_.GetUserId(hdl)}};
|
||||
{"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);
|
||||
|
||||
@@ -88,6 +88,7 @@ websocketpp::connection_hdl TransmissionManager::GetWsHandle(
|
||||
std::string TransmissionManager::GetUserId(websocketpp::connection_hdl hdl) {
|
||||
for (auto it = user_id_ws_hdl_list_.begin(); it != user_id_ws_hdl_list_.end();
|
||||
++it) {
|
||||
LOG_INFO("[{}]", it->first);
|
||||
if (it->second.lock().get() == hdl.lock().get()) return it->first;
|
||||
}
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user