mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-12 19:24:22 +08:00
Auto get icecand ip address from http request (#3251)
Get ip address from http `Host` header, and set it to icecand ip for webrtc
This commit is contained in:
@@ -635,7 +635,7 @@ void WebRtcTransportImp::onCheckAnswer(RtcSession &sdp) {
|
||||
});
|
||||
for (auto &m : sdp.media) {
|
||||
m.addr.reset();
|
||||
m.addr.address = extern_ips.empty() ? SockUtil::get_local_ip() : extern_ips[0];
|
||||
m.addr.address = extern_ips.empty() ? _localIp.empty() ? SockUtil::get_local_ip() : _localIp : extern_ips[0];
|
||||
m.rtcp_addr.reset();
|
||||
m.rtcp_addr.address = m.addr.address;
|
||||
|
||||
@@ -730,7 +730,7 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
|
||||
return ret;
|
||||
});
|
||||
if (extern_ips.empty()) {
|
||||
std::string local_ip = SockUtil::get_local_ip();
|
||||
std::string local_ip = _localIp.empty() ? SockUtil::get_local_ip() : _localIp;
|
||||
if (local_udp_port) { configure.addCandidate(*makeIceCandidate(local_ip, local_udp_port, 120, "udp")); }
|
||||
if (local_tcp_port) { configure.addCandidate(*makeIceCandidate(local_ip, local_tcp_port, _preferred_tcp ? 125 : 115, "tcp")); }
|
||||
} else {
|
||||
@@ -748,6 +748,10 @@ void WebRtcTransportImp::setIceCandidate(vector<SdpAttrCandidate> cands) {
|
||||
_cands = std::move(cands);
|
||||
}
|
||||
|
||||
void WebRtcTransportImp::setLocalIp(const std::string &localIp) {
|
||||
_localIp = localIp;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
class RtpChannel : public RtpTrackImp, public std::enable_shared_from_this<RtpChannel> {
|
||||
@@ -1239,6 +1243,10 @@ std::string exchangeSdp(const WebRtcInterface &exchanger, const std::string& off
|
||||
return const_cast<WebRtcInterface &>(exchanger).getAnswerSdp(offer);
|
||||
}
|
||||
|
||||
void setLocalIp(const WebRtcInterface& exchanger, const std::string& localIp) {
|
||||
return const_cast<WebRtcInterface &>(exchanger).setLocalIp(localIp);
|
||||
}
|
||||
|
||||
void WebRtcPluginManager::setListener(Listener cb) {
|
||||
lock_guard<mutex> lck(_mtx_creator);
|
||||
_listener = std::move(cb);
|
||||
|
||||
@@ -42,10 +42,13 @@ public:
|
||||
virtual const std::string& getIdentifier() const = 0;
|
||||
virtual const std::string& deleteRandStr() const { static std::string s_null; return s_null; }
|
||||
virtual void setIceCandidate(std::vector<SdpAttrCandidate> cands) {}
|
||||
virtual void setLocalIp(const std::string &localIp) {}
|
||||
};
|
||||
|
||||
std::string exchangeSdp(const WebRtcInterface &exchanger, const std::string& offer);
|
||||
|
||||
void setLocalIp(const WebRtcInterface &exchanger, const std::string &localIp);
|
||||
|
||||
class WebRtcException : public WebRtcInterface {
|
||||
public:
|
||||
WebRtcException(const SockException &ex) : _ex(ex) {};
|
||||
@@ -253,6 +256,7 @@ public:
|
||||
void removeTuple(RTC::TransportTuple* tuple);
|
||||
void safeShutdown(const SockException &ex);
|
||||
|
||||
void setLocalIp(const std::string &localIp) override;
|
||||
protected:
|
||||
void OnIceServerSelectedTuple(const RTC::IceServer *iceServer, RTC::TransportTuple *tuple) override;
|
||||
WebRtcTransportImp(const EventPoller::Ptr &poller,bool preferred_tcp = false);
|
||||
@@ -306,6 +310,8 @@ private:
|
||||
//根据接收rtp的pt获取相关信息
|
||||
std::unordered_map<uint8_t/*pt*/, std::unique_ptr<WrappedMediaTrack>> _pt_to_track;
|
||||
std::vector<SdpAttrCandidate> _cands;
|
||||
//源访问的hostip
|
||||
std::string _localIp;
|
||||
};
|
||||
|
||||
class WebRtcTransportManager {
|
||||
|
||||
Reference in New Issue
Block a user