From d910c80a000b47d274117bb10e5d76ed135e0f4d Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Sat, 19 Nov 2022 09:46:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96webrtc=20iceandidate=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Sdp.cpp | 2 +- webrtc/WebRtcTransport.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index 2466d9e8..3a30ba67 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -1204,7 +1204,7 @@ RtcSessionSdp::Ptr RtcSession::toRtcSessionSdp() const{ } for (auto &cand : m.candidate) { - if(cand.port){ + if (cand.port) { sdp_media.addAttr(std::make_shared(cand)); } } diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index e2be1628..a3528fd2 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -614,7 +614,7 @@ makeIceCandidate(std::string ip, uint16_t port, uint32_t priority = 100, std::st void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const { WebRtcTransport::onRtcConfigure(configure); - GET_CONFIG(uint16_t, local_port, Rtc::kPort); + GET_CONFIG(uint16_t, local_udp_port, Rtc::kPort); GET_CONFIG(uint16_t, local_tcp_port, Rtc::kTcpPort); // 添加接收端口candidate信息 GET_CONFIG_FUNC(std::vector, extern_ips, Rtc::kExternIP, [](string str) { @@ -626,15 +626,15 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const { return ret; }); if (extern_ips.empty()) { - std::string localIp = SockUtil::get_local_ip(); - configure.addCandidate(*makeIceCandidate(localIp, local_port, 120, "udp")); - configure.addCandidate(*makeIceCandidate(localIp, local_tcp_port, 110, "tcp")); + std::string local_ip = SockUtil::get_local_ip(); + 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, 110, "tcp")); } } else { const uint32_t delta = 10; uint32_t priority = 100 + delta * extern_ips.size(); for (auto ip : extern_ips) { - configure.addCandidate(*makeIceCandidate(ip, local_port, priority + 5, "udp")); - configure.addCandidate(*makeIceCandidate(ip, local_tcp_port, priority, "tcp")); + if (local_udp_port) { configure.addCandidate(*makeIceCandidate(ip, local_udp_port, priority + 5, "udp")); } + if (local_tcp_port) { configure.addCandidate(*makeIceCandidate(ip, local_tcp_port, priority, "tcp")); } priority -= delta; } }