diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index b6f2e89c7..52b4cd984 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -1938,15 +1938,27 @@ bool SrsRtcConnection::is_stun_timeout() return last_stun_time + sessionStunTimeout < srs_get_system_time(); } +// TODO: FIXME: We should support multiple addresses, because client may use more than one addresses. void SrsRtcConnection::update_sendonly_socket(SrsUdpMuxSocket* skt) { + std::string old_peer_id; if (sendonly_skt) { srs_trace("session %s address changed, update %s -> %s", id().c_str(), sendonly_skt->peer_id().c_str(), skt->peer_id().c_str()); + old_peer_id = sendonly_skt->peer_id(); } + // Update the transport. srs_freep(sendonly_skt); sendonly_skt = skt->copy_sendonly(); + + // Update the sessions to handle packets from the new address. + server_->insert_into_id_sessions(sendonly_skt->peer_id().c_str(), this); + + // Remove the old address. + if (!old_peer_id.empty()) { + server_->remove_id_sessions(old_peer_id); + } } void SrsRtcConnection::check_send_nacks(SrsRtpNackForReceiver* nack, uint32_t ssrc) diff --git a/trunk/src/app/srs_app_rtc_server.cpp b/trunk/src/app/srs_app_rtc_server.cpp index 69ad16d15..7f5d59053 100644 --- a/trunk/src/app/srs_app_rtc_server.cpp +++ b/trunk/src/app/srs_app_rtc_server.cpp @@ -494,6 +494,14 @@ 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::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::iterator iter = map_username_session.begin(); diff --git a/trunk/src/app/srs_app_rtc_server.hpp b/trunk/src/app/srs_app_rtc_server.hpp index c12c8c3d9..79c445d88 100644 --- a/trunk/src/app/srs_app_rtc_server.hpp +++ b/trunk/src/app/srs_app_rtc_server.hpp @@ -94,6 +94,7 @@ public: void destroy(SrsRtcConnection* session); public: bool insert_into_id_sessions(const std::string& peer_id, SrsRtcConnection* session); + void remove_id_sessions(const std::string& peer_id); void check_and_clean_timeout_session(); int nn_sessions(); SrsRtcConnection* find_session_by_username(const std::string& ufrag);