get ip from env, for externIP in file 'config.ini' (#1786)

This commit is contained in:
Haibo Chen 2022-07-09 21:44:57 +08:00 committed by GitHub
parent 09a8d53150
commit 576056c465
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 9 deletions

@ -1 +1 @@
Subproject commit 136b6b2f28193da218f577423db217aeb0f7aa6a
Subproject commit 5b30d6d4cb344b368d4a8272ef07e1656fc85021

View File

@ -48,6 +48,21 @@ static onceToken token([]() {
static atomic<uint64_t> s_key{0};
static void translateIPFromEnv(std::vector<std::string> &v) {
for (auto iter = v.begin(); iter != v.end();) {
if (start_with(*iter, "$")) {
auto ip = toolkit::getEnv(*iter);
if (ip.empty()) {
iter = v.erase(iter);
} else {
*iter++ = ip;
}
} else {
++iter;
}
}
}
WebRtcTransport::WebRtcTransport(const EventPoller::Ptr &poller) {
_poller = poller;
_identifier = "zlm_" + to_string(++s_key);
@ -468,9 +483,10 @@ void WebRtcTransportImp::onStartWebRTC() {
// 系统又要有rid这里手工生成rid并为其绑定ssrc
std::string rid = "r" + std::to_string(index);
track->rtp_ext_ctx->setRid(ssrc.ssrc, rid);
if(ssrc.rtx_ssrc)
if (ssrc.rtx_ssrc) {
track->rtp_ext_ctx->setRid(ssrc.rtx_ssrc, rid);
}
}
++index;
}
}
@ -480,8 +496,10 @@ void WebRtcTransportImp::onCheckAnswer(RtcSession &sdp) {
//修改answer sdp的ip、端口信息
GET_CONFIG_FUNC(std::vector<std::string>, extern_ips, RTC::kExternIP, [](string str) {
std::vector<std::string> ret;
if (str.length())
if (str.length()) {
ret = split(str, ",");
}
translateIPFromEnv(ret);
return ret;
});
for (auto &m : sdp.media) {
@ -556,15 +574,16 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
//添加接收端口candidate信息
GET_CONFIG_FUNC(std::vector<std::string>, extern_ips, RTC::kExternIP, [](string str){
std::vector<std::string> ret;
if (str.length())
if (str.length()) {
ret = split(str, ",");
}
translateIPFromEnv(ret);
return ret;
});
if (extern_ips.empty()) {
std::string localIp = SockUtil::get_local_ip();
configure.addCandidate(*makeIceCandidate(localIp, local_port, 120, "udp"));
}
else {
} else {
const uint32_t delta = 10;
uint32_t priority = 100 + delta * extern_ips.size();
for (auto ip : extern_ips) {
@ -575,7 +594,6 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
}
///////////////////////////////////////////////////////////////////
class RtpChannel : public RtpTrackImp, public std::enable_shared_from_this<RtpChannel> {