1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

RTC: Support multiple address for client. 4.0.36

This commit is contained in:
winlin 2020-07-25 09:33:18 +08:00
parent 7ec5ef8497
commit 21835c38b7
7 changed files with 91 additions and 64 deletions

View file

@ -542,17 +542,20 @@ void SrsRtcServer::destroy(SrsRtcConnection* session)
std::map<std::string, SrsRtcConnection*>::iterator it;
if ((it = map_username_session.find(session->username())) != map_username_session.end()) {
string username = session->username();
if ((it = map_username_session.find(username)) != map_username_session.end()) {
map_username_session.erase(it);
}
if ((it = map_id_session.find(session->peer_id())) != map_id_session.end()) {
map_id_session.erase(it);
vector<SrsUdpMuxSocket*> addresses = session->peer_addresses();
for (int i = 0; i < (int)addresses.size(); i++) {
SrsUdpMuxSocket* addr = addresses.at(i);
map_id_session.erase(addr->peer_id());
}
SrsContextRestore(_srs_context->get_id());
session->switch_to_context();
srs_trace("RTC session=%s, destroy, summary: %s", session->id().c_str(), session->stat_->summary().c_str());
srs_trace("RTC: session destroy, username=%s, summary: %s", username.c_str(), session->stat_->summary().c_str());
zombies_.push_back(session);
}
@ -562,14 +565,6 @@ bool SrsRtcServer::insert_into_id_sessions(const string& peer_id, SrsRtcConnecti
return map_id_session.insert(make_pair(peer_id, session)).second;
}
void SrsRtcServer::remove_id_sessions(const string& peer_id)
{
std::map<std::string, SrsRtcConnection*>::iterator it;
if ((it = map_id_session.find(peer_id)) != map_id_session.end()) {
map_id_session.erase(it);
}
}
void SrsRtcServer::check_and_clean_timeout_session()
{
map<string, SrsRtcConnection*>::iterator iter = map_username_session.begin();
@ -585,14 +580,19 @@ void SrsRtcServer::check_and_clean_timeout_session()
// Now, we got the RTC session to cleanup, switch to its context
// to make all logs write to the "correct" pid+cid.
session->switch_to_context();
srs_trace("RTC session=%s, STUN timeout, summary: %s", session->id().c_str(), session->stat_->summary().c_str());
srs_trace("RTC: session STUN timeout, summary: %s", session->stat_->summary().c_str());
session->disposing_ = true;
zombies_.push_back(session);
// Use C++98 style: https://stackoverflow.com/a/4636230
map_username_session.erase(iter++);
map_id_session.erase(session->peer_id());
vector<SrsUdpMuxSocket*> addresses = session->peer_addresses();
for (int i = 0; i < (int)addresses.size(); i++) {
SrsUdpMuxSocket* addr = addresses.at(i);
map_id_session.erase(addr->peer_id());
}
if (handler) {
handler->on_timeout(session);